blog/js/pjax.min.js

3 lines
2.9 KiB
JavaScript

"use strict";$((function(){if(window.history&&window.history.pushState&&window.history.replaceState){window.addEventListener("popstate",(function(n){n.state&&(t(),"undefined"==typeof n.state.content?a(n.state.url,!1):r(n.state),window.dispatchEvent(e.complete))}));var e={before:new Event("pjax:before"),success:new Event("pjax:success"),complete:new Event("pjax:complete"),error:new Event("pjax:error")};$(document).on("click","a[target!=_blank][rel!=gallery][class!=toc-link]",(function(){var e=$(this).attr("href");return void 0===e||(!!e.includes("javascript:")||(a(decodeURI(e),!0),!1))}))}function t(){var e=document.getElementById("kratos-blog-post").offsetTop,t=document.getElementById("kratos-desktop-topnav").offsetHeight,n=t?e-t:0;$("body,html").animate({scrollTop:n},600)}function n(e,t,n){var o=e.querySelector('meta[property="'+t+'"]');if(o)n?o.setAttribute("content",n):o.parentNode&&o.parentNode.removeChild(o);else{if(!n)return;(o=e.createElement("meta")).setAttribute("property",t),o.setAttribute("content",n),e.head.appendChild(o)}}function o(e,t){var n=e.querySelector('meta[property="'+t+'"]');return n?n.getAttribute("content"):null}function r(e,t){if(document.title=e.title||"Untitled",t){var o=document.getElementById("main");"function"==typeof o.replaceWith?o.replaceWith(t.getElementById("main")):document.getElementById("main").innerHTML=e.content}else document.getElementById("main").innerHTML=e.content;for(var r=document.getElementById("main").getElementsByTagName("script"),i=0;i<r.length;i++){var a=r[i];if(!a.type||"text/javascript"===a.type.toLowerCase()){var c=document.createElement("script");c.setAttribute("type","text/javascript"),a.src?c.src=a.src:c.appendChild(document.createTextNode(a.text)),"function"==typeof a.replaceWith?a.replaceWith(c):(a.parentNode.insertBefore(c,a),a.parentNode.removeChild(a))}}n(document,"og:title",e.ogTitle),n(document,"og:url",e.ogUrl)}function i(e,t){return{url:e,title:t.title,ogTitle:o(t,"og:title"),ogUrl:o(t,"og:url"),content:t.getElementById("main").innerHTML}}function a(n,o){var a=function(){location.href=n,window.dispatchEvent(e.error)},c=new XMLHttpRequest;c.onerror=function(e){console.error(e),a()},c.ontimeout=function(){a()},c.onreadystatechange=function(){4===c.readyState&&function(t){window.dispatchEvent(e.success);var a=document.implementation.createHTMLDocument("pjax");if(a.documentElement.innerHTML=t,a.getElementById("main")){history.replaceState(i(location.href,document),document.title,location.href);var c=i(n,a);o&&window.history.pushState(c,c.title,c.url),r(c,a);var l=n.match(/\#.+$/);l&&$("body,html").animate({scrollTop:$(l[0]).offset().top-40},600)}else window.open(n);NProgress.done(),window.dispatchEvent(e.complete)}(c.responseText)},c.open("GET",n,!0),c.timeout=6e3,"undefined"!=typeof load_comm&&null!==load_comm&&(load_comm=null),t(),NProgress.start(),window.dispatchEvent(e.before),c.send()}}));
//# sourceMappingURL=../maps/pjax.min.js.map