ajaxify 8.1.5 → 8.2.1

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.
Files changed (3) hide show
  1. package/ajaxify.js +254 -343
  2. package/ajaxify.min.js +1 -1
  3. 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 Ay; //to become the global handle for the main Ajaxify parent class - if used by you already, please rename and rebuild
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,10 +31,10 @@ 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
- let $ = this;
34
+ Ay = this;
26
35
 
27
36
  //Options default values
28
- $.s = {
37
+ Ay.s = {
29
38
  // basic config parameters
30
39
  elements: "body", //selector for element IDs that are going to be swapped (e.g. "#el1, #el2, #el3")
31
40
  selector : "a:not(.no-ajaxy)", //selector for links to trigger swapping - not elements to be swapped - i.e. a selection of links
@@ -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", "load")
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 = ""; $.h = {};
64
- $.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(":"); }
67
- $.intevents = () => {
68
- 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
71
+ Ay.pass = 0; Ay.currentURL = ""; Ay.h = {};
72
+ Ay.parse = (s, pl) => (pl = document.createElement('div'), pl.insertAdjacentHTML('afterbegin', s), pl.firstElementChild); // HTML parser
73
+ Ay.trigger = (t, e) => { let ev = document.createEvent('HTMLEvents'); ev.initEvent("pronto." + t, true, false); ev.data = e ? e : Ay.Rq("e"); window.dispatchEvent(ev); document.dispatchEvent(ev); };
74
+ Ay.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(":"); };
75
+ Ay.intevents = () => {
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
@@ -115,72 +100,7 @@ class Hints { constructor(h) { let _ = this;
115
100
  _.find = (t) => (!t || !_.list) ? false : _.list.some(h => t.iO(h)); //iterate through hints within passed text (t)
116
101
  }}
117
102
 
118
- function lg(m){ $.s.verbosity && console && console.log(m); }
119
-
120
- // The stateful Cache class
121
- // Usage - parameter "o" values:
122
- // none - returns currently cached page
123
- // <URL> - returns page with specified URL
124
- // <object> - saves the page in cache
125
- // f - flushes the cache
126
- class Cache { constructor() {
127
- let d = false;
128
-
129
- this.a = function (o) {
130
- if (!o) return d;
131
-
132
- if (typeof o === "string") { //URL or "f" passed
133
- if(o === "f") { //"f" passed -> flush
134
- $.pages("f"); //delegate flush to $.pages
135
- lg("Cache flushed");
136
- } else d = $.pages($.memory(o)); //URL passed -> look up page in memory
137
-
138
- return d; //return cached page
139
- }
140
-
141
- if (typeof o === "object") {
142
- d = o;
143
- return d;
144
- }
145
- };
146
- }}
147
-
148
- // The stateful Memory class
149
- // Usage: $.memory(<URL>) - returns the same URL if not turned off internally
150
- class Memory { constructor(options) {
151
- $.h.memoryoff = new Hints($.s.memoryoff);
152
-
153
- this.a = function (h) {
154
- if (!h || $.s.memoryoff === true) return false;
155
- if ($.s.memoryoff === false) return h;
156
- return $.h.memoryoff.find(h) ? false : h;
157
- };
158
- }}
159
-
160
- // The stateful Pages class
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[0])) === -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){ Ay.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 Ay.cache.g();
199
130
 
200
131
  if (o.iO("/")) {
201
132
  cb = p;
@@ -214,34 +145,29 @@ 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 (!Ay.cache.g()) return;
149
+ if (o === "body") return qs("#ajy-" + o, Ay.cache.g());
150
+ if (o === "script") return qa(o, Ay.cache.g());
220
151
 
221
- return qs((o === "title") ? o : ".ajy-" + o, $.cache());
152
+ return qs((o === "title") ? o : ".ajy-" + o, Ay.cache.g());
222
153
  };
223
154
  let _lSel = $t => (
224
- $.pass++,
155
+ Ay.pass++,
225
156
  _lEls($t),
226
157
  qa("body > script").forEach(e => (e.classList.contains(inlineclass)) ? e.parentNode.removeChild(e) : false),
227
- $.scripts(true),
228
- $.scripts("s"),
229
- $.scripts("c")
158
+ Ay.scripts(true),
159
+ Ay.scripts("s"),
160
+ Ay.scripts("c")
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 (Ay.Rq("is") || !Ay.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,12 +175,12 @@ 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
+ Ay.cache.g() && !_isBody($t) && $t.forEach(function($el) {
179
+ _ld($el, qs("#" + $el.getAttribute("id"), Ay.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", Ay.cache.g())), 1),
256
182
  _lAjax = (hin, pre) => {
257
- var ispost = $.Rq("is");
183
+ var ispost = Ay.Rq("is");
258
184
  if (pre) rt="p"; else rt="c";
259
185
 
260
186
  ac = new AbortController(); // set abort controller
@@ -264,11 +190,11 @@ let _lSel = $t => (
264
190
  cache: "default",
265
191
  mode: "same-origin",
266
192
  headers: {"X-Requested-With": "XMLHttpRequest"},
267
- body: (ispost) ? $.Rq("d") : null,
193
+ body: (ispost) ? Ay.Rq("d") : null,
268
194
  signal: ac.signal
269
195
  }).then(r => {
270
196
  if (!r.ok || !_isHtml(r)) {
271
- if (!pre) {location.href = hin; _cl(); $.pronto(0, $.currentURL);}
197
+ if (!pre) {location.href = hin; _cl(); Ay.pronto(0, Ay.currentURL);}
272
198
  return;
273
199
  }
274
200
  rsp = r; // store response
@@ -282,14 +208,14 @@ let _lSel = $t => (
282
208
  }).catch(err => {
283
209
  if(err.name === "AbortError") return;
284
210
  try {
285
- $.trigger("error", err);
211
+ Ay.trigger("error", err);
286
212
  lg("Response text : " + err.message);
287
213
  return _cache(hin, err.message, err);
288
214
  } catch (e) {}
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) => Ay.cache.s(Ay.parse(_parseHTML(h))) && (Ay.pages.p([href, Ay.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,10 +229,10 @@ let _lSel = $t => (
303
229
  // otherwise - delta loading
304
230
  class Scripts { constructor() {
305
231
  let $s = false, txt = 0;
306
- $.h.inlinehints = new Hints($.s.inlinehints);
307
- $.h.inlineskip = new Hints($.s.inlineskip);
232
+ Ay.h.inlinehints = new Hints(Ay.s.inlinehints);
233
+ Ay.h.inlineskip = new Hints(Ay.s.inlineskip);
308
234
 
309
- this.a = function (o) {
235
+ this.a = function (o) {
310
236
  if (o === "i") {
311
237
  if(!$s) $s = {};
312
238
  return true;
@@ -315,30 +241,30 @@ class Scripts { constructor() {
315
241
  if (o === "s") return _allstyle($s.y);
316
242
 
317
243
  if (o === "1") {
318
- $.detScripts($s);
244
+ Ay.detScripts.d($s);
319
245
  return _addScripts($s);
320
246
  }
321
247
 
322
- if (o === "c") return $.s.canonical && $s.can ? $s.can.getAttribute("href") : false;
323
- if (o === "d") return $.detScripts($s);
248
+ if (o === "c") return Ay.s.canonical && $s.can ? $s.can.getAttribute("href") : false;
249
+ if (o === "d") return Ay.detScripts.d($s);
324
250
  if (o && typeof o == "object") return _onetxt(o);
325
251
 
326
- if ($.scripts("d")) return;
252
+ if (Ay.scripts("d")) return;
327
253
  _addScripts($s);
328
254
  };
329
255
  let _allstyle = $s =>
330
- !$.s.style || !$s || (
256
+ !Ay.s.style || !$s || (
331
257
  qa("style", qs("head")).forEach(e => e.parentNode.removeChild(e)),
332
258
  $s.forEach(el => _addstyle(el.textContent))
333
259
  ),
334
260
  _onetxt = $s =>
335
261
  (!(txt = $s.textContent).iO(").ajaxify(") && (!txt.iO("new Ajaxify(")) &&
336
- (($.s.inline && !$.h.inlineskip.find(txt)) || $s.classList.contains("ajaxy") ||
337
- $.h.inlinehints.find(txt))
262
+ ((Ay.s.inline && !Ay.h.inlineskip.find(txt)) || $s.classList.contains("ajaxy") ||
263
+ Ay.h.inlinehints.find(txt))
338
264
  ) && _addtxt($s),
339
265
  _addtxt = $s => {
340
266
  if(!txt || !txt.length) return;
341
- if($.s.inlineappend || ($s.getAttribute("type") && !$s.getAttribute("type").iO("text/javascript"))) try { return _apptxt($s); } catch (e) { }
267
+ if(Ay.s.inlineappend || ($s.getAttribute("type") && !$s.getAttribute("type").iO("text/javascript"))) try { return _apptxt($s); } catch (e) { }
342
268
 
343
269
  try { eval(txt); } catch (e1) {
344
270
  lg("Error in inline script : " + txt + "\nError code : " + e1);
@@ -348,30 +274,8 @@ let _allstyle = $s =>
348
274
  try {sc.appendChild(document.createTextNode($s.textContent))} catch(e) {sc.text = $s.textContent};
349
275
  return qs("body").appendChild(sc);
350
276
  },
351
- _addstyle = t => qs("head").appendChild($.parse('<style>' + t + '</style>')),
352
- _addScripts = $s => ( $.addAll($s.c, "href"), $.s.inlinesync ? setTimeout(() => $.addAll($s.j, "src")) : $.addAll($s.j, "src"))
353
- }}
354
-
355
- // The DetScripts plugin - stands for "detach scripts"
356
- // Works on "$s" <object> that is passed in and fills it
357
- // Fetches all stylesheets in the head
358
- // Fetches the canonical URL
359
- // Fetches all external scripts on the page
360
- // Fetches all inline scripts on the page
361
- class DetScripts { constructor() {
362
- let head = 0, lk = 0, j = 0;
363
-
364
- this.a = function ($s) {
365
- head = $.pass ? $.fn("head") : qs("head"); //If "pass" is 0 -> fetch head from DOM, otherwise from target page
366
- if (!head) return true;
367
- lk = qa($.pass ? ".ajy-link" : "link", head); //If "pass" is 0 -> fetch links from DOM, otherwise from target page
368
- j = $.pass ? $.fn("script") : qa("script"); //If "pass" is 0 -> fetch JSs from DOM, otherwise from target page
369
- $s.c = _rel(lk, "stylesheet"); //Extract stylesheets
370
- $s.y = qa("style", head); //Extract style tags
371
- $s.can = _rel(lk, "canonical"); //Extract canonical tag
372
- $s.j = j; //Assign JSs to internal selection
373
- };
374
- let _rel = (lk, v) => Array.prototype.filter.call(lk, e => e.getAttribute("rel").iO(v));
277
+ _addstyle = t => qs("head").appendChild(Ay.parse('<style>' + t + '</style>')),
278
+ _addScripts = $s => (Ay.addAll($s.c, "href"), Ay.addAll($s.j, "src"))
375
279
  }}
376
280
 
377
281
  // The AddAll plugin
@@ -380,21 +284,25 @@ let _rel = (lk, v) => Array.prototype.filter.call(lk, e => e.getAttribute("rel")
380
284
  // href - operate on stylesheets in the new selection
381
285
  // src - operate on JS scripts
382
286
  class AddAll { constructor() {
383
- let $scriptsO = [], $sCssO = [], $sO = [], PK = 0, url = 0;
384
- $.h.alwayshints = new Hints($.s.alwayshints);
287
+ let $scriptsO = [], $sCssO = [], $sO = [], PK = 0, url = 0,
288
+ linki = '<link rel="stylesheet" type="text/css" href="*" />',
289
+ linkr = 'link[href*="!"]',
290
+ scrr = 'script[src*="!"]';
291
+
292
+ Ay.h.alwayshints = new Hints(Ay.s.alwayshints);
385
293
 
386
294
  this.a = function ($this, pk) {
387
295
  if(!$this.length) return; //ensure input
388
- if($.s.deltas === "n") return true; //Delta-loading completely disabled
296
+ if(Ay.s.deltas === "n") return true; //Delta-loading completely disabled
389
297
 
390
298
  PK = pk; //Copy "primary key" into internal variable
391
299
 
392
- if(!$.s.deltas) return _allScripts($this); //process all scripts
300
+ if(!Ay.s.deltas) return _allScripts($this); //process all scripts
393
301
  //deltas presumed to be "true" -> proceed with normal delta-loading
394
302
 
395
303
  $scriptsO = PK == "href" ? $sCssO : $sO; //Copy old. Stylesheets or JS
396
304
 
397
- if(!$.pass) _newArray($this); //Fill new array on initial load, nothing more
305
+ if(!Ay.pass) _newArray($this); //Fill new array on initial load, nothing more
398
306
  else $this.forEach(function(s) { //Iterate through selection
399
307
  var $t = s;
400
308
  url = $t.getAttribute(PK);
@@ -412,20 +320,20 @@ class AddAll { constructor() {
412
320
  return;
413
321
  }
414
322
 
415
- if(PK != "href" && !$t.classList.contains("no-ajaxy")) $.scripts($t); //Inline JS script? -> inject into DOM
323
+ if(PK != "href" && !$t.classList.contains("no-ajaxy")) Ay.scripts($t); //Inline JS script? -> inject into DOM
416
324
  });
417
325
  };
418
326
  let _allScripts = $t => $t.forEach(e => _iScript(e)),
419
327
  _newArray = $t => $t.forEach(e => (url = e.getAttribute(PK)) ? $scriptsO.push(url) : 0),
420
- _classAlways = $t => $t.getAttribute("data-class") == "always" || $.h.alwayshints.find(url),
328
+ _classAlways = $t => $t.getAttribute("data-class") == "always" || Ay.h.alwayshints.find(url),
421
329
  _iScript = $S => {
422
330
  url = $S.getAttribute(PK);
423
331
 
424
- if(PK == "href") return qs("head").appendChild($.parse(linki.replace("*", url)));
425
- if(!url) return $.scripts($S);
332
+ if(PK == "href") return qs("head").appendChild(Ay.parse(linki.replace("*", url)));
333
+ if(!url) return Ay.scripts($S);
426
334
 
427
335
  var sc = document.createElement("script");
428
- sc.async = $.s.asyncdef;
336
+ sc.async = Ay.s.asyncdef;
429
337
  _copyAttributes(sc, $S);
430
338
  qs("head").appendChild(sc);
431
339
  },
@@ -454,26 +362,26 @@ class RQ { constructor() {
454
362
 
455
363
  this.a = function (o, p, t) {
456
364
  if(o === "=") {
457
- if(p) return h === $.currentURL //check whether internally stored "href" ("h") variable is the same as the global currentURL
365
+ if(p) return h === Ay.currentURL //check whether internally stored "href" ("h") variable is the same as the global currentURL
458
366
  || h === l; //or href of last request ("l")
459
- return h === $.currentURL; //for click requests
367
+ return h === Ay.currentURL; //for click requests
460
368
  }
461
369
 
462
370
  if(o === "!") return l = h; //store href in "l" (last request)
463
371
 
464
372
  if(o === "?") { //Edin previously called this "isOK" - powerful intelligent plausibility check
465
- let xs=$.fn("s");
466
- if (!xs.iO("0") && !p) $.fn("a"); //if fetch is not idle and new request is standard one, do ac.abort() to set it free
373
+ let xs=Ay.fn("s");
374
+ if (!xs.iO("0") && !p) Ay.fn("a"); //if fetch is not idle and new request is standard one, do ac.abort() to set it free
467
375
  if (xs==="1c" && p) return false; //if fetch is processing standard request and new request is prefetch, cancel prefetch until fetch is finished
468
- if (xs==="1p" && p) $.s.memoryoff ? $.fn("a") : 1; //if fetch is processing prefetch request and new request is prefetch do nothing (see [options] comment below)
469
- //([semaphore options for requests] $.fn("a") -> abort previous, proceed with new | return false -> leave previous, stop new | return true -> proceed)
376
+ if (xs==="1p" && p) Ay.s.memoryoff ? Ay.fn("a") : 1; //if fetch is processing prefetch request and new request is prefetch do nothing (see [options] comment below)
377
+ //([semaphore options for requests] Ay.fn("a") -> abort previous, proceed with new | return false -> leave previous, stop new | return true -> proceed)
470
378
  return true;
471
379
  }
472
380
 
473
381
  if(o === "v") { //validate value passed in "p", which is expected to be a click event value - also performs "i" afterwards
474
382
  if(!p) return false; //ensure data
475
383
  _setE(p, t); //Set event and href in one go
476
- if(!$.internal(h)) return false; //if not internal -> report failure
384
+ if(!Ay.internal(h)) return false; //if not internal -> report failure
477
385
  o = "i"; //continue with "i"
478
386
  }
479
387
 
@@ -533,13 +441,13 @@ class Frms { constructor() {
533
441
  let fm = 0, divs = 0;
534
442
 
535
443
  this.a = function (o, p) {
536
- if (!$.s.forms || !o) return; //ensure data
444
+ if (!Ay.s.forms || !o) return; //ensure data
537
445
 
538
446
  if(o === "d") divs = p; //set divs variable
539
447
  if(o === "a") divs.forEach(div => { //iterate through divs
540
- Array.prototype.filter.call(qa($.s.forms, div), function(e) { //filter forms
448
+ Array.prototype.filter.call(qa(Ay.s.forms, div), function(e) { //filter forms
541
449
  let c = e.getAttribute("action");
542
- return($.internal(c && c.length > 0 ? c : $.currentURL)); //ensure "action"
450
+ return(Ay.internal(c && c.length > 0 ? c : Ay.currentURL)); //ensure "action"
543
451
  }).forEach(frm => { //iterate through forms
544
452
  frm.addEventListener("submit", q => { //create event listener
545
453
  fm = q.target; // fetch target
@@ -551,22 +459,22 @@ class Frms { constructor() {
551
459
 
552
460
  var h, a = fm.getAttribute("action"); //fetch action attribute
553
461
  if (a && a.length > 0) h = a; //found -> store
554
- else h = $.currentURL; //not found -> select current URL
462
+ else h = Ay.currentURL; //not found -> select current URL
555
463
 
556
- $.Rq("v", q); //validate request
464
+ Ay.Rq("v", q); //validate request
557
465
 
558
466
  if (g == "get") h = _b(h, p); //GET -> copy URL parameters
559
467
  else {
560
- $.Rq("is", true); //set is POST in request data
561
- $.Rq("d", p); //save data in request data
468
+ Ay.Rq("is", true); //set is POST in request data
469
+ Ay.Rq("d", p); //save data in request data
562
470
  }
563
471
 
564
- $.trigger("submit", h); //raise pronto.submit event
565
- $.pronto(0, { href: h }); //programmatically change page
472
+ Ay.trigger("submit", h); //raise pronto.submit event
473
+ Ay.pronto(0, { href: h }); //programmatically change page
566
474
 
567
475
  q.preventDefault(); //prevent default form action
568
476
  return(false); //success -> disable default behaviour
569
- })
477
+ });
570
478
  });
571
479
  });
572
480
  };
@@ -585,84 +493,6 @@ let _k = () => {
585
493
  }
586
494
  }}
587
495
 
588
- // The stateful Offsets plugin
589
- // Usage:
590
- // 1) $.offsets(<URL>) - returns offset of specified URL from internal array
591
- // 2) $.offsets() - saves the current URL + offset in internal array
592
- class Offsets { constructor() {
593
- let d = [], i = -1;
594
-
595
- this.a = function (h) {
596
- if (typeof h === "string") { //Lookup page offset
597
- h = h.iO("?") ? h.split("?")[0] : h; //Handle root URL only from dynamic pages
598
- i = _iOffset(h); //Fetch offset
599
- if(i === -1) return 0; // scrollTop if not found
600
- return d[i][1]; //Return offset that was found
601
- }
602
-
603
- //Add page offset
604
- var u = $.currentURL, us1 = u.iO("?") ? u.split("?")[0] : u, us = us1.iO("#") ? us1.split("#")[0] : us1, os = [us, (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop];
605
- i = _iOffset(us); //get page index
606
- if(i === -1) d.push(os); //doesn't exist -> push to array
607
- else d[i] = os; //exists -> overwrite
608
- };
609
- let _iOffset = h => d.findIndex(e => e[0] == h)
610
- }}
611
-
612
- // The Scrolly plugin - manages scroll effects centrally
613
- // scrolltop values: "s" - "smart" (default), true - always scroll to top, false - no scroll
614
- // Switch (o) values:
615
- // + - add current page to offsets
616
- // ! - scroll to current page offset
617
- class Scrolly { constructor() {
618
-
619
- if ('scrollRestoration' in history) history.scrollRestoration = 'manual';
620
-
621
- this.a = function (o) {
622
- if(!o) return; //ensure operator
623
-
624
- var op = o; //cache operator
625
-
626
- if(o === "+" || o === "!") o = $.currentURL; //fetch currentURL for "+" and "-" operators
627
-
628
- if(op !== "+" && o.iO("#") && (o.iO("#") < o.length - 1)) { //if hash in URL and not standalone hash
629
- let $el = qs("#" + o.split("#")[1]); //fetch the element
630
- if (!$el) return; //nothing found -> return quickly
631
- let box = $el.getBoundingClientRect();
632
- _scrll(box.top + window.pageYOffset - document.documentElement.clientTop); // ...animate to ID
633
- return;
634
- }
635
-
636
- if($.s.scrolltop === "s") { //smart scroll enabled
637
- if(op === "+") $.offsets(); //add page offset
638
- if(op === "!") _scrll($.offsets(o)); //scroll to stored position of page
639
-
640
- return;
641
- }
642
-
643
- if(op !== "+" && $.s.scrolltop) _scrll(0); //otherwise scroll to top of page
644
-
645
- //default -> do nothing
646
- };
647
- let _scrll = o => setTimeout(() => window.scrollTo(0, o), 10) //delay of 10 milliseconds on all scroll effects
648
- }}
649
-
650
- // The hApi plugin - manages operations on the History API centrally
651
- // Second parameter (p) - set global currentURL
652
- // Switch (o) values:
653
- // = - perform a replaceState, using currentURL
654
- // otherwise - perform a pushState, using currentURL
655
- class HApi { constructor() {
656
-
657
- this.a = function (o, p) {
658
- if(!o) return; //ensure operator
659
- if(p) $.currentURL = p; //if p given -> update current URL
660
-
661
- if(o === "=") history.replaceState({ url: $.currentURL }, "state-" + $.currentURL, $.currentURL); //perform replaceState
662
- else if ($.currentURL !== window.location.href) history.pushState({ url: $.currentURL }, "state-" + $.currentURL, $.currentURL); //perform pushState
663
- };
664
- }}
665
-
666
496
  // The Pronto plugin - Pronto variant of Ben Plum's Pronto plugin - low level event handling in general
667
497
  // Works on a selection, passed to Pronto by the selection, which specifies, which elements to Ajaxify
668
498
  // Switch (h) values:
@@ -671,7 +501,7 @@ class HApi { constructor() {
671
501
  // <URL> - set "h" variable of Rq hard and continue with _request()
672
502
  class Pronto { constructor() {
673
503
  let $gthis = 0, requestTimer = 0, pd = 150, ptim = 0;
674
- $.h.prefetchoff = new Hints($.s.prefetchoff);
504
+ Ay.h.prefetchoff = new Hints(Ay.s.prefetchoff);
675
505
 
676
506
  this.a = function ($this, h) {
677
507
  if(!h) return; //ensure data
@@ -680,48 +510,48 @@ class Pronto { constructor() {
680
510
  bdy = document.body;
681
511
  if(!$this.length) $this = "body";
682
512
  $gthis = qa($this); //copy selection to global selector
683
- $.frms = new Frms().a; //initialise forms sub-plugin
684
- if($.s.idleTime) $.slides = new classSlides($).a; //initialise optional slideshow sub-plugin
685
- $.scrolly = new Scrolly().a; //initialise scroll effects sub-plugin
686
- $.offsets = new Offsets().a;
687
- $.hApi = new HApi().a;
513
+ Ay.frms = new Frms().a; //initialise forms sub-plugin
514
+ if(Ay.s.idleTime) Ay.slides = new classSlides(Ay).a; //initialise optional slideshow sub-plugin
515
+ Ay.scrolly = new Scrolly(); //initialise scroll effects sub-plugin
516
+ (Ay.offsets = new Offsets()).f();
517
+ Ay.hApi = new HApi();
688
518
  _init_p(); //initialise Pronto sub-plugin
689
519
  return $this; //return query selector for chaining
690
520
  }
691
521
 
692
522
  if(typeof(h) === "object") { //jump to internal page programmatically -> handler for forms sub-plugin
693
- $.Rq("h", h);
523
+ Ay.Rq("h", h);
694
524
  _request();
695
525
  return;
696
526
  }
697
527
 
698
528
  if(h.iO("/")) { //jump to internal page programmatically -> default handler
699
- $.Rq("h", h);
529
+ Ay.Rq("h", h);
700
530
  _request(true);
701
531
  }
702
532
  };
703
533
  let _init_p = () => {
704
- $.hApi("=", window.location.href);
534
+ Ay.hApi.r(window.location.href);
705
535
  window.addEventListener("popstate", _onPop);
706
- if ($.s.prefetchoff !== true) {
707
- _on("mouseenter", $.s.selector, _preftime); // start prefetch timeout
708
- _on("mouseleave", $.s.selector, _prefstop); // stop prefetch timeout
709
- _on("touchstart", $.s.selector, _prefetch);
536
+ if (Ay.s.prefetchoff !== true) {
537
+ _on("mouseenter", Ay.s.selector, _preftime); // start prefetch timeout
538
+ _on("mouseleave", Ay.s.selector, _prefstop); // stop prefetch timeout
539
+ _on("touchstart", Ay.s.selector, _prefetch);
710
540
  }
711
- _on("click", $.s.selector, _click, bdy);
712
- $.frms("d", qa("body"));
713
- $.frms("a");
714
- $.frms("d", $gthis);
715
- if($.s.idleTime) $.slides("i");
541
+ _on("click", Ay.s.selector, _click, bdy);
542
+ Ay.frms("d", qa("body"));
543
+ Ay.frms("a");
544
+ Ay.frms("d", $gthis);
545
+ if(Ay.s.idleTime) Ay.slides("i");
716
546
  },
717
547
  _preftime = (t, e) => (_prefstop(), ptim = setTimeout(()=> _prefetch(t, e), pd)), // call prefetch if timeout expires without being cleared by _prefstop
718
548
  _prefstop = () => clearTimeout(ptim),
719
549
  _prefetch = (t, e) => {
720
- if($.s.prefetchoff === true) return;
721
- if (!$.Rq("?", true)) return;
722
- var href = $.Rq("v", e, t);
723
- if ($.Rq("=", true) || !href || $.h.prefetchoff.find(href)) return;
724
- $.fn("+", href, () => false);
550
+ if(Ay.s.prefetchoff === true) return;
551
+ if (!Ay.Rq("?", true)) return;
552
+ var href = Ay.Rq("v", e, t);
553
+ if (Ay.Rq("=", true) || !href || Ay.h.prefetchoff.find(href)) return;
554
+ Ay.fn("+", href, () => false);
725
555
  },
726
556
  _stopBubbling = e => (
727
557
  e.preventDefault(),
@@ -729,69 +559,69 @@ let _init_p = () => {
729
559
  e.stopImmediatePropagation()
730
560
  ),
731
561
  _click = (t, e, notPush) => {
732
- if(!$.Rq("?")) return;
733
- var href = $.Rq("v", e, t);
562
+ if(!Ay.Rq("?")) return;
563
+ var href = Ay.Rq("v", e, t);
734
564
  if(!href || _exoticKey(t)) return;
735
565
  if(href.substr(-1) ==="#") return true;
736
566
  if(_hashChange()) {
737
- $.hApi("=", href);
567
+ Ay.hApi.r(href);
738
568
  return true;
739
569
  }
740
570
 
741
- $.scrolly("+");
571
+ Ay.scrolly.p();
742
572
  _stopBubbling(e);
743
- if($.Rq("=")) $.hApi("=");
744
- if($.s.refresh || !$.Rq("=")) _request(notPush);
573
+ if(Ay.Rq("=")) Ay.hApi.r();
574
+ if(Ay.s.refresh || !Ay.Rq("=")) _request(notPush);
745
575
  },
746
576
  _request = notPush => {
747
- $.Rq("!");
748
- if(notPush) $.Rq("p", false);
749
- $.trigger("request");
750
- $.fn($.Rq("h"), err => {
577
+ Ay.Rq("!");
578
+ if(notPush) Ay.Rq("p", false);
579
+ Ay.trigger("request");
580
+ Ay.fn(Ay.Rq("h"), err => {
751
581
  if (err) {
752
582
  lg("Error in _request : " + err);
753
- $.trigger("error", err);
583
+ Ay.trigger("error", err);
754
584
  }
755
585
 
756
586
  _render();
757
587
  });
758
588
  },
759
589
  _render = () => {
760
- $.trigger("beforeload");
761
- if($.s.requestDelay) {
590
+ Ay.trigger("beforeload");
591
+ if(Ay.s.requestDelay) {
762
592
  if(requestTimer) clearTimeout(requestTimer);
763
- requestTimer = setTimeout(_doRender, $.s.requestDelay);
593
+ requestTimer = setTimeout(_doRender, Ay.s.requestDelay);
764
594
  } else _doRender();
765
595
  },
766
596
  _onPop = e => {
767
597
  var url = window.location.href;
768
598
 
769
- $.Rq("i");
770
- $.Rq("h", url);
771
- $.Rq("p", false);
772
- $.scrolly("+");
599
+ Ay.Rq("i");
600
+ Ay.Rq("h", url);
601
+ Ay.Rq("p", false);
602
+ Ay.scrolly.p();
773
603
 
774
- if (!url || url === $.currentURL) return;
775
- $.trigger("request");
776
- $.fn(url, _render);
604
+ if (!url || url === Ay.currentURL) return;
605
+ Ay.trigger("request");
606
+ Ay.fn(url, _render);
777
607
  },
778
608
  _doRender = () => {
779
- $.trigger("load");
780
- if($.s.bodyClasses) { var classes = $.fn("body").getAttribute("class"); bdy.setAttribute("class", classes ? classes : ""); }
609
+ Ay.trigger("load");
610
+ if(Ay.s.bodyClasses) { var classes = Ay.fn("body").getAttribute("class"); bdy.setAttribute("class", classes ? classes : ""); }
781
611
 
782
- var href = $.Rq("h"), title;
783
- href = $.Rq("c", href);
612
+ var href = Ay.Rq("h"), title;
613
+ href = Ay.Rq("c", href);
784
614
 
785
- $.hApi($.Rq("p") ? "+" : "=", href);
786
- if(title = $.fn("title")) qs("title").innerHTML = title.innerHTML;
787
- $.Rq("C", $.fn("-", $gthis));
788
- $.frms("a");
615
+ if(Ay.Rq("p")) Ay.hApi.p(href); else Ay.hApi.r(href);
616
+ if(title = Ay.fn("title")) qs("title").innerHTML = title.innerHTML;
617
+ Ay.Rq("C", Ay.fn("-", $gthis));
618
+ Ay.frms("a");
789
619
 
790
- $.scrolly("!");
620
+ Ay.scrolly.l();
791
621
  _gaCaptureView(href);
792
- $.trigger("render");
793
- if($.s.passCount) qs("#" + $.s.passCount).innerHTML = "Pass: " + $.pass;
794
- if($.s.cb) $.s.cb();
622
+ Ay.trigger("render");
623
+ if(Ay.s.passCount) qs("#" + Ay.s.passCount).innerHTML = "Pass: " + Ay.pass;
624
+ if(Ay.s.cb) Ay.s.cb();
795
625
  },
796
626
  _gaCaptureView = href => {
797
627
  href = "/" + href.replace(rootUrl,"");
@@ -799,18 +629,18 @@ let _init_p = () => {
799
629
  else if (typeof window._gaq !== "undefined") window._gaq.push(["_trackPageview", href]);
800
630
  },
801
631
  _exoticKey = (t) => {
802
- var href = $.Rq("h"), e = $.Rq("e"), tgt = e.currentTarget.target || t.target;
632
+ var href = Ay.Rq("h"), e = Ay.Rq("e"), tgt = e.currentTarget.target || t.target;
803
633
  return (e.which > 1 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || tgt === "_blank"
804
634
  || href.iO("wp-login") || href.iO("wp-admin"));
805
635
  },
806
636
  _hashChange = () => {
807
- var e = $.Rq("e");
637
+ var e = Ay.Rq("e");
808
638
  return (e.hash && e.href.replace(e.hash, "") === window.location.href.replace(location.hash, "") || e.href === window.location.href + "#");
809
639
  }
810
640
  }}
811
641
 
812
642
 
813
- $.init = () => {
643
+ Ay.init = () => {
814
644
  let o = options;
815
645
  if (!o || typeof(o) !== "string") {
816
646
  if (document.readyState === "complete" ||
@@ -818,36 +648,117 @@ $.init = () => {
818
648
  else document.addEventListener('DOMContentLoaded', run);
819
649
  return $;
820
650
  }
821
- else return $.pronto(0, o);
651
+ else return Ay.pronto(0, o);
822
652
  };
823
653
 
824
654
  let run = () => {
825
- $.s = Object.assign($.s, options);
826
- $.pages = new Pages().a;
827
- $.pronto = new Pronto().a;
655
+ Ay.s = Object.assign(Ay.s, options);
656
+ (Ay.pages = new Pages()).f();
657
+ Ay.pronto = new Pronto().a;
828
658
  if (load()) {
829
- $.pronto($.s.elements, "i");
830
- if ($.s.deltas) $.scripts("1");
659
+ Ay.pronto(Ay.s.elements, "i");
660
+ if (Ay.s.deltas) Ay.scripts("1");
831
661
  }
832
662
  },
833
663
  load = () => {
834
- if (!api || !$.s.pluginon) {
664
+ if (!(window.history && window.history.pushState && window.history.replaceState) || !Ay.s.pluginon) {
835
665
  lg("Gracefully exiting...");
836
666
  return false;
837
667
  }
838
668
 
839
669
  lg("Ajaxify loaded..."); //verbosity option steers, whether this initialisation message is output
840
670
 
841
- if ($.s.intevents) $.intevents(); // intercept events
842
- $.scripts = new Scripts().a;
843
- $.scripts("i");
844
- $.cache = new Cache().a;
845
- $.memory = new Memory().a;
846
- $.fn = $.getPage = new GetPage().a;
847
- $.detScripts = new DetScripts().a;
848
- $.addAll = new AddAll().a;
849
- $.Rq = new RQ().a;
671
+ if (Ay.s.intevents) Ay.intevents(); // intercept events
672
+ Ay.scripts = new Scripts().a;
673
+ Ay.scripts("i");
674
+ Ay.cache = new Cache();
675
+ Ay.memory = new Memory(); Ay.h.memoryoff = new Hints(Ay.s.memoryoff);
676
+ Ay.fn = Ay.getPage = new GetPage().a;
677
+ Ay.detScripts = new DetScripts();
678
+ Ay.addAll = new AddAll().a;
679
+ Ay.Rq = new RQ().a;
850
680
  return true;
681
+ };
682
+ Ay.init(); // initialize Ajaxify on definition
683
+ }}
684
+
685
+ // The stateful Cache class
686
+ // this.d = entire current page (as an object)
687
+ class Cache {
688
+ g(){ return this.d } //getter
689
+ s(v){ return this.d = v } //setter
690
+ l(u){ let v = Ay.memory.l(u); return this.s(v === false ? v : Ay.pages.l(v)) } //lookup URL and load
691
+ }
692
+
693
+ // The stateful Memory class
694
+ // Usage: Ay.memory.l(<URL>) - returns the same URL if not turned off internally
695
+ class Memory {
696
+ l(h){
697
+ if (!h || Ay.s.memoryoff === true) return false;
698
+ if (Ay.s.memoryoff === false) return h;
699
+ return Ay.h.memoryoff.find(h) ? false : h;
851
700
  }
852
- $.init(); // initialize Ajaxify on definition
853
- }}
701
+ }
702
+
703
+ // The stateful Pages class
704
+ // this.d = Array of pages - [0] = URL // [1] = reference to whole page
705
+ class Pages {
706
+ f(){ this.d = [] } //flush
707
+ l(u){ if (this.P(u)) return this.d[this.i][1] } //lookup URL and return page
708
+ 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
709
+ P(u){ return (this.i = this.d.findIndex(e => e[0] == u)) + 1 } //lookup page index and store in "i"
710
+ }
711
+
712
+ // The DetScripts class - stands for "detach scripts"
713
+ // Works on "s" <object> that is passed in and fills it
714
+ class DetScripts {
715
+ d(s) {
716
+ if(!(this.h = Ay.pass ? Ay.fn("head") : qs("head"))) return true; //If pass is 0 -> fetch head from DOM, otherwise from target page
717
+ this.lk = qa(Ay.pass ? ".ajy-link" : "link", this.h); //If pass is 0 -> fetch links from DOM, otherwise from target page
718
+ s.j = Ay.pass ? Ay.fn("script") : qa("script"); //If pass is 0 -> fetch JSs from DOM, otherwise from target page
719
+ s.c = this.x("stylesheet"); //Extract stylesheets
720
+ s.y = qa("style", this.h); //Extract style tags
721
+ s.can = this.x("canonical"); //Extract canonical tag
722
+ }
723
+ x(v){ return Array.prototype.filter.call(this.lk, e => e.getAttribute("rel").iO(v)) } //Extract link tags with given "rel"
724
+ }
725
+
726
+ // The Offsets class
727
+ // this.d = Array of pages - [0] = URL // [1] = offset
728
+ class Offsets {
729
+ f(){ this.d = [] } //flush internal offsets array - must be performed by parent
730
+ l(h){ if(h.iO("?")) h = h.split("?")[0]; //lookup page offset
731
+ return this.O(h) ? this.d[this.i][1] : 0; //return if found otherwise 0
732
+ }
733
+ p(h){ let us1 = h.iO("?") ? h.split("?")[0] : h, //initialise all helper variables in one go
734
+ us = us1.iO("#") ? us1.split("#")[0] : us1,
735
+ os = [us, (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop];
736
+ if(this.O(us)) this.d[this.i]=os; else this.d.push(os); // update if found, otherwise push
737
+ }
738
+ O(h){ return (this.i = this.d.findIndex(e => e[0] == h)) + 1 } //find URL in internal array - add 1 for convenience
739
+ }
740
+
741
+ // The Scrolly class
742
+ // operates on Ay.currentURL
743
+ class Scrolly { constructor() { if ('scrollRestoration' in history) history.scrollRestoration = 'manual' }
744
+ p(){ Ay.s.scrolltop == "s" && Ay.offsets.p(Ay.currentURL) }
745
+ l(){ let o = Ay.currentURL;
746
+ if(o.iO("#") && (o.iO("#") < o.length - 1)) { //if hash in URL and not standalone hash
747
+ let el = qs("#" + o.split("#")[1]); //fetch the element
748
+ if(!el) return; //nothing found -> return quickly
749
+ let box = el.getBoundingClientRect();
750
+ return this.s(box.top + window.pageYOffset - document.documentElement.clientTop); // ...animate to ID
751
+ }
752
+ if(Ay.s.scrolltop == "s") this.s(Ay.offsets.l(o)); //smart scroll -> lookup and restore offset
753
+ else Ay.s.scrolltop && this.s(0); //scrolltop true -> scroll to top of page
754
+ }
755
+ s(o){ window.scrollTo(0, o) } //scroll to offset
756
+ }
757
+
758
+ // The HAPi class
759
+ // operates on Ay.currentURL - manages operations on the History API centrally(replaceState / pushState)
760
+ class HApi {
761
+ r(h){ let c = this.u(h); history.replaceState({ url: c }, "state-" + c, c); } //perform replaceState
762
+ p(h){ let c = this.u(h); if (c !== window.location.href) history.pushState({ url: c }, "state-" + c, c); } //perform pushState
763
+ u(h){ if(h) Ay.currentURL = h; return Ay.currentURL; } //update currentURL if given and return always
764
+ }
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="",$.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)}});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"))}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 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){$.h.memoryoff=new Hints($.s.memoryoff),this.a=function(t){return!(!t||!0===$.s.memoryoff)&&(!1===$.s.memoryoff?t:!$.h.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[0]))?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;$.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"),$.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;$.h.alwayshints=new Hints($.s.alwayshints),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")||$.h.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(){"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 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=>setTimeout(()=>window.scrollTo(0,t),10)}}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;$.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).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)=>(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 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 Ay,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},Ay=this,Ay.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},Ay.pass=0,Ay.currentURL="",Ay.h={},Ay.parse=((t,e)=>(e=document.createElement("div"),e.insertAdjacentHTML("afterbegin",t),e.firstElementChild)),Ay.trigger=((t,e)=>{let r=document.createEvent("HTMLEvents");r.initEvent("pronto."+t,!0,!1),r.data=e||Ay.Rq("e"),window.dispatchEvent(r),document.dispatchEvent(r)}),Ay.internal=(t=>!!t&&("object"==typeof t&&(t=t.href),""===t||(t.substring(0,rootUrl.length)===rootUrl||!t.iO(":")))),Ay.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){Ay.s.verbosity&&console&&console.log(t)}class GetPage{constructor(){let t=0,e=0,r=0,s="",i=0,n=0,o=0,a=/<\!DOCTYPE[^>]*>/i,y=/<(html|head|link)([\s\>])/gi,l=/<(body)([\s\>])/gi,c=/<\/(html|head|body|link)\>/gi;this.a=function(i,a,y){if(!i)return Ay.cache.g();if(i.iO("/")){if(e=a,r==i)return;return d(i)}if("+"===i)return r=a,e=y,d(a,!0);if("a"!==i){if("s"===i)return(n?1:0)+s;if("-"===i)return A(a);if("x"===i)return t;if(Ay.cache.g())return"body"===i?qs("#ajy-"+i,Ay.cache.g()):"script"===i?qa(i,Ay.cache.g()):qs("title"===i?i:".ajy-"+i,Ay.cache.g())}else n>0&&(g(),o.abort())};let A=t=>(Ay.pass++,f(t),qa("body > script").forEach(t=>!!t.classList.contains(inlineclass)&&t.parentNode.removeChild(t)),Ay.scripts(!0),Ay.scripts("s"),Ay.scripts("c")),d=(t,s)=>(t.iO("#")&&(t=t.split("#")[0]),Ay.Rq("is")||!Ay.cache.l(t)?u(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}},f=t=>Ay.cache.g()&&!p(t)&&t.forEach(function(t){h(t,qs("#"+t.getAttribute("id"),Ay.cache.g()))}),p=t=>"body"==t[0].tagName.toLowerCase()&&(h(bdy,qs("#ajy-body",Ay.cache.g())),1),u=(e,r)=>{var i=Ay.Rq("is");s=r?"p":"c",o=new AbortController,n++,fetch(e,{method:i?"POST":"GET",cache:"default",mode:"same-origin",headers:{"X-Requested-With":"XMLHttpRequest"},body:i?Ay.Rq("d"):null,signal:o.signal}).then(s=>{if(s.ok&&q(s))return t=s,s.text();r||(location.href=e,g(),Ay.pronto(0,Ay.currentURL))}).then(r=>{if(g(1),r)return t.responseText=r,m(e,r)}).catch(t=>{if("AbortError"!==t.name)try{return Ay.trigger("error",t),lg("Response text : "+t.message),m(e,t.message,t)}catch(t){}}).finally(()=>n--)},g=t=>(r=0,t?0:e=0),m=(t,r,s)=>Ay.cache.s(Ay.parse(v(r)))&&(Ay.pages.p([t,Ay.cache.g()]),1)&&e&&e(s),q=t=>(i=t.headers.get("content-type"))&&(i.iO("html")||i.iO("form-")),v=t=>document.createElement("html").innerHTML=w(t).trim(),w=t=>String(t).replace(a,"").replace(y,'<div class="ajy-$1"$2').replace(l,'<div id="ajy-$1"$2').replace(c,"</div>")}}class Scripts{constructor(){let $s=!1,txt=0;Ay.h.inlinehints=new Hints(Ay.s.inlinehints),Ay.h.inlineskip=new Hints(Ay.s.inlineskip),this.a=function(t){return"i"===t?($s||($s={}),!0):"s"===t?_allstyle($s.y):"1"===t?(Ay.detScripts.d($s),_addScripts($s)):"c"===t?!(!Ay.s.canonical||!$s.can)&&$s.can.getAttribute("href"):"d"===t?Ay.detScripts.d($s):t&&"object"==typeof t?_onetxt(t):void(Ay.scripts("d")||_addScripts($s))};let _allstyle=t=>!Ay.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(")&&(Ay.s.inline&&!Ay.h.inlineskip.find(txt)||t.classList.contains("ajaxy")||Ay.h.inlinehints.find(txt))&&_addtxt(t),_addtxt=$s=>{if(txt&&txt.length){if(Ay.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(Ay.parse("<style>"+t+"</style>")),_addScripts=t=>(Ay.addAll(t.c,"href"),Ay.addAll(t.j,"src"))}}class AddAll{constructor(){let t=[],e=[],r=[],s=0,i=0;Ay.h.alwayshints=new Hints(Ay.s.alwayshints),this.a=function(c,A){if(c.length){if("n"===Ay.s.deltas)return!0;if(s=A,!Ay.s.deltas)return n(c);t="href"==s?e:r,Ay.pass?c.forEach(function(e){var r=e;if(i=r.getAttribute(s),a(r))return l(),void y(r);i?t.some(t=>t==i)||(t.push(i),y(r)):"href"==s||r.classList.contains("no-ajaxy")||Ay.scripts(r)}):o(c)}};let n=t=>t.forEach(t=>y(t)),o=e=>e.forEach(e=>(i=e.getAttribute(s))?t.push(i):0),a=t=>"always"==t.getAttribute("data-class")||Ay.h.alwayshints.find(i),y=t=>{if(i=t.getAttribute(s),"href"==s)return qs("head").appendChild(Ay.parse('<link rel="stylesheet" type="text/css" href="*" />'.replace("*",i)));if(!i)return Ay.scripts(t);var e=document.createElement("script");e.async=Ay.s.asyncdef,_copyAttributes(e,t),qs("head").appendChild(e)},l=()=>qa(("href"==s?'link[href*="!"]':'script[src*="!"]').replace("!",i)).forEach(t=>t.parentNode.removeChild(t))}}class RQ{constructor(){let t=0,e=0,r=0,s=0,i=0,n=0,o=!1;this.a=function(y,l,c){if("="===y)return l?n===Ay.currentURL||n===o:n===Ay.currentURL;if("!"===y)return o=n;if("?"===y){let t=Ay.fn("s");return t.iO("0")||l||Ay.fn("a"),"1c"===t&&l?!1:("1p"===t&&l&&(!Ay.s.memoryoff||Ay.fn("a")),!0)}if("v"===y){if(!l)return!1;if(a(l,c),!Ay.internal(n))return!1;y="i"}return"i"===y?(t=!1,e=null,r=!0,s=!1,n):"h"===y?(l&&("string"==typeof l&&(i=0),n=l.href?l.href:l),n):"e"===y?(l&&a(l,c),i||n):"p"===y?(void 0!==l&&(r=l),r):"is"===y?(void 0!==l&&(t=l),t):"d"===y?(l&&(e=l),e):"C"===y?(void 0!==l&&(s=l),s):"c"===y?!s||s===l||l.iO("#")||l.iO("?")?l:s:void 0};let a=(t,e)=>n="string"!=typeof(i=t)?i.currentTarget&&i.currentTarget.href||e&&e.href||i.currentTarget.action||i.originalEvent.state.url:i}}class Frms{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=r();var i="get",o=t.getAttribute("method");o.length>0&&"post"==o.toLowerCase()&&(i="post");var a,y=t.getAttribute("action");return a=y&&y.length>0?y:Ay.currentURL,Ay.Rq("v",e),"get"==i?a=s(a,n):(Ay.Rq("is",!0),Ay.Rq("d",n)),Ay.trigger("submit",a),Ay.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,i]of(t.iO("?")&&(t=t.substring(0,t.iO("?"))),e.entries()))r+=`${s}=${encodeURIComponent(i)}&`;return`${t}?${r.slice(0,-1)}`}}}class Pronto{constructor(){let t=0,e=0,r=0;Ay.h.prefetchoff=new Hints(Ay.s.prefetchoff),this.a=function(e,r){if(r)return"i"===r?(bdy=document.body,e.length||(e="body"),t=qa(e),Ay.frms=(new Frms).a,Ay.s.idleTime&&(Ay.slides=new classSlides(Ay).a),Ay.scrolly=new Scrolly,(Ay.offsets=new Offsets).f(),Ay.hApi=new HApi,s(),e):"object"==typeof r?(Ay.Rq("h",r),void y()):void(r.iO("/")&&(Ay.Rq("h",r),y(!0)))};let s=()=>{Ay.hApi.r(window.location.href),window.addEventListener("popstate",c),!0!==Ay.s.prefetchoff&&(_on("mouseenter",Ay.s.selector,i),_on("mouseleave",Ay.s.selector,n),_on("touchstart",Ay.s.selector,o)),_on("click",Ay.s.selector,a,bdy),Ay.frms("d",qa("body")),Ay.frms("a"),Ay.frms("d",t),Ay.s.idleTime&&Ay.slides("i")},i=(t,e)=>(n(),r=setTimeout(()=>o(t,e),150)),n=()=>clearTimeout(r),o=(t,e)=>{if(!0!==Ay.s.prefetchoff&&Ay.Rq("?",!0)){var r=Ay.Rq("v",e,t);Ay.Rq("=",!0)||!r||Ay.h.prefetchoff.find(r)||Ay.fn("+",r,()=>!1)}},a=(t,e,r)=>{if(Ay.Rq("?")){var s=Ay.Rq("v",e,t);if(s&&!h(t)){if("#"===s.substr(-1))return!0;if(f())return Ay.hApi.r(s),!0;Ay.scrolly.p(),(t=>(t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation()))(e),Ay.Rq("=")&&Ay.hApi.r(),!Ay.s.refresh&&Ay.Rq("=")||y(r)}}},y=t=>{Ay.Rq("!"),t&&Ay.Rq("p",!1),Ay.trigger("request"),Ay.fn(Ay.Rq("h"),t=>{t&&(lg("Error in _request : "+t),Ay.trigger("error",t)),l()})},l=()=>{Ay.trigger("beforeload"),Ay.s.requestDelay?(e&&clearTimeout(e),e=setTimeout(A,Ay.s.requestDelay)):A()},c=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.trigger("request"),Ay.fn(e,l))},A=()=>{if(Ay.trigger("load"),Ay.s.bodyClasses){var e=Ay.fn("body").getAttribute("class");bdy.setAttribute("class",e||"")}var r,s=Ay.Rq("h");s=Ay.Rq("c",s),Ay.Rq("p")?Ay.hApi.p(s):Ay.hApi.r(s),(r=Ay.fn("title"))&&(qs("title").innerHTML=r.innerHTML),Ay.Rq("C",Ay.fn("-",t)),Ay.frms("a"),Ay.scrolly.l(),d(s),Ay.trigger("render"),Ay.s.passCount&&(qs("#"+Ay.s.passCount).innerHTML="Pass: "+Ay.pass),Ay.s.cb&&Ay.s.cb()},d=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=Ay.Rq("h"),r=Ay.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")},f=()=>{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 t=options;return t&&"string"==typeof t?Ay.pronto(0,t):("complete"===document.readyState||"loading"!==document.readyState&&!document.documentElement.doScroll?run():document.addEventListener("DOMContentLoaded",run),$)});let run=()=>{Ay.s=Object.assign(Ay.s,options),(Ay.pages=new Pages).f(),Ay.pronto=(new Pronto).a,load()&&(Ay.pronto(Ay.s.elements,"i"),Ay.s.deltas&&Ay.scripts("1"))},load=()=>window.history&&window.history.pushState&&window.history.replaceState&&Ay.s.pluginon?(lg("Ajaxify loaded..."),Ay.s.intevents&&Ay.intevents(),Ay.scripts=(new Scripts).a,Ay.scripts("i"),Ay.cache=new Cache,Ay.memory=new Memory,Ay.h.memoryoff=new Hints(Ay.s.memoryoff),Ay.fn=Ay.getPage=(new GetPage).a,Ay.detScripts=new DetScripts,Ay.addAll=(new AddAll).a,Ay.Rq=(new RQ).a,!0):(lg("Gracefully exiting..."),!1);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(Ay.pass?".ajy-link":"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,r=e.iO("#")?e.split("#")[0]:e,s=[r,document.documentElement&&document.documentElement.scrollTop||document.body.scrollTop];this.O(r)?this.d[this.i]=s:this.d.push(s)}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 r=e.getBoundingClientRect();return this.s(r.top+window.pageYOffset-document.documentElement.clientTop)}"s"==Ay.s.scrolltop?this.s(Ay.offsets.l(t)):Ay.s.scrolltop&&this.s(0)}s(t){window.scrollTo(0,t)}}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}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ajaxify",
3
- "version": "8.1.5",
3
+ "version": "8.2.1",
4
4
  "description": "Ajaxify - The Ajax Plugin",
5
5
  "main": "ajaxify.min.js",
6
6
  "scripts": {