ajaxify 8.1.2 → 8.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ajaxify.js +110 -155
- package/ajaxify.min.js +1 -1
- package/package.json +1 -1
package/ajaxify.js
CHANGED
|
@@ -15,6 +15,15 @@ Ajaxifies the whole site, dynamically replacing the elements specified in "eleme
|
|
|
15
15
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
+
let $;
|
|
19
|
+
|
|
20
|
+
//Module global helpers
|
|
21
|
+
let rootUrl = location.origin, inlineclass = "ajy-inline",
|
|
22
|
+
bdy,
|
|
23
|
+
qa=(s,o=document)=>o.querySelectorAll(s),
|
|
24
|
+
qs=(s,o=document)=>o.querySelector(s);
|
|
25
|
+
|
|
26
|
+
|
|
18
27
|
// The main plugin - Ajaxify
|
|
19
28
|
// Is passed the global options
|
|
20
29
|
// Checks for necessary pre-conditions - otherwise gracefully degrades
|
|
@@ -22,7 +31,7 @@ Ajaxifies the whole site, dynamically replacing the elements specified in "eleme
|
|
|
22
31
|
// Calls Pronto
|
|
23
32
|
class Ajaxify { constructor(options) {
|
|
24
33
|
String.prototype.iO = function(s) { return this.toString().indexOf(s) + 1; }; //Intuitively better understandable shorthand for String.indexOf() - String.iO()
|
|
25
|
-
|
|
34
|
+
$ = this;
|
|
26
35
|
|
|
27
36
|
//Options default values
|
|
28
37
|
$.s = {
|
|
@@ -43,11 +52,10 @@ $.s = {
|
|
|
43
52
|
asyncdef : true, // default async value for dynamically inserted external scripts, false = synchronous / true = asynchronous
|
|
44
53
|
alwayshints : false, // strings, - separated by ", " - if matched in any external script URL - these are always loaded on every page load
|
|
45
54
|
inline : true, // true = all inline scripts loaded, false = only specific inline scripts are loaded
|
|
46
|
-
inlinesync : true, // synchronise inline scripts loading by adding a central tiny delay to all of them
|
|
47
55
|
inlinehints : false, // strings - separated by ", " - if matched in any inline scripts - only these are executed - set "inline" to false beforehand
|
|
48
56
|
inlineskip : "adsbygoogle", // strings - separated by ", " - if matched in any inline scripts - these are NOT are executed - set "inline" to true beforehand
|
|
49
57
|
inlineappend : true, // append scripts to the main content element, instead of "eval"-ing them
|
|
50
|
-
intevents: true, // intercept events that are fired only on classic page load and simulate their trigger on ajax page load ("DOMContentLoaded"
|
|
58
|
+
intevents: true, // intercept events that are fired only on classic page load and simulate their trigger on ajax page load ("DOMContentLoaded")
|
|
51
59
|
style : true, // true = all style tags in the head loaded, false = style tags on target page ignored
|
|
52
60
|
prefetchoff : false, // Plugin pre-fetches pages on hoverIntent - true = set off completely // strings - separated by ", " - hints to select out
|
|
53
61
|
|
|
@@ -60,38 +68,15 @@ $.s = {
|
|
|
60
68
|
};
|
|
61
69
|
|
|
62
70
|
|
|
63
|
-
$.pass = 0; $.currentURL = "";
|
|
71
|
+
$.pass = 0; $.currentURL = ""; $.h = {};
|
|
64
72
|
$.parse = (s, pl) => (pl = document.createElement('div'), pl.insertAdjacentHTML('afterbegin', s), pl.firstElementChild); // HTML parser
|
|
65
|
-
$.trigger = (t, e) => { let ev = document.createEvent('HTMLEvents'); ev.initEvent("pronto." + t, true, false); ev.data = e ? e : $.Rq("e"); window.dispatchEvent(ev); document.dispatchEvent(ev); }
|
|
66
|
-
$.internal = (url) => { if (!url) return false; if (typeof(url) === "object") url = url.href; if (url==="") return true; return url.substring(0,rootUrl.length) === rootUrl || !url.iO(":"); }
|
|
73
|
+
$.trigger = (t, e) => { let ev = document.createEvent('HTMLEvents'); ev.initEvent("pronto." + t, true, false); ev.data = e ? e : $.Rq("e"); window.dispatchEvent(ev); document.dispatchEvent(ev); };
|
|
74
|
+
$.internal = (url) => { if (!url) return false; if (typeof(url) === "object") url = url.href; if (url==="") return true; return url.substring(0,rootUrl.length) === rootUrl || !url.iO(":"); };
|
|
67
75
|
$.intevents = () => {
|
|
68
|
-
let iFn = function (a, b, c = false) { if ((this === document || this === window) &&
|
|
76
|
+
let iFn = function (a, b, c = false) { if ((this === document || this === window) && a=="DOMContentLoaded") setTimeout(b); else this.ael(a,b,c);}; // if "DOMContentLoaded" - execute function, else - add event listener
|
|
69
77
|
EventTarget.prototype.ael = EventTarget.prototype.addEventListener; // store original method
|
|
70
78
|
EventTarget.prototype.addEventListener = iFn; // start intercepting event listener addition
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
//Module global variables
|
|
74
|
-
let rootUrl = location.origin, api = window.history && window.history.pushState && window.history.replaceState,
|
|
75
|
-
|
|
76
|
-
//Regexes for escaping fetched HTML of a whole page - best of Baluptons Ajaxify
|
|
77
|
-
//Makes it possible to pre-fetch an entire page
|
|
78
|
-
docType = /<\!DOCTYPE[^>]*>/i,
|
|
79
|
-
tagso = /<(html|head|link)([\s\>])/gi,
|
|
80
|
-
tagsod = /<(body)([\s\>])/gi,
|
|
81
|
-
tagsc = /<\/(html|head|body|link)\>/gi,
|
|
82
|
-
|
|
83
|
-
//Helper strings
|
|
84
|
-
div12 = '<div class="ajy-$1"$2',
|
|
85
|
-
divid12 = '<div id="ajy-$1"$2',
|
|
86
|
-
linki = '<link rel="stylesheet" type="text/css" href="*" />',
|
|
87
|
-
linkr = 'link[href*="!"]',
|
|
88
|
-
scrr = 'script[src*="!"]',
|
|
89
|
-
inlineclass = "ajy-inline";
|
|
90
|
-
|
|
91
|
-
//Global helpers
|
|
92
|
-
let doc=document, bdy,
|
|
93
|
-
qa=(s,o=doc)=>o.querySelectorAll(s),
|
|
94
|
-
qs=(s,o=doc)=>o.querySelector(s);
|
|
79
|
+
};
|
|
95
80
|
|
|
96
81
|
function _copyAttributes(el, $S, flush) { //copy all attributes of element generically
|
|
97
82
|
if (flush) [...el.attributes].forEach(e => el.removeAttribute(e.name)); //delete all old attributes
|
|
@@ -110,77 +95,12 @@ function _on(eventName, elementSelector, handler, el = document) { //e.currentTa
|
|
|
110
95
|
}, !!eventName.iO('mo'));
|
|
111
96
|
}
|
|
112
97
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
Hints.prototype.find = function (t) {return (!t || !this.myHints) ? false : this.myHints.some(h => t.iO(h))}; //iterate through hints within passed text (t)
|
|
118
|
-
|
|
119
|
-
function lg(m){ $.s.verbosity && console && console.log(m); }
|
|
120
|
-
|
|
121
|
-
// The stateful Cache class
|
|
122
|
-
// Usage - parameter "o" values:
|
|
123
|
-
// none - returns currently cached page
|
|
124
|
-
// <URL> - returns page with specified URL
|
|
125
|
-
// <object> - saves the page in cache
|
|
126
|
-
// f - flushes the cache
|
|
127
|
-
class Cache { constructor() {
|
|
128
|
-
let d = false;
|
|
129
|
-
|
|
130
|
-
this.a = function (o) {
|
|
131
|
-
if (!o) return d;
|
|
132
|
-
|
|
133
|
-
if (typeof o === "string") { //URL or "f" passed
|
|
134
|
-
if(o === "f") { //"f" passed -> flush
|
|
135
|
-
$.pages("f"); //delegate flush to $.pages
|
|
136
|
-
lg("Cache flushed");
|
|
137
|
-
} else d = $.pages($.memory(o)); //URL passed -> look up page in memory
|
|
138
|
-
|
|
139
|
-
return d; //return cached page
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (typeof o === "object") {
|
|
143
|
-
d = o;
|
|
144
|
-
return d;
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
}}
|
|
148
|
-
|
|
149
|
-
// The stateful Memory class
|
|
150
|
-
// Usage: $.memory(<URL>) - returns the same URL if not turned off internally
|
|
151
|
-
class Memory { constructor(options) {
|
|
152
|
-
|
|
153
|
-
this.a = function (h) {
|
|
154
|
-
if (!h || $.s.memoryoff === true) return false;
|
|
155
|
-
if ($.s.memoryoff === false) return h;
|
|
156
|
-
return Hints($.s.memoryoff).find(h) ? false : h;
|
|
157
|
-
};
|
|
98
|
+
class Hints { constructor(h) { let _ = this;
|
|
99
|
+
_.list = (typeof h === 'string' && h.length > 0) ? h.split(", ") : false; //hints are passed as a comma separated string
|
|
100
|
+
_.find = (t) => (!t || !_.list) ? false : _.list.some(h => t.iO(h)); //iterate through hints within passed text (t)
|
|
158
101
|
}}
|
|
159
102
|
|
|
160
|
-
|
|
161
|
-
// Usage - parameter "h" values:
|
|
162
|
-
// <URL> - returns page with specified URL from internal array
|
|
163
|
-
// <object> - saves the passed page in internal array
|
|
164
|
-
// false - returns false
|
|
165
|
-
class Pages { constructor() {
|
|
166
|
-
let d = [], i = -1;
|
|
167
|
-
|
|
168
|
-
this.a = function (h) {
|
|
169
|
-
if (typeof h === "string") {
|
|
170
|
-
if(h === "f") d = [];
|
|
171
|
-
else if((i=_iPage(h)) !== -1) return d[i][1];
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (typeof h === "object") {
|
|
175
|
-
if((i=_iPage(h)) === -1) d.push(h);
|
|
176
|
-
else d[i] = h;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (typeof h === "boolean") return false;
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
let _iPage = h => d.findIndex(e => e[0] == h)
|
|
183
|
-
}}
|
|
103
|
+
function lg(m){ $.s.verbosity && console && console.log(m); }
|
|
184
104
|
|
|
185
105
|
// The GetPage class
|
|
186
106
|
// First parameter (o) is a switch:
|
|
@@ -192,10 +112,21 @@ class Pages { constructor() {
|
|
|
192
112
|
// otherwise - returns selection of current page to client
|
|
193
113
|
|
|
194
114
|
class GetPage { constructor() {
|
|
195
|
-
let rsp = 0, cb = 0, plus = 0, rt = "", ct = 0, rc = 0, ac = 0
|
|
196
|
-
|
|
115
|
+
let rsp = 0, cb = 0, plus = 0, rt = "", ct = 0, rc = 0, ac = 0,
|
|
116
|
+
|
|
117
|
+
//Regexes for escaping fetched HTML of a whole page - best of Baluptons Ajaxify
|
|
118
|
+
//Makes it possible to pre-fetch an entire page
|
|
119
|
+
docType = /<\!DOCTYPE[^>]*>/i,
|
|
120
|
+
tagso = /<(html|head|link)([\s\>])/gi,
|
|
121
|
+
tagsod = /<(body)([\s\>])/gi,
|
|
122
|
+
tagsc = /<\/(html|head|body|link)\>/gi,
|
|
123
|
+
|
|
124
|
+
//Helper strings
|
|
125
|
+
div12 = '<div class="ajy-$1"$2',
|
|
126
|
+
divid12 = '<div id="ajy-$1"$2';
|
|
127
|
+
|
|
197
128
|
this.a = function (o, p, p2) {
|
|
198
|
-
if (!o) return $.cache();
|
|
129
|
+
if (!o) return $.cache.g();
|
|
199
130
|
|
|
200
131
|
if (o.iO("/")) {
|
|
201
132
|
cb = p;
|
|
@@ -214,11 +145,11 @@ class GetPage { constructor() {
|
|
|
214
145
|
if (o === "-") return _lSel(p);
|
|
215
146
|
if (o === "x") return rsp;
|
|
216
147
|
|
|
217
|
-
if (!$.cache()) return;
|
|
218
|
-
if (o === "body") return qs("#ajy-" + o, $.cache());
|
|
219
|
-
if (o === "script") return qa(o, $.cache());
|
|
148
|
+
if (!$.cache.g()) return;
|
|
149
|
+
if (o === "body") return qs("#ajy-" + o, $.cache.g());
|
|
150
|
+
if (o === "script") return qa(o, $.cache.g());
|
|
220
151
|
|
|
221
|
-
return qs((o === "title") ? o : ".ajy-" + o, $.cache());
|
|
152
|
+
return qs((o === "title") ? o : ".ajy-" + o, $.cache.g());
|
|
222
153
|
};
|
|
223
154
|
let _lSel = $t => (
|
|
224
155
|
$.pass++,
|
|
@@ -230,18 +161,13 @@ let _lSel = $t => (
|
|
|
230
161
|
),
|
|
231
162
|
_lPage = (h, pre) => {
|
|
232
163
|
if (h.iO("#")) h = h.split("#")[0];
|
|
233
|
-
if ($.Rq("is") || !$.cache(h)) return _lAjax(h, pre);
|
|
164
|
+
if ($.Rq("is") || !$.cache.l(h)) return _lAjax(h, pre);
|
|
234
165
|
|
|
235
166
|
plus = 0;
|
|
236
167
|
if (cb) return cb();
|
|
237
168
|
},
|
|
238
169
|
_ld = ($t, $h) => {
|
|
239
|
-
if(!$h)
|
|
240
|
-
lg("Inserting placeholder for ID: " + $t.getAttribute("id"));
|
|
241
|
-
var tagN = $t.tagName.toLowerCase();
|
|
242
|
-
$t.parentNode.replaceChild($.parse("<" + tagN + " id='" + $t.getAttribute("id") + "'></" + tagN + ">"), $t);
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
170
|
+
if(!$h) return; //no input
|
|
245
171
|
|
|
246
172
|
var $c = $h.cloneNode(true); // clone element node (true = deep clone)
|
|
247
173
|
qa("script", $c).forEach(e => e.parentNode.removeChild(e));
|
|
@@ -249,10 +175,10 @@ let _lSel = $t => (
|
|
|
249
175
|
$t.innerHTML = $c.innerHTML;
|
|
250
176
|
},
|
|
251
177
|
_lEls = $t =>
|
|
252
|
-
$.cache() && !_isBody($t) && $t.forEach(function($el) {
|
|
253
|
-
_ld($el, qs("#" + $el.getAttribute("id"), $.cache()));
|
|
178
|
+
$.cache.g() && !_isBody($t) && $t.forEach(function($el) {
|
|
179
|
+
_ld($el, qs("#" + $el.getAttribute("id"), $.cache.g()));
|
|
254
180
|
}),
|
|
255
|
-
_isBody = $t => $t[0].tagName.toLowerCase() == "body" && (_ld(bdy, qs("#ajy-body", $.cache())), 1),
|
|
181
|
+
_isBody = $t => $t[0].tagName.toLowerCase() == "body" && (_ld(bdy, qs("#ajy-body", $.cache.g())), 1),
|
|
256
182
|
_lAjax = (hin, pre) => {
|
|
257
183
|
var ispost = $.Rq("is");
|
|
258
184
|
if (pre) rt="p"; else rt="c";
|
|
@@ -289,7 +215,7 @@ let _lSel = $t => (
|
|
|
289
215
|
}).finally(() => rc--); // reset active request counter
|
|
290
216
|
},
|
|
291
217
|
_cl = c => (plus = 0, (!c) ? cb = 0 : 0), // clear plus AND/OR callback
|
|
292
|
-
_cache = (href, h, err) => $.cache($.parse(_parseHTML(h))) && ($.pages([href, $.cache()]), 1) && cb && cb(err),
|
|
218
|
+
_cache = (href, h, err) => $.cache.s($.parse(_parseHTML(h))) && ($.pages.p([href, $.cache.g()]), 1) && cb && cb(err),
|
|
293
219
|
_isHtml = x => (ct = x.headers.get("content-type")) && (ct.iO("html") || ct.iO("form-")),
|
|
294
220
|
_parseHTML = h => document.createElement("html").innerHTML = _replD(h).trim(),
|
|
295
221
|
_replD = h => String(h).replace(docType, "").replace(tagso, div12).replace(tagsod, divid12).replace(tagsc, "</div>")
|
|
@@ -303,8 +229,10 @@ let _lSel = $t => (
|
|
|
303
229
|
// otherwise - delta loading
|
|
304
230
|
class Scripts { constructor() {
|
|
305
231
|
let $s = false, txt = 0;
|
|
232
|
+
$.h.inlinehints = new Hints($.s.inlinehints);
|
|
233
|
+
$.h.inlineskip = new Hints($.s.inlineskip);
|
|
306
234
|
|
|
307
|
-
|
|
235
|
+
this.a = function (o) {
|
|
308
236
|
if (o === "i") {
|
|
309
237
|
if(!$s) $s = {};
|
|
310
238
|
return true;
|
|
@@ -331,8 +259,8 @@ let _allstyle = $s =>
|
|
|
331
259
|
),
|
|
332
260
|
_onetxt = $s =>
|
|
333
261
|
(!(txt = $s.textContent).iO(").ajaxify(") && (!txt.iO("new Ajaxify(")) &&
|
|
334
|
-
(($.s.inline &&
|
|
335
|
-
|
|
262
|
+
(($.s.inline && !$.h.inlineskip.find(txt)) || $s.classList.contains("ajaxy") ||
|
|
263
|
+
$.h.inlinehints.find(txt))
|
|
336
264
|
) && _addtxt($s),
|
|
337
265
|
_addtxt = $s => {
|
|
338
266
|
if(!txt || !txt.length) return;
|
|
@@ -347,7 +275,7 @@ let _allstyle = $s =>
|
|
|
347
275
|
return qs("body").appendChild(sc);
|
|
348
276
|
},
|
|
349
277
|
_addstyle = t => qs("head").appendChild($.parse('<style>' + t + '</style>')),
|
|
350
|
-
_addScripts = $s => (
|
|
278
|
+
_addScripts = $s => ($.addAll($s.c, "href"), $.addAll($s.j, "src"))
|
|
351
279
|
}}
|
|
352
280
|
|
|
353
281
|
// The DetScripts plugin - stands for "detach scripts"
|
|
@@ -378,7 +306,12 @@ let _rel = (lk, v) => Array.prototype.filter.call(lk, e => e.getAttribute("rel")
|
|
|
378
306
|
// href - operate on stylesheets in the new selection
|
|
379
307
|
// src - operate on JS scripts
|
|
380
308
|
class AddAll { constructor() {
|
|
381
|
-
let $scriptsO = [], $sCssO = [], $sO = [], PK = 0, url = 0
|
|
309
|
+
let $scriptsO = [], $sCssO = [], $sO = [], PK = 0, url = 0,
|
|
310
|
+
linki = '<link rel="stylesheet" type="text/css" href="*" />',
|
|
311
|
+
linkr = 'link[href*="!"]',
|
|
312
|
+
scrr = 'script[src*="!"]';
|
|
313
|
+
|
|
314
|
+
$.h.alwayshints = new Hints($.s.alwayshints);
|
|
382
315
|
|
|
383
316
|
this.a = function ($this, pk) {
|
|
384
317
|
if(!$this.length) return; //ensure input
|
|
@@ -414,7 +347,7 @@ class AddAll { constructor() {
|
|
|
414
347
|
};
|
|
415
348
|
let _allScripts = $t => $t.forEach(e => _iScript(e)),
|
|
416
349
|
_newArray = $t => $t.forEach(e => (url = e.getAttribute(PK)) ? $scriptsO.push(url) : 0),
|
|
417
|
-
_classAlways = $t => $t.getAttribute("data-class") == "always" ||
|
|
350
|
+
_classAlways = $t => $t.getAttribute("data-class") == "always" || $.h.alwayshints.find(url),
|
|
418
351
|
_iScript = $S => {
|
|
419
352
|
url = $S.getAttribute(PK);
|
|
420
353
|
|
|
@@ -563,7 +496,7 @@ class Frms { constructor() {
|
|
|
563
496
|
|
|
564
497
|
q.preventDefault(); //prevent default form action
|
|
565
498
|
return(false); //success -> disable default behaviour
|
|
566
|
-
})
|
|
499
|
+
});
|
|
567
500
|
});
|
|
568
501
|
});
|
|
569
502
|
};
|
|
@@ -613,6 +546,8 @@ let _iOffset = h => d.findIndex(e => e[0] == h)
|
|
|
613
546
|
// ! - scroll to current page offset
|
|
614
547
|
class Scrolly { constructor() {
|
|
615
548
|
|
|
549
|
+
if ('scrollRestoration' in history) history.scrollRestoration = 'manual';
|
|
550
|
+
|
|
616
551
|
this.a = function (o) {
|
|
617
552
|
if(!o) return; //ensure operator
|
|
618
553
|
|
|
@@ -639,23 +574,7 @@ class Scrolly { constructor() {
|
|
|
639
574
|
|
|
640
575
|
//default -> do nothing
|
|
641
576
|
};
|
|
642
|
-
let _scrll = o => window.scrollTo(0, o)
|
|
643
|
-
}}
|
|
644
|
-
|
|
645
|
-
// The hApi plugin - manages operatios on the History API centrally
|
|
646
|
-
// Second parameter (p) - set global currentURL
|
|
647
|
-
// Switch (o) values:
|
|
648
|
-
// = - perform a replaceState, using currentURL
|
|
649
|
-
// otherwise - perform a pushState, using currentURL
|
|
650
|
-
class HApi { constructor() {
|
|
651
|
-
|
|
652
|
-
this.a = function (o, p) {
|
|
653
|
-
if(!o) return; //ensure operator
|
|
654
|
-
if(p) $.currentURL = p; //if p given -> update current URL
|
|
655
|
-
|
|
656
|
-
if(o === "=") history.replaceState({ url: $.currentURL }, "state-" + $.currentURL, $.currentURL); //perform replaceState
|
|
657
|
-
else if ($.currentURL !== window.location.href) history.pushState({ url: $.currentURL }, "state-" + $.currentURL, $.currentURL); //perform pushState
|
|
658
|
-
};
|
|
577
|
+
let _scrll = o => setTimeout(() => window.scrollTo(0, o), 10) //delay of 10 milliseconds on all scroll effects
|
|
659
578
|
}}
|
|
660
579
|
|
|
661
580
|
// The Pronto plugin - Pronto variant of Ben Plum's Pronto plugin - low level event handling in general
|
|
@@ -666,6 +585,7 @@ class HApi { constructor() {
|
|
|
666
585
|
// <URL> - set "h" variable of Rq hard and continue with _request()
|
|
667
586
|
class Pronto { constructor() {
|
|
668
587
|
let $gthis = 0, requestTimer = 0, pd = 150, ptim = 0;
|
|
588
|
+
$.h.prefetchoff = new Hints($.s.prefetchoff);
|
|
669
589
|
|
|
670
590
|
this.a = function ($this, h) {
|
|
671
591
|
if(!h) return; //ensure data
|
|
@@ -678,7 +598,7 @@ class Pronto { constructor() {
|
|
|
678
598
|
if($.s.idleTime) $.slides = new classSlides($).a; //initialise optional slideshow sub-plugin
|
|
679
599
|
$.scrolly = new Scrolly().a; //initialise scroll effects sub-plugin
|
|
680
600
|
$.offsets = new Offsets().a;
|
|
681
|
-
$.hApi = new HApi()
|
|
601
|
+
$.hApi = new HApi();
|
|
682
602
|
_init_p(); //initialise Pronto sub-plugin
|
|
683
603
|
return $this; //return query selector for chaining
|
|
684
604
|
}
|
|
@@ -695,7 +615,7 @@ class Pronto { constructor() {
|
|
|
695
615
|
}
|
|
696
616
|
};
|
|
697
617
|
let _init_p = () => {
|
|
698
|
-
$.hApi(
|
|
618
|
+
$.hApi.r(window.location.href);
|
|
699
619
|
window.addEventListener("popstate", _onPop);
|
|
700
620
|
if ($.s.prefetchoff !== true) {
|
|
701
621
|
_on("mouseenter", $.s.selector, _preftime); // start prefetch timeout
|
|
@@ -708,13 +628,13 @@ let _init_p = () => {
|
|
|
708
628
|
$.frms("d", $gthis);
|
|
709
629
|
if($.s.idleTime) $.slides("i");
|
|
710
630
|
},
|
|
711
|
-
_preftime = (t, e) => ptim = setTimeout(()=> _prefetch(t, e), pd), // call prefetch if timeout expires without being cleared by _prefstop
|
|
631
|
+
_preftime = (t, e) => (_prefstop(), ptim = setTimeout(()=> _prefetch(t, e), pd)), // call prefetch if timeout expires without being cleared by _prefstop
|
|
712
632
|
_prefstop = () => clearTimeout(ptim),
|
|
713
633
|
_prefetch = (t, e) => {
|
|
714
634
|
if($.s.prefetchoff === true) return;
|
|
715
635
|
if (!$.Rq("?", true)) return;
|
|
716
636
|
var href = $.Rq("v", e, t);
|
|
717
|
-
if ($.Rq("=", true) || !href ||
|
|
637
|
+
if ($.Rq("=", true) || !href || $.h.prefetchoff.find(href)) return;
|
|
718
638
|
$.fn("+", href, () => false);
|
|
719
639
|
},
|
|
720
640
|
_stopBubbling = e => (
|
|
@@ -728,13 +648,13 @@ let _init_p = () => {
|
|
|
728
648
|
if(!href || _exoticKey(t)) return;
|
|
729
649
|
if(href.substr(-1) ==="#") return true;
|
|
730
650
|
if(_hashChange()) {
|
|
731
|
-
$.hApi(
|
|
651
|
+
$.hApi.r(href);
|
|
732
652
|
return true;
|
|
733
653
|
}
|
|
734
654
|
|
|
735
655
|
$.scrolly("+");
|
|
736
656
|
_stopBubbling(e);
|
|
737
|
-
if($.Rq("=")) $.hApi(
|
|
657
|
+
if($.Rq("=")) $.hApi.r();
|
|
738
658
|
if($.s.refresh || !$.Rq("=")) _request(notPush);
|
|
739
659
|
},
|
|
740
660
|
_request = notPush => {
|
|
@@ -776,7 +696,7 @@ let _init_p = () => {
|
|
|
776
696
|
var href = $.Rq("h"), title;
|
|
777
697
|
href = $.Rq("c", href);
|
|
778
698
|
|
|
779
|
-
|
|
699
|
+
if($.Rq("p")) $.hApi.p(href); else $.hApi.r(href);
|
|
780
700
|
if(title = $.fn("title")) qs("title").innerHTML = title.innerHTML;
|
|
781
701
|
$.Rq("C", $.fn("-", $gthis));
|
|
782
702
|
$.frms("a");
|
|
@@ -817,7 +737,7 @@ $.init = () => {
|
|
|
817
737
|
|
|
818
738
|
let run = () => {
|
|
819
739
|
$.s = Object.assign($.s, options);
|
|
820
|
-
$.pages = new Pages().
|
|
740
|
+
($.pages = new Pages()).f();
|
|
821
741
|
$.pronto = new Pronto().a;
|
|
822
742
|
if (load()) {
|
|
823
743
|
$.pronto($.s.elements, "i");
|
|
@@ -825,7 +745,7 @@ let run = () => {
|
|
|
825
745
|
}
|
|
826
746
|
},
|
|
827
747
|
load = () => {
|
|
828
|
-
if (!
|
|
748
|
+
if (!(window.history && window.history.pushState && window.history.replaceState) || !$.s.pluginon) {
|
|
829
749
|
lg("Gracefully exiting...");
|
|
830
750
|
return false;
|
|
831
751
|
}
|
|
@@ -835,13 +755,48 @@ let run = () => {
|
|
|
835
755
|
if ($.s.intevents) $.intevents(); // intercept events
|
|
836
756
|
$.scripts = new Scripts().a;
|
|
837
757
|
$.scripts("i");
|
|
838
|
-
$.cache = new Cache()
|
|
839
|
-
$.memory = new Memory().
|
|
758
|
+
$.cache = new Cache();
|
|
759
|
+
$.memory = new Memory(); $.h.memoryoff = new Hints($.s.memoryoff);
|
|
840
760
|
$.fn = $.getPage = new GetPage().a;
|
|
841
761
|
$.detScripts = new DetScripts().a;
|
|
842
762
|
$.addAll = new AddAll().a;
|
|
843
763
|
$.Rq = new RQ().a;
|
|
844
764
|
return true;
|
|
845
|
-
}
|
|
765
|
+
};
|
|
846
766
|
$.init(); // initialize Ajaxify on definition
|
|
847
|
-
}}
|
|
767
|
+
}}
|
|
768
|
+
|
|
769
|
+
// The stateful Cache class
|
|
770
|
+
// this.d = entire current page (as an object)
|
|
771
|
+
class Cache {
|
|
772
|
+
g(){ return this.d } //getter
|
|
773
|
+
s(v){ return this.d = v } //setter
|
|
774
|
+
l(u){ let v = $.memory.l(u); return this.s(v === false ? v : $.pages.l(v)) } //lookup URL and load
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
// The stateful Memory class
|
|
778
|
+
// Usage: $.memory.l(<URL>) - returns the same URL if not turned off internally
|
|
779
|
+
class Memory {
|
|
780
|
+
l(h) {
|
|
781
|
+
if (!h || $.s.memoryoff === true) return false;
|
|
782
|
+
if ($.s.memoryoff === false) return h;
|
|
783
|
+
return $.h.memoryoff.find(h) ? false : h;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// The stateful Pages class
|
|
788
|
+
// this.d = Array of pages - [0] = URL // [1] = reference to whole page
|
|
789
|
+
class Pages {
|
|
790
|
+
f(){ this.d = [] } //flush
|
|
791
|
+
l(u){ if (this.P(u)) return this.d[this.i][1] } //lookup URL and return page
|
|
792
|
+
p(o){ if(this.P(o[0])) this.d[this.i]=o; else this.d.push(o) } //update or push page passed as an object
|
|
793
|
+
P(u){ return (this.i = this.d.findIndex(e => e[0] == u)) + 1 } //lookup page index and store in "i"
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
// The HAPi class
|
|
797
|
+
// operates on $.currentURL - manages operations on the History API centrally(replaceState / pushState)
|
|
798
|
+
class HApi {
|
|
799
|
+
r(h) { let c = this.u(h); history.replaceState({ url: c }, "state-" + c, c); } //perform replaceState
|
|
800
|
+
p(h) { let c = this.u(h); if (c !== window.location.href) history.pushState({ url: c }, "state-" + c, c); } //perform pushState
|
|
801
|
+
u(h) { if(h) $.currentURL = h; return $.currentURL; } //update currentURL if given and return always
|
|
802
|
+
}
|
package/ajaxify.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class Ajaxify{constructor(options){String.prototype.iO=function(t){return this.toString().indexOf(t)+1};let $=this;$.s={elements:"body",selector:"a:not(.no-ajaxy)",forms:"form:not(.no-ajaxy)",canonical:!1,refresh:!1,requestDelay:0,scrolltop:"s",bodyClasses:!1,deltas:!0,asyncdef:!0,alwayshints:!1,inline:!0,inlinesync:!0,inlinehints:!1,inlineskip:"adsbygoogle",inlineappend:!0,intevents:!0,style:!0,prefetchoff:!1,verbosity:0,memoryoff:!1,cb:0,pluginon:!0,passCount:!1},$.pass=0,$.currentURL="",$.parse=((t,e)=>(e=document.createElement("div"),e.insertAdjacentHTML("afterbegin",t),e.firstElementChild)),$.trigger=((t,e)=>{let r=document.createEvent("HTMLEvents");r.initEvent("pronto."+t,!0,!1),r.data=e||$.Rq("e"),window.dispatchEvent(r),document.dispatchEvent(r)}),$.internal=(t=>!!t&&("object"==typeof t&&(t=t.href),""===t||(t.substring(0,rootUrl.length)===rootUrl||!t.iO(":")))),$.intevents=(()=>{EventTarget.prototype.ael=EventTarget.prototype.addEventListener,EventTarget.prototype.addEventListener=function(t,e,r=!1){this!==document&&this!==window||"DOMContentLoaded"!=t&&"load"!=t?this.ael(t,e,r):setTimeout(e)}});let rootUrl=location.origin,api=window.history&&window.history.pushState&&window.history.replaceState,docType=/<\!DOCTYPE[^>]*>/i,tagso=/<(html|head|link)([\s\>])/gi,tagsod=/<(body)([\s\>])/gi,tagsc=/<\/(html|head|body|link)\>/gi,div12='<div class="ajy-$1"$2',divid12='<div id="ajy-$1"$2',linki='<link rel="stylesheet" type="text/css" href="*" />',linkr='link[href*="!"]',scrr='script[src*="!"]',inlineclass="ajy-inline",doc=document,bdy,qa=(t,e=doc)=>e.querySelectorAll(t),qs=(t,e=doc)=>e.querySelector(t);function _copyAttributes(t,e,r){r&&[...t.attributes].forEach(e=>t.removeAttribute(e.name)),[...e.attributes].forEach(e=>t.setAttribute(e.nodeName,e.nodeValue))}function _on(t,e,r,n=document){n.addEventListener(t,function(t){for(var n=t.target;n&&n!=this;n=n.parentNode)if(n.matches(e)){r(n,t);break}},!!t.iO("mo"))}function Hints(t){if(!(this instanceof Hints))return new Hints(t);this.myHints="string"==typeof t&&t.length>0&&t.split(", ")}function lg(t){$.s.verbosity&&console&&console.log(t)}Hints.prototype.find=function(t){return!(!t||!this.myHints)&&this.myHints.some(e=>t.iO(e))};class Cache{constructor(){let t=!1;this.a=function(e){return e?"string"==typeof e?("f"===e?($.pages("f"),lg("Cache flushed")):t=$.pages($.memory(e)),t):"object"==typeof e?t=e:void 0:t}}}class Memory{constructor(t){this.a=function(t){return!(!t||!0===$.s.memoryoff)&&(!1===$.s.memoryoff?t:!Hints($.s.memoryoff).find(t)&&t)}}}class Pages{constructor(){let t=[],e=-1;this.a=function(n){if("string"==typeof n)if("f"===n)t=[];else if(-1!==(e=r(n)))return t[e][1];if("object"==typeof n&&(-1===(e=r(n))?t.push(n):t[e]=n),"boolean"==typeof n)return!1};let r=e=>t.findIndex(t=>t[0]==e)}}class GetPage{constructor(){let t=0,e=0,r=0,n="",s=0,i=0,o=0;this.a=function(s,l,d){if(!s)return $.cache();if(s.iO("/")){if(e=l,r==s)return;return c(s)}if("+"===s)return r=l,e=d,c(l,!0);if("a"!==s){if("s"===s)return(i?1:0)+n;if("-"===s)return a(l);if("x"===s)return t;if($.cache())return"body"===s?qs("#ajy-"+s,$.cache()):"script"===s?qa(s,$.cache()):qs("title"===s?s:".ajy-"+s,$.cache())}else i>0&&(p(),o.abort())};let a=t=>($.pass++,d(t),qa("body > script").forEach(t=>!!t.classList.contains(inlineclass)&&t.parentNode.removeChild(t)),$.scripts(!0),$.scripts("s"),$.scripts("c")),c=(t,n)=>(t.iO("#")&&(t=t.split("#")[0]),$.Rq("is")||!$.cache(t)?u(t,n):(r=0,e?e():void 0)),l=(t,e)=>{if(e){var r=e.cloneNode(!0);qa("script",r).forEach(t=>t.parentNode.removeChild(t)),_copyAttributes(t,r,!0),t.innerHTML=r.innerHTML}else{lg("Inserting placeholder for ID: "+t.getAttribute("id"));var n=t.tagName.toLowerCase();t.parentNode.replaceChild($.parse("<"+n+" id='"+t.getAttribute("id")+"'></"+n+">"),t)}},d=t=>$.cache()&&!f(t)&&t.forEach(function(t){l(t,qs("#"+t.getAttribute("id"),$.cache()))}),f=t=>"body"==t[0].tagName.toLowerCase()&&(l(bdy,qs("#ajy-body",$.cache())),1),u=(e,r)=>{var s=$.Rq("is");n=r?"p":"c",o=new AbortController,i++,fetch(e,{method:s?"POST":"GET",cache:"default",mode:"same-origin",headers:{"X-Requested-With":"XMLHttpRequest"},body:s?$.Rq("d"):null,signal:o.signal}).then(n=>{if(n.ok&&y(n))return t=n,n.text();r||(location.href=e,p(),$.pronto(0,$.currentURL))}).then(r=>{if(p(1),r)return t.responseText=r,h(e,r)}).catch(t=>{if("AbortError"!==t.name)try{return $.trigger("error",t),lg("Response text : "+t.message),h(e,t.message,t)}catch(t){}}).finally(()=>i--)},p=t=>(r=0,t?0:e=0),h=(t,r,n)=>$.cache($.parse(g(r)))&&($.pages([t,$.cache()]),1)&&e&&e(n),y=t=>(s=t.headers.get("content-type"))&&(s.iO("html")||s.iO("form-")),g=t=>document.createElement("html").innerHTML=m(t).trim(),m=t=>String(t).replace(docType,"").replace(tagso,div12).replace(tagsod,divid12).replace(tagsc,"</div>")}}class Scripts{constructor(){let $s=!1,txt=0;this.a=function(t){return"i"===t?($s||($s={}),!0):"s"===t?_allstyle($s.y):"1"===t?($.detScripts($s),_addScripts($s)):"c"===t?!(!$.s.canonical||!$s.can)&&$s.can.getAttribute("href"):"d"===t?$.detScripts($s):t&&"object"==typeof t?_onetxt(t):void($.scripts("d")||_addScripts($s))};let _allstyle=t=>!$.s.style||!t||(qa("style",qs("head")).forEach(t=>t.parentNode.removeChild(t)),t.forEach(t=>_addstyle(t.textContent))),_onetxt=t=>!(txt=t.textContent).iO(").ajaxify(")&&!txt.iO("new Ajaxify(")&&($.s.inline&&!Hints($.s.inlineskip).find(txt)||t.classList.contains("ajaxy")||Hints($.s.inlinehints).find(txt))&&_addtxt(t),_addtxt=$s=>{if(txt&&txt.length){if($.s.inlineappend||$s.getAttribute("type")&&!$s.getAttribute("type").iO("text/javascript"))try{return _apptxt($s)}catch(t){}try{eval(txt)}catch(t){lg("Error in inline script : "+txt+"\nError code : "+t)}}},_apptxt=t=>{let e=document.createElement("script");_copyAttributes(e,t),e.classList.add(inlineclass);try{e.appendChild(document.createTextNode(t.textContent))}catch(r){e.text=t.textContent}return qs("body").appendChild(e)},_addstyle=t=>qs("head").appendChild($.parse("<style>"+t+"</style>")),_addScripts=t=>($.addAll(t.c,"href"),$.s.inlinesync?setTimeout(()=>$.addAll(t.j,"src")):$.addAll(t.j,"src"))}}class DetScripts{constructor(){let t=0,e=0,r=0;this.a=function(s){if(!(t=$.pass?$.fn("head"):qs("head")))return!0;e=qa($.pass?".ajy-link":"link",t),r=$.pass?$.fn("script"):qa("script"),s.c=n(e,"stylesheet"),s.y=qa("style",t),s.can=n(e,"canonical"),s.j=r};let n=(t,e)=>Array.prototype.filter.call(t,t=>t.getAttribute("rel").iO(e))}}class AddAll{constructor(){let t=[],e=[],r=[],n=0,s=0;this.a=function(d,f){if(d.length){if("n"===$.s.deltas)return!0;if(n=f,!$.s.deltas)return i(d);t="href"==n?e:r,$.pass?d.forEach(function(e){var r=e;if(s=r.getAttribute(n),a(r))return l(),void c(r);s?t.some(t=>t==s)||(t.push(s),c(r)):"href"==n||r.classList.contains("no-ajaxy")||$.scripts(r)}):o(d)}};let i=t=>t.forEach(t=>c(t)),o=e=>e.forEach(e=>(s=e.getAttribute(n))?t.push(s):0),a=t=>"always"==t.getAttribute("data-class")||Hints($.s.alwayshints).find(s),c=t=>{if(s=t.getAttribute(n),"href"==n)return qs("head").appendChild($.parse(linki.replace("*",s)));if(!s)return $.scripts(t);var e=document.createElement("script");e.async=$.s.asyncdef,_copyAttributes(e,t),qs("head").appendChild(e)},l=()=>qa(("href"==n?linkr:scrr).replace("!",s)).forEach(t=>t.parentNode.removeChild(t))}}class RQ{constructor(){let t=0,e=0,r=0,n=0,s=0,i=0,o=!1;this.a=function(c,l,d){if("="===c)return l?i===$.currentURL||i===o:i===$.currentURL;if("!"===c)return o=i;if("?"===c){let t=$.fn("s");return t.iO("0")||l||$.fn("a"),"1c"===t&&l?!1:("1p"===t&&l&&(!$.s.memoryoff||$.fn("a")),!0)}if("v"===c){if(!l)return!1;if(a(l,d),!$.internal(i))return!1;c="i"}return"i"===c?(t=!1,e=null,r=!0,n=!1,i):"h"===c?(l&&("string"==typeof l&&(s=0),i=l.href?l.href:l),i):"e"===c?(l&&a(l,d),s||i):"p"===c?(void 0!==l&&(r=l),r):"is"===c?(void 0!==l&&(t=l),t):"d"===c?(l&&(e=l),e):"C"===c?(void 0!==l&&(n=l),n):"c"===c?!n||n===l||l.iO("#")||l.iO("?")?l:n:void 0};let a=(t,e)=>i="string"!=typeof(s=t)?s.currentTarget&&s.currentTarget.href||e&&e.href||s.currentTarget.action||s.originalEvent.state.url:s}}class Frms{constructor(){let t=0,e=0;this.a=function(s,i){$.s.forms&&s&&("d"===s&&(e=i),"a"===s&&e.forEach(e=>{Array.prototype.filter.call(qa($.s.forms,e),function(t){let e=t.getAttribute("action");return $.internal(e&&e.length>0?e:$.currentURL)}).forEach(e=>{e.addEventListener("submit",e=>{t=e.target,i=r();var s="get",o=t.getAttribute("method");o.length>0&&"post"==o.toLowerCase()&&(s="post");var a,c=t.getAttribute("action");return a=c&&c.length>0?c:$.currentURL,$.Rq("v",e),"get"==s?a=n(a,i):($.Rq("is",!0),$.Rq("d",i)),$.trigger("submit",a),$.pronto(0,{href:a}),e.preventDefault(),!1})})}))};let r=()=>{let e=new FormData(t),r=qs("input[name][type=submit]",t);return r&&e.append(r.getAttribute("name"),r.value),e},n=(t,e)=>{let r="";for(var[n,s]of(t.iO("?")&&(t=t.substring(0,t.iO("?"))),e.entries()))r+=`${n}=${encodeURIComponent(s)}&`;return`${t}?${r.slice(0,-1)}`}}}class Offsets{constructor(){let t=[],e=-1;this.a=function(n){if("string"==typeof n)return n=n.iO("?")?n.split("?")[0]:n,-1===(e=r(n))?0:t[e][1];var s=$.currentURL,i=s.iO("?")?s.split("?")[0]:s,o=i.iO("#")?i.split("#")[0]:i,a=[o,document.documentElement&&document.documentElement.scrollTop||document.body.scrollTop];-1===(e=r(o))?t.push(a):t[e]=a};let r=e=>t.findIndex(t=>t[0]==e)}}class Scrolly{constructor(){this.a=function(e){if(e){var r=e;if("+"!==e&&"!"!==e||(e=$.currentURL),"+"!==r&&e.iO("#")&&e.iO("#")<e.length-1){let r=qs("#"+e.split("#")[1]);if(!r)return;let n=r.getBoundingClientRect();t(n.top+window.pageYOffset-document.documentElement.clientTop)}else{if("s"===$.s.scrolltop)return"+"===r&&$.offsets(),void("!"===r&&t($.offsets(e)));"+"!==r&&$.s.scrolltop&&t(0)}}};let t=t=>window.scrollTo(0,t)}}class HApi{constructor(){this.a=function(t,e){t&&(e&&($.currentURL=e),"="===t?history.replaceState({url:$.currentURL},"state-"+$.currentURL,$.currentURL):$.currentURL!==window.location.href&&history.pushState({url:$.currentURL},"state-"+$.currentURL,$.currentURL))}}}class Pronto{constructor(){let t=0,e=0,r=0;this.a=function(e,r){if(r)return"i"===r?(bdy=document.body,e.length||(e="body"),t=qa(e),$.frms=(new Frms).a,$.s.idleTime&&($.slides=new classSlides($).a),$.scrolly=(new Scrolly).a,$.offsets=(new Offsets).a,$.hApi=(new HApi).a,n(),e):"object"==typeof r?($.Rq("h",r),void c()):void(r.iO("/")&&($.Rq("h",r),c(!0)))};let n=()=>{$.hApi("=",window.location.href),window.addEventListener("popstate",d),!0!==$.s.prefetchoff&&(_on("mouseenter",$.s.selector,s),_on("mouseleave",$.s.selector,i),_on("touchstart",$.s.selector,o)),_on("click",$.s.selector,a,bdy),$.frms("d",qa("body")),$.frms("a"),$.frms("d",t),$.s.idleTime&&$.slides("i")},s=(t,e)=>r=setTimeout(()=>o(t,e),150),i=()=>clearTimeout(r),o=(t,e)=>{if(!0!==$.s.prefetchoff&&$.Rq("?",!0)){var r=$.Rq("v",e,t);$.Rq("=",!0)||!r||Hints($.s.prefetchoff).find(r)||$.fn("+",r,()=>!1)}},a=(t,e,r)=>{if($.Rq("?")){var n=$.Rq("v",e,t);if(n&&!p(t)){if("#"===n.substr(-1))return!0;if(h())return $.hApi("=",n),!0;$.scrolly("+"),(t=>(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation()))(e),$.Rq("=")&&$.hApi("="),!$.s.refresh&&$.Rq("=")||c(r)}}},c=t=>{$.Rq("!"),t&&$.Rq("p",!1),$.trigger("request"),$.fn($.Rq("h"),t=>{t&&(lg("Error in _request : "+t),$.trigger("error",t)),l()})},l=()=>{$.trigger("beforeload"),$.s.requestDelay?(e&&clearTimeout(e),e=setTimeout(f,$.s.requestDelay)):f()},d=t=>{var e=window.location.href;$.Rq("i"),$.Rq("h",e),$.Rq("p",!1),$.scrolly("+"),e&&e!==$.currentURL&&($.trigger("request"),$.fn(e,l))},f=()=>{if($.trigger("load"),$.s.bodyClasses){var e=$.fn("body").getAttribute("class");bdy.setAttribute("class",e||"")}var r,n=$.Rq("h");n=$.Rq("c",n),$.hApi($.Rq("p")?"+":"=",n),(r=$.fn("title"))&&(qs("title").innerHTML=r.innerHTML),$.Rq("C",$.fn("-",t)),$.frms("a"),$.scrolly("!"),u(n),$.trigger("render"),$.s.passCount&&(qs("#"+$.s.passCount).innerHTML="Pass: "+$.pass),$.s.cb&&$.s.cb()},u=t=>{t="/"+t.replace(rootUrl,""),void 0!==window.ga?window.ga("send","pageview",t):void 0!==window._gaq&&window._gaq.push(["_trackPageview",t])},p=t=>{var e=$.Rq("h"),r=$.Rq("e"),n=r.currentTarget.target||t.target;return r.which>1||r.metaKey||r.ctrlKey||r.shiftKey||r.altKey||"_blank"===n||e.iO("wp-login")||e.iO("wp-admin")},h=()=>{var t=$.Rq("e");return t.hash&&t.href.replace(t.hash,"")===window.location.href.replace(location.hash,"")||t.href===window.location.href+"#"}}}$.init=(()=>{let t=options;return t&&"string"==typeof t?$.pronto(0,t):("complete"===document.readyState||"loading"!==document.readyState&&!document.documentElement.doScroll?run():document.addEventListener("DOMContentLoaded",run),$)});let run=()=>{$.s=Object.assign($.s,options),$.pages=(new Pages).a,$.pronto=(new Pronto).a,load()&&($.pronto($.s.elements,"i"),$.s.deltas&&$.scripts("1"))},load=()=>api&&$.s.pluginon?(lg("Ajaxify loaded..."),$.s.intevents&&$.intevents(),$.scripts=(new Scripts).a,$.scripts("i"),$.cache=(new Cache).a,$.memory=(new Memory).a,$.fn=$.getPage=(new GetPage).a,$.detScripts=(new DetScripts).a,$.addAll=(new AddAll).a,$.Rq=(new RQ).a,!0):(lg("Gracefully exiting..."),!1);$.init()}}
|
|
1
|
+
let $,rootUrl=location.origin,inlineclass="ajy-inline",bdy,qa=(t,e=document)=>e.querySelectorAll(t),qs=(t,e=document)=>e.querySelector(t);class Ajaxify{constructor(options){function _copyAttributes(t,e,r){r&&[...t.attributes].forEach(e=>t.removeAttribute(e.name)),[...e.attributes].forEach(e=>t.setAttribute(e.nodeName,e.nodeValue))}function _on(t,e,r,s=document){s.addEventListener(t,function(t){for(var s=t.target;s&&s!=this;s=s.parentNode)if(s.matches(e)){r(s,t);break}},!!t.iO("mo"))}String.prototype.iO=function(t){return this.toString().indexOf(t)+1},$=this,$.s={elements:"body",selector:"a:not(.no-ajaxy)",forms:"form:not(.no-ajaxy)",canonical:!1,refresh:!1,requestDelay:0,scrolltop:"s",bodyClasses:!1,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},$.pass=0,$.currentURL="",$.h={},$.parse=((t,e)=>(e=document.createElement("div"),e.insertAdjacentHTML("afterbegin",t),e.firstElementChild)),$.trigger=((t,e)=>{let r=document.createEvent("HTMLEvents");r.initEvent("pronto."+t,!0,!1),r.data=e||$.Rq("e"),window.dispatchEvent(r),document.dispatchEvent(r)}),$.internal=(t=>!!t&&("object"==typeof t&&(t=t.href),""===t||(t.substring(0,rootUrl.length)===rootUrl||!t.iO(":")))),$.intevents=(()=>{EventTarget.prototype.ael=EventTarget.prototype.addEventListener,EventTarget.prototype.addEventListener=function(t,e,r=!1){this!==document&&this!==window||"DOMContentLoaded"!=t?this.ael(t,e,r):setTimeout(e)}});class Hints{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 lg(t){$.s.verbosity&&console&&console.log(t)}class GetPage{constructor(){let t=0,e=0,r=0,s="",n=0,i=0,o=0,a=/<\!DOCTYPE[^>]*>/i,l=/<(html|head|link)([\s\>])/gi,c=/<(body)([\s\>])/gi,d=/<\/(html|head|body|link)\>/gi;this.a=function(n,a,l){if(!n)return $.cache.g();if(n.iO("/")){if(e=a,r==n)return;return u(n)}if("+"===n)return r=a,e=l,u(a,!0);if("a"!==n){if("s"===n)return(i?1:0)+s;if("-"===n)return f(a);if("x"===n)return t;if($.cache.g())return"body"===n?qs("#ajy-"+n,$.cache.g()):"script"===n?qa(n,$.cache.g()):qs("title"===n?n:".ajy-"+n,$.cache.g())}else i>0&&(m(),o.abort())};let f=t=>($.pass++,p(t),qa("body > script").forEach(t=>!!t.classList.contains(inlineclass)&&t.parentNode.removeChild(t)),$.scripts(!0),$.scripts("s"),$.scripts("c")),u=(t,s)=>(t.iO("#")&&(t=t.split("#")[0]),$.Rq("is")||!$.cache.l(t)?g(t,s):(r=0,e?e():void 0)),h=(t,e)=>{if(e){var r=e.cloneNode(!0);qa("script",r).forEach(t=>t.parentNode.removeChild(t)),_copyAttributes(t,r,!0),t.innerHTML=r.innerHTML}},p=t=>$.cache.g()&&!y(t)&&t.forEach(function(t){h(t,qs("#"+t.getAttribute("id"),$.cache.g()))}),y=t=>"body"==t[0].tagName.toLowerCase()&&(h(bdy,qs("#ajy-body",$.cache.g())),1),g=(e,r)=>{var n=$.Rq("is");s=r?"p":"c",o=new AbortController,i++,fetch(e,{method:n?"POST":"GET",cache:"default",mode:"same-origin",headers:{"X-Requested-With":"XMLHttpRequest"},body:n?$.Rq("d"):null,signal:o.signal}).then(s=>{if(s.ok&&q(s))return t=s,s.text();r||(location.href=e,m(),$.pronto(0,$.currentURL))}).then(r=>{if(m(1),r)return t.responseText=r,v(e,r)}).catch(t=>{if("AbortError"!==t.name)try{return $.trigger("error",t),lg("Response text : "+t.message),v(e,t.message,t)}catch(t){}}).finally(()=>i--)},m=t=>(r=0,t?0:e=0),v=(t,r,s)=>$.cache.s($.parse(w(r)))&&($.pages.p([t,$.cache.g()]),1)&&e&&e(s),q=t=>(n=t.headers.get("content-type"))&&(n.iO("html")||n.iO("form-")),w=t=>document.createElement("html").innerHTML=b(t).trim(),b=t=>String(t).replace(a,"").replace(l,'<div class="ajy-$1"$2').replace(c,'<div id="ajy-$1"$2').replace(d,"</div>")}}class Scripts{constructor(){let $s=!1,txt=0;$.h.inlinehints=new Hints($.s.inlinehints),$.h.inlineskip=new Hints($.s.inlineskip),this.a=function(t){return"i"===t?($s||($s={}),!0):"s"===t?_allstyle($s.y):"1"===t?($.detScripts($s),_addScripts($s)):"c"===t?!(!$.s.canonical||!$s.can)&&$s.can.getAttribute("href"):"d"===t?$.detScripts($s):t&&"object"==typeof t?_onetxt(t):void($.scripts("d")||_addScripts($s))};let _allstyle=t=>!$.s.style||!t||(qa("style",qs("head")).forEach(t=>t.parentNode.removeChild(t)),t.forEach(t=>_addstyle(t.textContent))),_onetxt=t=>!(txt=t.textContent).iO(").ajaxify(")&&!txt.iO("new Ajaxify(")&&($.s.inline&&!$.h.inlineskip.find(txt)||t.classList.contains("ajaxy")||$.h.inlinehints.find(txt))&&_addtxt(t),_addtxt=$s=>{if(txt&&txt.length){if($.s.inlineappend||$s.getAttribute("type")&&!$s.getAttribute("type").iO("text/javascript"))try{return _apptxt($s)}catch(t){}try{eval(txt)}catch(t){lg("Error in inline script : "+txt+"\nError code : "+t)}}},_apptxt=t=>{let e=document.createElement("script");_copyAttributes(e,t),e.classList.add(inlineclass);try{e.appendChild(document.createTextNode(t.textContent))}catch(r){e.text=t.textContent}return qs("body").appendChild(e)},_addstyle=t=>qs("head").appendChild($.parse("<style>"+t+"</style>")),_addScripts=t=>($.addAll(t.c,"href"),$.addAll(t.j,"src"))}}class DetScripts{constructor(){let t=0,e=0,r=0;this.a=function(n){if(!(t=$.pass?$.fn("head"):qs("head")))return!0;e=qa($.pass?".ajy-link":"link",t),r=$.pass?$.fn("script"):qa("script"),n.c=s(e,"stylesheet"),n.y=qa("style",t),n.can=s(e,"canonical"),n.j=r};let s=(t,e)=>Array.prototype.filter.call(t,t=>t.getAttribute("rel").iO(e))}}class AddAll{constructor(){let t=[],e=[],r=[],s=0,n=0;$.h.alwayshints=new Hints($.s.alwayshints),this.a=function(d,f){if(d.length){if("n"===$.s.deltas)return!0;if(s=f,!$.s.deltas)return i(d);t="href"==s?e:r,$.pass?d.forEach(function(e){var r=e;if(n=r.getAttribute(s),a(r))return c(),void l(r);n?t.some(t=>t==n)||(t.push(n),l(r)):"href"==s||r.classList.contains("no-ajaxy")||$.scripts(r)}):o(d)}};let i=t=>t.forEach(t=>l(t)),o=e=>e.forEach(e=>(n=e.getAttribute(s))?t.push(n):0),a=t=>"always"==t.getAttribute("data-class")||$.h.alwayshints.find(n),l=t=>{if(n=t.getAttribute(s),"href"==s)return qs("head").appendChild($.parse('<link rel="stylesheet" type="text/css" href="*" />'.replace("*",n)));if(!n)return $.scripts(t);var e=document.createElement("script");e.async=$.s.asyncdef,_copyAttributes(e,t),qs("head").appendChild(e)},c=()=>qa(("href"==s?'link[href*="!"]':'script[src*="!"]').replace("!",n)).forEach(t=>t.parentNode.removeChild(t))}}class RQ{constructor(){let t=0,e=0,r=0,s=0,n=0,i=0,o=!1;this.a=function(l,c,d){if("="===l)return c?i===$.currentURL||i===o:i===$.currentURL;if("!"===l)return o=i;if("?"===l){let t=$.fn("s");return t.iO("0")||c||$.fn("a"),"1c"===t&&c?!1:("1p"===t&&c&&(!$.s.memoryoff||$.fn("a")),!0)}if("v"===l){if(!c)return!1;if(a(c,d),!$.internal(i))return!1;l="i"}return"i"===l?(t=!1,e=null,r=!0,s=!1,i):"h"===l?(c&&("string"==typeof c&&(n=0),i=c.href?c.href:c),i):"e"===l?(c&&a(c,d),n||i):"p"===l?(void 0!==c&&(r=c),r):"is"===l?(void 0!==c&&(t=c),t):"d"===l?(c&&(e=c),e):"C"===l?(void 0!==c&&(s=c),s):"c"===l?!s||s===c||c.iO("#")||c.iO("?")?c:s:void 0};let a=(t,e)=>i="string"!=typeof(n=t)?n.currentTarget&&n.currentTarget.href||e&&e.href||n.currentTarget.action||n.originalEvent.state.url:n}}class Frms{constructor(){let t=0,e=0;this.a=function(n,i){$.s.forms&&n&&("d"===n&&(e=i),"a"===n&&e.forEach(e=>{Array.prototype.filter.call(qa($.s.forms,e),function(t){let e=t.getAttribute("action");return $.internal(e&&e.length>0?e:$.currentURL)}).forEach(e=>{e.addEventListener("submit",e=>{t=e.target,i=r();var n="get",o=t.getAttribute("method");o.length>0&&"post"==o.toLowerCase()&&(n="post");var a,l=t.getAttribute("action");return a=l&&l.length>0?l:$.currentURL,$.Rq("v",e),"get"==n?a=s(a,i):($.Rq("is",!0),$.Rq("d",i)),$.trigger("submit",a),$.pronto(0,{href:a}),e.preventDefault(),!1})})}))};let r=()=>{let e=new FormData(t),r=qs("input[name][type=submit]",t);return r&&e.append(r.getAttribute("name"),r.value),e},s=(t,e)=>{let r="";for(var[s,n]of(t.iO("?")&&(t=t.substring(0,t.iO("?"))),e.entries()))r+=`${s}=${encodeURIComponent(n)}&`;return`${t}?${r.slice(0,-1)}`}}}class Offsets{constructor(){let t=[],e=-1;this.a=function(s){if("string"==typeof s)return s=s.iO("?")?s.split("?")[0]:s,-1===(e=r(s))?0:t[e][1];var n=$.currentURL,i=n.iO("?")?n.split("?")[0]:n,o=i.iO("#")?i.split("#")[0]:i,a=[o,document.documentElement&&document.documentElement.scrollTop||document.body.scrollTop];-1===(e=r(o))?t.push(a):t[e]=a};let r=e=>t.findIndex(t=>t[0]==e)}}class Scrolly{constructor(){"scrollRestoration"in history&&(history.scrollRestoration="manual"),this.a=function(e){if(e){var r=e;if("+"!==e&&"!"!==e||(e=$.currentURL),"+"!==r&&e.iO("#")&&e.iO("#")<e.length-1){let r=qs("#"+e.split("#")[1]);if(!r)return;let s=r.getBoundingClientRect();t(s.top+window.pageYOffset-document.documentElement.clientTop)}else{if("s"===$.s.scrolltop)return"+"===r&&$.offsets(),void("!"===r&&t($.offsets(e)));"+"!==r&&$.s.scrolltop&&t(0)}}};let t=t=>setTimeout(()=>window.scrollTo(0,t),10)}}class Pronto{constructor(){let t=0,e=0,r=0;$.h.prefetchoff=new Hints($.s.prefetchoff),this.a=function(e,r){if(r)return"i"===r?(bdy=document.body,e.length||(e="body"),t=qa(e),$.frms=(new Frms).a,$.s.idleTime&&($.slides=new classSlides($).a),$.scrolly=(new Scrolly).a,$.offsets=(new Offsets).a,$.hApi=new HApi,s(),e):"object"==typeof r?($.Rq("h",r),void l()):void(r.iO("/")&&($.Rq("h",r),l(!0)))};let s=()=>{$.hApi.r(window.location.href),window.addEventListener("popstate",d),!0!==$.s.prefetchoff&&(_on("mouseenter",$.s.selector,n),_on("mouseleave",$.s.selector,i),_on("touchstart",$.s.selector,o)),_on("click",$.s.selector,a,bdy),$.frms("d",qa("body")),$.frms("a"),$.frms("d",t),$.s.idleTime&&$.slides("i")},n=(t,e)=>(i(),r=setTimeout(()=>o(t,e),150)),i=()=>clearTimeout(r),o=(t,e)=>{if(!0!==$.s.prefetchoff&&$.Rq("?",!0)){var r=$.Rq("v",e,t);$.Rq("=",!0)||!r||$.h.prefetchoff.find(r)||$.fn("+",r,()=>!1)}},a=(t,e,r)=>{if($.Rq("?")){var s=$.Rq("v",e,t);if(s&&!h(t)){if("#"===s.substr(-1))return!0;if(p())return $.hApi.r(s),!0;$.scrolly("+"),(t=>(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation()))(e),$.Rq("=")&&$.hApi.r(),!$.s.refresh&&$.Rq("=")||l(r)}}},l=t=>{$.Rq("!"),t&&$.Rq("p",!1),$.trigger("request"),$.fn($.Rq("h"),t=>{t&&(lg("Error in _request : "+t),$.trigger("error",t)),c()})},c=()=>{$.trigger("beforeload"),$.s.requestDelay?(e&&clearTimeout(e),e=setTimeout(f,$.s.requestDelay)):f()},d=t=>{var e=window.location.href;$.Rq("i"),$.Rq("h",e),$.Rq("p",!1),$.scrolly("+"),e&&e!==$.currentURL&&($.trigger("request"),$.fn(e,c))},f=()=>{if($.trigger("load"),$.s.bodyClasses){var e=$.fn("body").getAttribute("class");bdy.setAttribute("class",e||"")}var r,s=$.Rq("h");s=$.Rq("c",s),$.Rq("p")?$.hApi.p(s):$.hApi.r(s),(r=$.fn("title"))&&(qs("title").innerHTML=r.innerHTML),$.Rq("C",$.fn("-",t)),$.frms("a"),$.scrolly("!"),u(s),$.trigger("render"),$.s.passCount&&(qs("#"+$.s.passCount).innerHTML="Pass: "+$.pass),$.s.cb&&$.s.cb()},u=t=>{t="/"+t.replace(rootUrl,""),void 0!==window.ga?window.ga("send","pageview",t):void 0!==window._gaq&&window._gaq.push(["_trackPageview",t])},h=t=>{var e=$.Rq("h"),r=$.Rq("e"),s=r.currentTarget.target||t.target;return r.which>1||r.metaKey||r.ctrlKey||r.shiftKey||r.altKey||"_blank"===s||e.iO("wp-login")||e.iO("wp-admin")},p=()=>{var t=$.Rq("e");return t.hash&&t.href.replace(t.hash,"")===window.location.href.replace(location.hash,"")||t.href===window.location.href+"#"}}}$.init=(()=>{let t=options;return t&&"string"==typeof t?$.pronto(0,t):("complete"===document.readyState||"loading"!==document.readyState&&!document.documentElement.doScroll?run():document.addEventListener("DOMContentLoaded",run),$)});let run=()=>{$.s=Object.assign($.s,options),($.pages=new Pages).f(),$.pronto=(new Pronto).a,load()&&($.pronto($.s.elements,"i"),$.s.deltas&&$.scripts("1"))},load=()=>window.history&&window.history.pushState&&window.history.replaceState&&$.s.pluginon?(lg("Ajaxify loaded..."),$.s.intevents&&$.intevents(),$.scripts=(new Scripts).a,$.scripts("i"),$.cache=new Cache,$.memory=new Memory,$.h.memoryoff=new Hints($.s.memoryoff),$.fn=$.getPage=(new GetPage).a,$.detScripts=(new DetScripts).a,$.addAll=(new AddAll).a,$.Rq=(new RQ).a,!0):(lg("Gracefully exiting..."),!1);$.init()}}class Cache{g(){return this.d}s(t){return this.d=t}l(t){let e=$.memory.l(t);return this.s(!1===e?e:$.pages.l(e))}}class Memory{l(t){return!(!t||!0===$.s.memoryoff)&&(!1===$.s.memoryoff?t:!$.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 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&&($.currentURL=t),$.currentURL}}
|