1 line
11 KiB
Plaintext
1 line
11 KiB
Plaintext
{"version":3,"sources":["pjax.js"],"names":["$","window","history","pushState","replaceState","addEventListener","e","state","scrollToMainTop","content","pjax","url","replacePageContent","dispatchEvent","pjaxEvents","complete","before","Event","success","error","document","on","reqUrl","this","attr","includes","decodeURI","postTop","getElementById","offsetTop","navHeight","offsetHeight","theTop","animate","scrollTop","setMetaProperty","doc","property","meta","querySelector","setAttribute","parentNode","removeChild","createElement","head","appendChild","getMetaProperty","els","getAttribute","data","title","oldMain","replaceWith","innerHTML","scripts","getElementsByTagName","i","length","script","type","toLowerCase","newScript","src","createTextNode","text","insertBefore","ogTitle","ogUrl","getPageData","needPushState","onError","location","href","request","XMLHttpRequest","onerror","console","ontimeout","onreadystatechange","readyState","responseText","newDoc","implementation","createHTMLDocument","documentElement","reqId","match","offset","top","open","NProgress","done","onComplete","timeout","load_comm","start","send"],"mappings":"AAAA,aAAAA,GAAE,WACE,GAAKC,OAAOC,SACPD,OAAOC,QAAQC,WACfF,OAAOC,QAAQE,aAFpB,CAoGAH,OAAOI,iBAAiB,YAXxB,SAAyBC,GACjBA,EAAEC,QACFC,IAC+B,oBAApBF,EAAEC,MAAME,QACfC,EAAKJ,EAAEC,MAAMI,KAAK,GAElBC,EAAmBN,EAAEC,OAEzBN,OAAOY,cAAcC,EAAWC,cAKxC,IAAMD,EAAa,CACfE,OAAQ,IAAIC,MAAM,eAClBC,QAAS,IAAID,MAAM,gBACnBF,SAAU,IAAIE,MAAM,iBACpBE,MAAO,IAAIF,MAAM,eAgErBjB,EAAEoB,UAAUC,GAAG,QAAS,oDAAoD,WACxE,IAAMC,EAAStB,EAAEuB,MAAMC,KAAK,QAC5B,YAAsB,IAAXF,MACFA,EAAOG,SAAS,iBACpBf,EAAKgB,UAAUJ,IAAS,IACtB,OAzKX,SAASd,IACL,IAAMmB,EAAUP,SAASQ,eAAe,oBAAoBC,UACtDC,EAAYV,SAASQ,eAAe,yBAAyBG,aAC7DC,EAASF,EAAYH,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ACpCA,UAAY,MAGhBtF,IACAkF,UAAUK,QAEV9F,OAAOY,cAAcC,EAAWE,QAiDpCyD,EAAQuB","file":"../js/pjax.min.js","sourcesContent":["$(function () {\n if (!window.history ||\n !window.history.pushState ||\n !window.history.replaceState) {\n return;\n }\n\n function scrollToMainTop() {\n const postTop = document.getElementById(\"kratos-blog-post\").offsetTop\n const navHeight = document.getElementById(\"kratos-desktop-topnav\").offsetHeight;\n const theTop = navHeight ? postTop - navHeight : 0;\n $(\"body,html\").animate({ scrollTop: theTop }, 600);\n }\n\n function setMetaProperty(doc, property, content) {\n var meta = doc.querySelector('meta[property=\"' + property + '\"]');\n if (meta) {\n if (content) {\n meta.setAttribute('content', content);\n } else {\n // 兼容性考虑,不直接使用 remove\n if (meta.parentNode) {\n meta.parentNode.removeChild(meta);\n }\n }\n } else {\n if (!content) {\n return;\n }\n meta = doc.createElement('meta');\n meta.setAttribute('property', property);\n meta.setAttribute('content', content);\n doc.head.appendChild(meta);\n }\n }\n\n function getMetaProperty(doc, property) {\n const els = doc.querySelector('meta[property=\"' + property + '\"]');\n return els ? els.getAttribute('content') : null;\n }\n\n function replacePageContent(data, doc) {\n document.title = data.title || 'Untitled';\n if (doc) {\n const oldMain = document.getElementById(\"main\");\n if (typeof oldMain.replaceWith === 'function') {\n // 避免多次解析DOM树带来的性能损失\n oldMain.replaceWith(doc.getElementById(\"main\"));\n } else {\n document.getElementById(\"main\").innerHTML = data.content;\n }\n } else {\n document.getElementById(\"main\").innerHTML = data.content;\n }\n // JS必须手动执行\n const scripts = document.getElementById(\"main\").getElementsByTagName(\"script\");\n for (var i = 0; i < scripts.length; i++) {\n const script = scripts[i];\n if (!script.type || script.type.toLowerCase() === \"text/javascript\") {\n var newScript = document.createElement(\"script\");\n newScript.setAttribute('type', 'text/javascript');\n if (script.src) {\n newScript.src = script.src;\n } else {\n newScript.appendChild(document.createTextNode(script.text));\n }\n if (typeof script.replaceWith === 'function') {\n script.replaceWith(newScript);\n } else {\n // 兼容性考虑\n script.parentNode.insertBefore(newScript, script);\n script.parentNode.removeChild(script);\n }\n }\n }\n // 更新部分元数据\n // 使用部分组件时可能会自动读取这些数据(如LiveRe评论系统)\n setMetaProperty(document, 'og:title', data.ogTitle);\n setMetaProperty(document, 'og:url', data.ogUrl);\n }\n function getPageData(url, doc) {\n return {\n url: url,\n title: doc.title,\n ogTitle: getMetaProperty(doc, 'og:title'),\n ogUrl: getMetaProperty(doc, 'og:url'),\n content: doc.getElementById(\"main\").innerHTML,\n }\n }\n\n function popStateHandler(e) {\n if (e.state) {\n scrollToMainTop();\n if (typeof e.state.content === 'undefined') {\n pjax(e.state.url, false);\n } else {\n replacePageContent(e.state)\n }\n window.dispatchEvent(pjaxEvents.complete);\n }\n };\n window.addEventListener('popstate', popStateHandler);\n\n const pjaxEvents = {\n before: new Event('pjax:before'),\n success: new Event('pjax:success'),\n complete: new Event('pjax:complete'),\n error: new Event('pjax:error'),\n };\n\n function pjax(reqUrl, needPushState) {\n const beforeSend = () => {\n // 防止评论区再被加载,重置加载函数\n if (typeof load_comm !== 'undefined' && load_comm !== null) {\n load_comm = null;\n }\n\n scrollToMainTop();\n NProgress.start();\n\n window.dispatchEvent(pjaxEvents.before);\n }\n const onError = () => {\n location.href = reqUrl;\n window.dispatchEvent(pjaxEvents.error);\n }\n const onComplete = (responseText) => {\n window.dispatchEvent(pjaxEvents.success);\n\n const newDoc = document.implementation.createHTMLDocument(\"pjax\");\n newDoc.documentElement.innerHTML = responseText;\n const isSuccessRequest = !!newDoc.getElementById(\"main\");\n if (isSuccessRequest) {\n history.replaceState(getPageData(location.href, document), document.title, location.href);\n const data = getPageData(reqUrl, newDoc)\n if (needPushState) {\n window.history.pushState(data, data.title, data.url);\n }\n replacePageContent(data, newDoc);\n\n // 如果URL里有指定节点ID,则滚动到相应的节点位置\n const reqId = reqUrl.match(/\\#.+$/);\n if (reqId) {\n $(\"body,html\").animate({ scrollTop: $(reqId[0]).offset().top - 40 }, 600);\n }\n } else {\n // 其实是失败的\n // 不如打开一个新页面?\n window.open(reqUrl);\n }\n NProgress.done();\n window.dispatchEvent(pjaxEvents.complete);\n }\n const request = new XMLHttpRequest();\n request.onerror = function (e) {\n console.error(e);\n onError();\n };\n request.ontimeout = function () {\n onError();\n };\n request.onreadystatechange = function () {\n if (request.readyState === 4) {\n onComplete(request.responseText);\n }\n };\n request.open(\"GET\", reqUrl, true);\n request.timeout = 6000;\n beforeSend();\n request.send();\n }\n $(document).on(\"click\", 'a[target!=_blank][rel!=gallery][class!=toc-link]', function () {\n const reqUrl = $(this).attr(\"href\");\n if (typeof reqUrl === 'undefined') return true;\n else if (reqUrl.includes(\"javascript:\")) return true;\n else pjax(decodeURI(reqUrl), true);\n return false;\n });\n});\n"]} |