-
Notifications
You must be signed in to change notification settings - Fork 123
/
ajaxify.min.js
1 lines (1 loc) · 12.8 KB
/
ajaxify.min.js
1
let Ay;function _won(t,e,s=!1){!1===s&&(s={once:!0}),setTimeout(()=>window.addEventListener(t,e,s))}let rootUrl=location.origin,inlineclass="ajy-inline",bdy,qa=(t,e=document)=>e.querySelectorAll(t),qs=(t,e=document)=>e.querySelector(t),qha=t=>qs("head").appendChild(t),qba=t=>qs("body").appendChild(t),prC=t=>t.parentNode.removeChild(t),dcE=t=>document.createElement(t),_copyAttributes=(t,e,s)=>{s&&[...t.attributes].forEach(e=>t.removeAttribute(e.name)),[...e.attributes].forEach(e=>"ajy-body"==e.nodeValue||t.setAttribute(e.nodeName,e.nodeValue))};class Ajaxify{constructor(t){function e(t,e,s,r=document){r.addEventListener(t,function(t){for(var r=t.target;r&&r!=this;r=r.parentNode)if(r.matches(e)){s(r,t);break}},!!t.iO("mo"))}String.prototype.iO=function(t){return this.toString().indexOf(t)+1},Ay=this,Ay.s={elements:"body",selector:"a:not(.no-ajaxy)",forms:"form:not(.no-ajaxy)",canonical:!1,refresh:!1,requestDelay:0,scrolltop:"s",scrollDelay:!1,bodyClasses:!0,deltas:!0,asyncdef:!0,alwayshints:!1,inline:!0,inlinehints:!1,inlineskip:"adsbygoogle",inlineappend:!0,intevents:!0,style:!0,prefetchoff:!1,verbosity:0,memoryoff:!1,cb:0,pluginon:!0,passCount:!1,DCLDelay:0},Ay.pass=0,Ay.currentURL="",Ay.h={},Ay.parse=(t,e)=>((e=dcE("div")).insertAdjacentHTML("afterbegin",t),e.firstElementChild),Ay.triggerEvent=t=>{if(!1!==Ay.s.DCLDelay){let e=new Event(t,{bubbles:!0,cancelable:!0}),s="DOMContentLoaded"===t?document:window;0===Ay.s.DCLDelay?s.dispatchEvent(e):setTimeout(()=>{s.dispatchEvent(e)},Ay.s.DCLDelay)}},Ay.trigger=(t,e)=>{let s=new Event("pronto."+t,{bubbles:!0,cancelable:!1});s.data=e||Ay.Rq("e"),window.dispatchEvent(s)},Ay.internal=t=>!!t&&("object"==typeof t&&(t=t.href),""===t||t.substring(0,rootUrl.length)===rootUrl||!t.iO(":")),Ay.intevents=()=>{let t=function(t,e,s=!1){return(this===document||this===window)&&("DOMContentLoaded"==t||"load"==t)&&(s=s?Object.assign(s,{once:!0}):{once:!0}),this&&this.ael(t,e,s)};EventTarget.prototype.ael=EventTarget.prototype.addEventListener,EventTarget.prototype.addEventListener=t};class s{constructor(t){let e=this;e.list="string"==typeof t&&t.length>0&&t.split(", "),e.find=t=>!!t&&!!e.list&&e.list.some(e=>t.iO(e))}}function r(t){Ay.s.verbosity&&console&&console.log(t)}class i{constructor(){let t=0,e=0,s=0,i="",n=0,a=0,y=0,l=/<\!DOCTYPE[^>]*>/i,o=/<(html|head)([\s\>])/gi,c=/<(body)([\s\>])/gi,h=/<\/(html|head|body)\>/gi,A='<div class="ajy-$1"$2',p='<div id="ajy-$1"$2';this.a=function(r,n,l){if(!r)return Ay.cache.g();if(r.iO("/")){if(e=n,s==r)return;return f(r)}if("+"===r)return s=n,e=l,f(n,!0);if("a"===r){a>0&&(b(),y.abort());return}return"s"===r?(a?1:0)+i:"-"===r?d(n):"x"===r?t:Ay.cache.g()?"body"===r?qs("#ajy-"+r,Ay.cache.g()):"script"===r?qa(r,Ay.cache.g()):qs("title"===r?r:".ajy-"+r,Ay.cache.g()):void 0};let d=t=>(Ay.pass++,g(t),qa("body > script").forEach(t=>!!t.classList.contains(inlineclass)&&prC(t)),Ay.scripts.t(),Ay.scripts.s(),Ay.scripts.c()),f=(t,r)=>(t.iO("#")&&(t=t.split("#")[0]),Ay.Rq("is")||!Ay.cache.l(t))?m(t,r):(s=0,e)?e():void 0,u=(t,e)=>{if(e){var s=e.cloneNode(!0);qa("script",s).forEach(t=>prC(t)),_copyAttributes(t,s,!0),t.innerHTML=s.innerHTML}},g=t=>Ay.cache.g()&&!$(t)&&t.forEach(function(t){u(t,qs("#"+t.getAttribute("id"),Ay.cache.g()))}),$=t=>"body"==t[0].tagName.toLowerCase()&&(u(bdy,qs("#ajy-body",Ay.cache.g())),1),m=(e,s)=>{var n=Ay.Rq("is");i=s?"p":"c",y=new AbortController,a++,fetch(e,{method:n?"POST":"GET",cache:"default",mode:"same-origin",headers:{"X-Requested-With":"XMLHttpRequest"},body:n?Ay.Rq("d"):null,signal:y.signal}).then(r=>{if(!r.ok||!v(r)){s||(location.href=e);return}return t=r,r.text()}).then(s=>{if(b(1),s)return t.responseText=s,q(e,s)}).catch(t=>{if("AbortError"!==t.name)try{return Ay.trigger("error",t),r("Response text : "+t.message),q(e,t.message,t)}catch(s){}}).finally(()=>a--)},b=t=>(s=0,t?0:e=0),q=(t,s,r)=>Ay.cache.s(Ay.parse(R(s)))&&(Ay.pages.p([t,Ay.cache.g()]),1)&&e&&e(r),v=t=>(n=t.headers.get("content-type"))&&(n.iO("html")||n.iO("form-")),R=t=>dcE("html").innerHTML=_(t).trim(),_=t=>String(t).replace(l,"").replace(o,A).replace(c,p).replace(h,"</div>")}}class n{constructor(){let t=0,e=0,s=0,r=0,i=0,n=0,a=!1;this.a=function(l,o,c){if("="===l)return o?n===Ay.currentURL||n===a:n===Ay.currentURL;if("!"===l)return a=n;if("?"===l){let h=Ay.fn("s");return h.iO("0")||o||Ay.fn("a"),("1c"!==h||!o)&&("1p"===h&&o&&Ay.s.memoryoff&&Ay.fn("a"),!0)}if("v"===l){if(!o||(y(o,c),!Ay.internal(n)))return!1;l="i"}return"i"===l?(t=!1,e=null,s=!0,r=!1,n):"h"===l?(o&&("string"==typeof o&&(i=0),n=o.href?o.href:o),n):"e"===l?(o&&y(o,c),i||n):"p"===l?(void 0!==o&&(s=o),s):"is"===l?(void 0!==o&&(t=o),t):"d"===l?(o&&(e=o),e):"C"===l?(void 0!==o&&(r=o),r):"c"===l?!r||r===o||o.iO("#")||o.iO("?")?o:r:void 0};let y=(t,e)=>n="string"!=typeof(i=t)?i.currentTarget&&i.currentTarget.href||e&&e.href||i.currentTarget.action||i.originalEvent.state.url:i}}class a{constructor(){let t=0,e=0;this.a=function(i,n){Ay.s.forms&&i&&("d"===i&&(e=n),"a"===i&&e.forEach(e=>{Array.prototype.filter.call(qa(Ay.s.forms,e),function(t){let e=t.getAttribute("action");return Ay.internal(e&&e.length>0?e:Ay.currentURL)}).forEach(e=>{e.addEventListener("submit",e=>{t=e.target,n=s();var i="get",a=t.getAttribute("method");a.length>0&&"post"==a.toLowerCase()&&(i="post");var y,l=t.getAttribute("action");return y=l&&l.length>0?l:Ay.currentURL,Ay.Rq("v",e),"get"==i?y=r(y,n):(Ay.Rq("is",!0),Ay.Rq("d",n)),Ay.trigger("submit",y),Ay.pronto(0,{href:y}),e.preventDefault(),!1})})}))};let s=()=>{let e=new FormData(t),s=qs("input[name][type=submit]",t);return s&&e.append(s.getAttribute("name"),s.value),e},r=(t,e)=>{let s="";for(var[r,i]of(t.iO("?")&&(t=t.substring(0,t.iO("?"))),e.entries()))s+=`${r}=${encodeURIComponent(i)}&`;return`${t}?${s.slice(0,-1)}`}}}class y{constructor(){let t=0,i=0,n=150,y=0;Ay.h.prefetchoff=new s(Ay.s.prefetchoff),this.a=function(e,s){if(s){if("i"===s)return bdy=document.body,e.length||(e="body"),t=qa(e),Ay.frms=new a().a,Ay.s.idleTime&&(Ay.slides=new classSlides(Ay).a),Ay.scrolly=new Scrolly,(Ay.offsets=new Offsets).f(),Ay.hApi=new HApi,l(),e;if("object"==typeof s){Ay.Rq("h",s),d();return}s.iO("/")&&(Ay.Rq("h",s),d(!0))}};let l=()=>{Ay.hApi.r(window.location.href),window.addEventListener("popstate",u),!0!==Ay.s.prefetchoff&&(e("mouseenter",Ay.s.selector,o),e("mouseleave",Ay.s.selector,c),e("touchstart",Ay.s.selector,h)),e("click",Ay.s.selector,p,bdy),Ay.frms("d",qa("body")),Ay.frms("a"),Ay.frms("d",t),Ay.s.idleTime&&Ay.slides("i")},o=(t,e)=>(c(),y=setTimeout(()=>h(t,e),n)),c=()=>clearTimeout(y),h=(t,e)=>{if(!0!==Ay.s.prefetchoff&&Ay.Rq("?",!0)){var s=Ay.Rq("v",e,t);Ay.Rq("=",!0)||!s||Ay.h.prefetchoff.find(s)||Ay.fn("+",s,()=>!1)}},A=t=>(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation()),p=(t,e,s)=>{if(Ay.Rq("?")){var r=Ay.Rq("v",e,t);if(!(!r||m(t))){if("#"===r.substr(-1))return!0;if(b())return Ay.hApi.r(r),!0;Ay.scrolly.p(),A(e),Ay.Rq("=")&&Ay.hApi.r(),(Ay.s.refresh||!Ay.Rq("="))&&d(s)}}},d=t=>{Ay.Rq("!"),t&&Ay.Rq("p",!1),Ay.fn(Ay.Rq("h"),t=>{t&&(r("Error in _request : "+t),Ay.trigger("error",t)),f()})},f=()=>{Ay.s.requestDelay?(i&&clearTimeout(i),i=setTimeout(g,Ay.s.requestDelay)):g()},u=t=>{var e=window.location.href;Ay.Rq("i"),Ay.Rq("h",e),Ay.Rq("p",!1),Ay.scrolly.p(),e&&e!==Ay.currentURL&&Ay.fn(e,f)},g=()=>{Ay.s.bodyClasses&&_copyAttributes(bdy,Ay.fn("body"),!0);var e,s=Ay.Rq("h");s=Ay.Rq("c",s),Ay.Rq("p")?Ay.hApi.p(s):Ay.hApi.r(s),(e=Ay.fn("title"))&&(qs("title").innerHTML=e.innerHTML),Ay.Rq("C",Ay.fn("-",t)),Ay.frms("a"),Ay.scrolly.l(),$(s),Ay.triggerEvent("DOMContentLoaded"),Ay.s.passCount&&(qs("#"+Ay.s.passCount).innerHTML="Pass: "+Ay.pass),Ay.s.cb&&Ay.s.cb()},$=t=>{t="/"+t.replace(rootUrl,""),void 0!==window.ga?window.ga("send","pageview",t):void 0!==window._gaq&&window._gaq.push(["_trackPageview",t])},m=t=>{var e=Ay.Rq("h"),s=Ay.Rq("e"),r=s.currentTarget.target||t.target;return s.which>1||s.metaKey||s.ctrlKey||s.shiftKey||s.altKey||"_blank"===r||e.iO("wp-login")||e.iO("wp-admin")},b=()=>{var t=Ay.Rq("e");return t.hash&&t.href.replace(t.hash,"")===window.location.href.replace(location.hash,"")||t.href===window.location.href+"#"}}}Ay.init=()=>{let e=t;return e&&"string"==typeof e?Ay.pronto(0,e):("complete"!==document.readyState&&("loading"===document.readyState||document.documentElement.doScroll)?document.addEventListener("DOMContentLoaded",l):l(),Ay)};let l=()=>{Ay.s=Object.assign(Ay.s,t),(Ay.pages=new Pages).f(),Ay.pronto=new y().a,o()&&(Ay.pronto(Ay.s.elements,"i"),Ay.s.deltas&&Ay.scripts.o())},o=()=>window.history&&window.history.pushState&&window.history.replaceState&&Ay.s.pluginon?(r("Ajaxify loaded..."),Ay.scripts=new Scrpts,Ay.h.inlinehints=new s(Ay.s.inlinehints),Ay.h.inlineskip=new s(Ay.s.inlineskip),Ay.cache=new Cache,Ay.memory=new Memory,Ay.h.memoryoff=new s(Ay.s.memoryoff),Ay.fn=Ay.getPage=new i().a,Ay.detScripts=new DetScripts,Ay.addAll=new AddAll,Ay.h.alwayshints=new s(Ay.s.alwayshints),Ay.Rq=new n().a,!0):(r("Gracefully exiting..."),!1);Ay.s.intevents&&Ay.intevents(),Ay.init()}}class Cache{g(){return this.d}s(t){return this.d=t}l(t){let e=Ay.memory.l(t);return this.s(!1===e?e:Ay.pages.l(e))}}class Memory{l(t){return!!t&&!0!==Ay.s.memoryoff&&(!1===Ay.s.memoryoff?t:!Ay.h.memoryoff.find(t)&&t)}}class Pages{f(){this.d=[]}l(t){if(this.P(t))return this.d[this.i][1]}p(t){this.P(t[0])?this.d[this.i]=t:this.d.push(t)}P(t){return(this.i=this.d.findIndex(e=>e[0]==t))+1}}class DetScripts{d(t){if(!(this.h=Ay.pass?Ay.fn("head"):qs("head")))return!0;this.lk=qa("link",this.h),t.j=Ay.pass?Ay.fn("script"):qa("script"),t.c=this.x("stylesheet"),t.y=qa("style",this.h),t.can=this.x("canonical")}x(t){return Array.prototype.filter.call(this.lk,e=>e.getAttribute("rel").iO(t))}}class Offsets{f(){this.d=[]}l(t){return t.iO("?")&&(t=t.split("?")[0]),this.O(t)?this.d[this.i][1]:0}p(t){let e=t.iO("?")?t.split("?")[0]:t,s=e.iO("#")?e.split("#")[0]:e,r=[s,document.documentElement&&document.documentElement.scrollTop||document.body.scrollTop];this.O(s)?this.d[this.i]=r:this.d.push(r)}O(t){return(this.i=this.d.findIndex(e=>e[0]==t))+1}}class Scrolly{constructor(){"scrollRestoration"in history&&(history.scrollRestoration="manual")}p(){"s"==Ay.s.scrolltop&&Ay.offsets.p(Ay.currentURL)}l(){let t=Ay.currentURL;if(t.iO("#")&&t.iO("#")<t.length-1){let e=qs("#"+t.split("#")[1]);if(!e)return;let s=e.getBoundingClientRect();return this.s(s.top+window.pageYOffset-document.documentElement.clientTop)}"s"==Ay.s.scrolltop?this.s(Ay.offsets.l(t)):Ay.s.scrolltop&&this.s(0)}s(t){!1===Ay.s.scrollDelay?window.scrollTo(0,t):setTimeout(()=>window.scrollTo(0,t),Ay.s.scrollDelay)}}class HApi{r(t){let e=this.u(t);history.replaceState({url:e},"state-"+e,e)}p(t){let e=this.u(t);e!==window.location.href&&history.pushState({url:e},"state-"+e,e)}u(t){return t&&(Ay.currentURL=t),Ay.currentURL}}class AddAll{constructor(){this.CSS=[],this.JS=[],this.TCS=[]}a(t,e){if(this.TCS=[],t.length&&"n"!==Ay.s.deltas){if(this.PK=e,!Ay.s.deltas)return t.forEach(t=>this.iScript(t));this.O="href"==e?this.CSS:this.JS,t.forEach(t=>{let s=this.gA(t);if(!Ay.pass)return s&&this.O.push(s);if("always"==t.getAttribute("data-class")||Ay.h.alwayshints.find(s)){this.removeScript(),this.iScript(t);return}if(s){this.O.some(t=>t==s)||(this.O.push(s),this.iScript(t));return}"href"==e||t.classList.contains("no-ajaxy")||Ay.scripts.i(t)}),"src"===e&&Promise.all(this.TCS).then(()=>{}).catch(t=>{}).finally(()=>Ay.triggerEvent("load"))}}gA(t){return this.u=t[this.PK]}appendScript(t){return new Promise((e,s)=>{var r=dcE("script");r.onload=()=>e(),r.onreadystatechange=()=>e(),r.onerror=t=>s(t),r.async=!t.hasAttribute("defer")&&Ay.s.asyncdef,_copyAttributes(r,t),qba(r)})}iScript(t){return(this.gA(t),"href"==this.PK)?qha(Ay.parse('<link rel="stylesheet" type="text/css" href="*" />'.replace("*",this.u))):this.u?void this.TCS.push(this.appendScript(t)):Ay.scripts.i(t)}removeScript(){qa(("href"==this.PK?'link[href*="!"]':'script[src*="!"]').replace("!",this.u.substring(this.u.lastIndexOf("/")+1))).forEach(t=>prC(t))}}class Scrpts{constructor(){this.S={}}s(){this.allstyle(this.S.y)}o(){this.d(),this.a()}c(){return!!Ay.s.canonical&&!!this.S.can&&this.S.can.getAttribute("href")}d(){return Ay.detScripts.d(this.S)}i(t){this.one(t)}t(){this.d()||this.a()}a(){this.delta(this.S)}allstyle(t){Ay.s.style&&t&&(qa("style",qs("head")).forEach(t=>prC(t)),t.forEach(t=>{let e=Ay.parse("<style>"+t.textContent+"</style>");_copyAttributes(e,t),qha(e)}))}one(t){!(this.x=t.textContent).iO("new Ajaxify(")&&(Ay.s.inline&&!Ay.h.inlineskip.find(this.x)||t.classList.contains("ajaxy")||Ay.h.inlinehints.find(this.x))&&this.add(t)}add(S){if(this.x&&this.x.length){if(Ay.s.inlineappend||S.getAttribute("type")&&!S.getAttribute("type").iO("text/javascript"))try{return this.app(S)}catch(e){}try{eval(this.x)}catch(e1){lg("Error in inline script : "+this.x+"\nError code : "+e1)}}}app(t){let e=dcE("script");_copyAttributes(e,t),e.classList.add(inlineclass);try{e.appendChild(document.createTextNode(this.x))}catch(s){e.text=this.x}return qs("body").appendChild(e)}delta(t){Ay.addAll.a(t.c,"href"),Ay.addAll.a(t.j,"src")}}