mirror of
https://github.com/Wonderfall/hugo-WonderMod.git
synced 2024-11-23 02:51:39 +01:00
1 line
5.7 KiB
JavaScript
1 line
5.7 KiB
JavaScript
|
var InstantClick=function(d,r){var B=navigator.userAgent,E="createTouch" in d,C,e,l,c={},G,L=false,h=false,u=false,A=false,I={},a=false,o=false,g=[],x,F,v,y={fetch:[],receive:[],wait:[],change:[]};function t(R){var Q=R.indexOf("#");if(Q<0){return R}return R.substr(0,Q)}function f(Q){while(Q.nodeName!="A"){Q=Q.parentNode}return Q}function M(Q){do{if(!Q.hasAttribute){break}if(Q.hasAttribute("data-instant")){return false}if(Q.hasAttribute("data-no-instant")){return true}}while(Q=Q.parentNode);return false}function P(Q){do{if(!Q.hasAttribute){break}if(Q.hasAttribute("data-no-instant")){return false}if(Q.hasAttribute("data-instant")){return true}}while(Q=Q.parentNode);return false}function b(S,Q){for(var R=0;R<y[S].length;R++){y[S][R](Q)}}function k(W,Q,U,T){d.title=W;d.documentElement.replaceChild(Q,d.body);if(U){history.pushState(null,null,U);var S=U.indexOf("#"),R=S>-1&&d.getElementById(U.substr(S+1)),V=0;if(R){while(R.offsetParent){V+=R.offsetTop;R=R.offsetParent}}scrollTo(0,V);C=t(U)}else{scrollTo(0,T)}m();H.done();b("change",false)}function p(){a=false;o=false}function q(Q){n(f(Q.target).href)}function K(R){var Q=f(R.target);Q.addEventListener("mouseout",N);if(!v){n(Q.href)}else{e=Q.href;l=setTimeout(n,v)}}function O(R){var Q=f(R.target);if(F){Q.removeEventListener("mousedown",q)}else{Q.removeEventListener("mouseover",K)}n(Q.href)}function D(Q){if(Q.which>1||Q.metaKey||Q.ctrlKey){return}Q.preventDefault();w(f(Q.target).href)}function N(){if(l){clearTimeout(l);l=false;return}if(!a||o){return}G.abort();p()}function s(){if(G.readyState<4){return}if(G.status==0){return}I.ready=+new Date-I.start;b("receive");if(G.getResponseHeader("Content-Type").match(/\/(x|ht|xht)ml/)){var X=d.implementation.createHTMLDocument("");X.documentElement.innerHTML=G.responseText;h=X.title;A=X.body;var T=t(L);c[T]={body:A,title:h,scrollY:T in c?c[T].scrollY:0};var Q=X.head.children,W=0,U,V;for(var S=Q.length-1;S>=0;S--){U=Q[S];if(U.hasAttribute("data-instant-track")){V=U.getAttribute("href")||U.getAttribute("src")||U.innerHTML;for(var R=g.length-1;R>=0;R--){if(g[R]==V){W++}}}}if(W!=g.length){u=true}}else{u=true}if(o){o=false;w(L)}}function m(Z){var R=d.getElementsByTagName("a"),Y,U=r.protocol+"//"+r.host;for(var V=R.length-1;V>=0;V--){Y=R[V];if(Y.target||Y.hasAttribute("download")||Y.href.indexOf(U+"/")!=0||(Y.href.indexOf("#")>-1&&t(Y.href)==C)||(x?!P(Y):M(Y))){continue}Y.addEventListener("touchstart",O);if(F){Y.addEventListener("mousedown",q)}else{Y.addEventListener("mouseover",K)}Y.addEventListener("click",D)}if(!Z){var S=d.body.getElementsByTagName("script"),X,Q,W,T;for(V=0,j=S.length;V<j;V++){X=S[V];if(X.hasAttribute("data-no-instant")){continue}Q=d.createElement("script");if(X.src){Q.src=X.src}if(X.innerHTML){Q.innerHTML=X.innerHTML}W=X.parentNode;T=X.nextSibling;W.removeChild(X);W.insertBefore(Q,T)}}}function n(Q){if(!F&&"display" in I&&+new Date-(I.start+I.display)<100){return}if(l){clearTimeout(l);l=false}if(!Q){Q=e}if(a&&(Q==L||o)){return}a=true;o=false;L=Q;A=false;u=false;I={start:+new Date};b("fetch");G.open("GET",Q);G.send()}function w(Q){if(!("display" in I)){I.display=+new Date-I.start}if(l){if(L&&L!=Q){r.href=Q;return}n(Q);H.start(0,true);b("wait");o=true;return}if(!a||o){r.href=Q;return}if(u){r.href=L;return}if(!A){H.start(0,true);b("wait");o=true;return}c[C].scrollY=pageYOffset;p();k(h,A,L)}var H=function(){var Z,U,aa,Q,Y;function ab(){Z=d.createElement("div");Z.id="instantclick";U=d.createElement("div");U.id="instantclick-bar";U.className="instantclick-bar";Z.appendChild(U);var af=["Webkit","Moz","O"];aa="transform";if(!(aa in U.style)){for(var ac=0;ac<3;ac++){if(af[ac]+"Transform" in U.style){aa=af[ac]+"Transform"}}}var ae="transition";if(!(ae in U.style)){for(var ac=0;ac<3;ac++){if(af[ac]+"Transition" in U.style){ae="-"+af[ac].toLowerCase()+"-"+ae}}}var ad=d.createElement("style");ad.innerHTML="#instantclick{position:"+(E?"absolute":"fixed")+";top:0;left:0;width:100%;pointer-events:none;z-index:2147483647;"+ae+":opacity .25s .1s}.instantclick-bar{background:#29d;width:100%;margin-left:-100%;height:2px;"+ae+":all .25s}";d.hea
|