website_template/js/main.min.js

1 line
7.9 KiB
JavaScript
Raw Normal View History

2014-07-29 02:50:38 +02:00
function externalLinks(){if(document.getElementsByTagName)for(var e=document.getElementsByTagName("a"),t=0;t<e.length;t++){var n=e[t];n.getAttribute("href")&&"external"===n.getAttribute("class")&&(n.target="_blank")}}window.onload=externalLinks;var InstantClick=function(e,t){function n(e){var t=e.indexOf("#");return 0>t?e:e.substr(0,t)}function r(e){for(;"A"!=e.nodeName;)e=e.parentNode;return e}function a(e){do{if(!e.hasAttribute)break;if(e.hasAttribute("data-instant"))return!1;if(e.hasAttribute("data-no-instant"))return!0}while(e=e.parentNode);return!1}function i(e){do{if(!e.hasAttribute)break;if(e.hasAttribute("data-no-instant"))return!1;if(e.hasAttribute("data-instant"))return!0}while(e=e.parentNode);return!1}function o(e,t){for(var n=0;n<z[e].length;n++)z[e][n](t)}function s(t,r,a,i){if(e.title=t,e.documentElement.replaceChild(r,e.body),a){history.pushState(null,null,a);var s=a.indexOf("#"),c=s>-1&&e.getElementById(a.substr(s+1)),l=0;if(c)for(;c.offsetParent;)l+=c.offsetTop,c=c.offsetParent;scrollTo(0,l),E=n(a)}else scrollTo(0,i);v(),W.done(),o("change",!1)}function c(){Y=!1,O=!1}function l(e){g(r(e.target).href)}function d(e){var t=r(e.target);t.addEventListener("mouseout",h),C?(T=t.href,w=setTimeout(g,C)):g(t.href)}function f(e){var t=r(e.target);x?t.removeEventListener("mousedown",l):t.removeEventListener("mouseover",d),g(t.href)}function u(e){e.which>1||e.metaKey||e.ctrlKey||(e.preventDefault(),p(r(e.target).href))}function h(){return w?(clearTimeout(w),void(w=!1)):void(Y&&!O&&(L.abort(),c()))}function m(){if(!(L.readyState<4)&&0!=L.status){if(F.ready=+new Date-F.start,o("receive"),L.getResponseHeader("Content-Type").match(/\/(x|ht|xht)ml/)){var t=e.implementation.createHTMLDocument("");t.documentElement.innerHTML=L.responseText,D=t.title,B=t.body;var r=n(S);N[r]={body:B,title:D,scrollY:r in N?N[r].scrollY:0};for(var a,i,s=t.head.children,c=0,l=s.length-1;l>=0;l--)if(a=s[l],a.hasAttribute("data-instant-track")){i=a.getAttribute("href")||a.getAttribute("src")||a.innerHTML;for(var d=I.length-1;d>=0;d--)I[d]==i&&c++}c!=I.length&&(H=!0)}else H=!0;O&&(O=!1,p(S))}}function v(r){for(var o,s=e.getElementsByTagName("a"),c=t.protocol+"//"+t.host,h=s.length-1;h>=0;h--)o=s[h],o.target||o.hasAttribute("download")||0!=o.href.indexOf(c+"/")||o.href.indexOf("#")>-1&&n(o.href)==E||(k?!i(o):a(o))||(o.addEventListener("touchstart",f),x?o.addEventListener("mousedown",l):o.addEventListener("mouseover",d),o.addEventListener("click",u));if(!r){var m,v,g,p,y=e.body.getElementsByTagName("script");for(h=0,j=y.length;j>h;h++)m=y[h],m.hasAttribute("data-no-instant")||(v=e.createElement("script"),m.src&&(v.src=m.src),m.innerHTML&&(v.innerHTML=m.innerHTML),g=m.parentNode,p=m.nextSibling,g.removeChild(m),g.insertBefore(v,p))}}function g(e){!x&&"display"in F&&+new Date-(F.start+F.display)<100||(w&&(clearTimeout(w),w=!1),e||(e=T),(!Y||e!=S&&!O)&&(Y=!0,O=!1,S=e,B=!1,H=!1,F={start:+new Date},o("fetch"),L.open("GET",e),L.send()))}function p(e){return"display"in F||(F.display=+new Date-F.start),w?S&&S!=e?void(t.href=e):(g(e),W.start(0,!0),o("wait"),void(O=!0)):!Y||O?void(t.href=e):H?void(t.href=S):B?(N[E].scrollY=pageYOffset,c(),void s(D,B,S)):(W.start(0,!0),o("wait"),void(O=!0))}function y(){if(!E){if(!q)return void o("change",!0);for(var r=arguments.length-1;r>=0;r--){var a=arguments[r];a===!0?k=!0:"mousedown"==a?x=!0:"number"==typeof a&&(C=a)}E=n(t.href),N[E]={body:e.body,title:e.title,scrollY:pageYOffset};for(var i,c,l=e.head.children,r=l.length-1;r>=0;r--)i=l[r],i.hasAttribute("data-instant-track")&&(c=i.getAttribute("href")||i.getAttribute("src")||i.innerHTML,I.push(c));L=new XMLHttpRequest,L.addEventListener("readystatechange",m),v(!0),W.init(),o("change",!0),addEventListener("popstate",function(){var e=n(t.href);if(e!=E){if(!(e in N))return void(t.href=t.href);N[E].scrollY=pageYOffset,E=e,s(N[e].title,N[e].body,!1,N[e].scrollY)}})}}function b(e,t){z[e].push(t)}var E,T,w,L,k,x,C,A=navigator.userAgent,M="createTouch"in e,N={},S=!1,D=!1,H=!1,B=!1,F={},Y=!1,O=!1,I=[],z={fetch:[],receive:[],wait:[],change:[]},W=function(){function t(){c=e.create