@glitchr/transparent 1.0.65 → 1.0.70
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/README.md +0 -1
- package/package.json +1 -1
- package/src/js/transparent.js +220 -74
package/README.md
CHANGED
package/package.json
CHANGED
package/src/js/transparent.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import $ from 'jquery';
|
|
2
|
-
|
|
3
1
|
// Modern browser: use passive event listeners where appropriate for better performance
|
|
4
2
|
jQuery.event.special.touchstart = { setup: function( _, ns, handle ) { this.addEventListener("touchstart", handle, { passive: !ns.includes("noPreventDefault") }); } };
|
|
5
3
|
jQuery.event.special.touchmove = { setup: function( _, ns, handle ) { this.addEventListener("touchmove", handle, { passive: !ns.includes("noPreventDefault") }); } };
|
|
@@ -14,7 +12,6 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
14
12
|
} else if (typeof exports === 'object') {
|
|
15
13
|
module.exports = factory();
|
|
16
14
|
} else {
|
|
17
|
-
root = window;
|
|
18
15
|
root.Transparent = factory();
|
|
19
16
|
}
|
|
20
17
|
|
|
@@ -182,9 +179,59 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
182
179
|
"smoothscroll_duration": "200ms",
|
|
183
180
|
"smoothscroll_speed" : 0,
|
|
184
181
|
"smoothscroll_easing" : "swing",
|
|
185
|
-
"exceptions": []
|
|
182
|
+
"exceptions": [],
|
|
183
|
+
// headlock: list of url substrings/regex to preserve in <head> across page transitions
|
|
184
|
+
// (e.g. third-party widgets like Brevo that inject <style>/<link> dynamically).
|
|
185
|
+
// In addition, head nodes injected dynamically AFTER initial DOMContentLoaded are
|
|
186
|
+
// preserved automatically. Use data-headlock="false" on a head element to opt-out.
|
|
187
|
+
"headlock": [
|
|
188
|
+
"brevo",
|
|
189
|
+
"conversations-widget",
|
|
190
|
+
/brevo/i
|
|
191
|
+
]
|
|
186
192
|
};
|
|
187
193
|
|
|
194
|
+
// Set of <head> children present on initial load. Anything added after is treated
|
|
195
|
+
// as dynamically injected (e.g. Brevo widget) and preserved across transitions.
|
|
196
|
+
var originalHeadNodes = new WeakSet();
|
|
197
|
+
function snapshotHeadNodes() {
|
|
198
|
+
var head = document.head;
|
|
199
|
+
if(!head) return;
|
|
200
|
+
for(var i = 0; i < head.children.length; i++)
|
|
201
|
+
originalHeadNodes.add(head.children[i]);
|
|
202
|
+
}
|
|
203
|
+
// Snapshot synchronously at module-eval time (scripts at end of <body> run before any
|
|
204
|
+
// async script — e.g. Brevo — can inject <style> tags, so the snapshot is clean).
|
|
205
|
+
// A DOMContentLoaded fallback is kept for the rare case where document.head is null
|
|
206
|
+
// (e.g. script loaded inside <head> before it finishes parsing).
|
|
207
|
+
snapshotHeadNodes();
|
|
208
|
+
if(!document.head)
|
|
209
|
+
document.addEventListener("DOMContentLoaded", snapshotHeadNodes, { once: true });
|
|
210
|
+
|
|
211
|
+
Transparent.isHeadlocked = function(el) {
|
|
212
|
+
if(!el || el.nodeType !== 1) return false;
|
|
213
|
+
// Explicit opt-out
|
|
214
|
+
var attr = el.getAttribute && el.getAttribute("data-headlock");
|
|
215
|
+
if(attr === "false") return false;
|
|
216
|
+
// Explicit opt-in via attribute
|
|
217
|
+
if(attr !== null && attr !== undefined) return true;
|
|
218
|
+
// Dynamically injected after initial load
|
|
219
|
+
if(!originalHeadNodes.has(el)) return true;
|
|
220
|
+
// URL pattern match (src/href attributes)
|
|
221
|
+
var patterns = Settings["headlock"] || [];
|
|
222
|
+
if(!patterns.length) return false;
|
|
223
|
+
var url = el.getAttribute && (el.getAttribute("src") || el.getAttribute("href"));
|
|
224
|
+
// <style> elements have no src/href — match against CSS textContent instead
|
|
225
|
+
if(!url && el.tagName === 'STYLE') url = el.textContent || '';
|
|
226
|
+
if(!url) return false;
|
|
227
|
+
for(var i = 0; i < patterns.length; i++) {
|
|
228
|
+
var p = patterns[i];
|
|
229
|
+
if(p instanceof RegExp) { if(p.test(url)) return true; }
|
|
230
|
+
else if(typeof p === "string" && p.length && url.indexOf(p) !== -1) return true;
|
|
231
|
+
}
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
|
|
188
235
|
const State = Transparent.state = {
|
|
189
236
|
|
|
190
237
|
ROOT : "transparent",
|
|
@@ -578,7 +625,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
578
625
|
}
|
|
579
626
|
}
|
|
580
627
|
|
|
581
|
-
|
|
628
|
+
closestEl = $(el).closest("a");
|
|
582
629
|
if(!closestEl.length) closestEl = $(el).closest("button");
|
|
583
630
|
if(!closestEl.length) closestEl = $(el).closest("input");
|
|
584
631
|
if (closestEl.length) el = closestEl[0];
|
|
@@ -893,7 +940,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
893
940
|
} else {
|
|
894
941
|
|
|
895
942
|
if(dom === undefined)
|
|
896
|
-
console.
|
|
943
|
+
console.alert("Response missing..");
|
|
897
944
|
|
|
898
945
|
var parent = Transparent.findElementFromParents(dom, $(this).parents(), 3);
|
|
899
946
|
if (parent === undefined) {
|
|
@@ -957,7 +1004,6 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
957
1004
|
Transparent.evalScript($("body")[0]);
|
|
958
1005
|
}
|
|
959
1006
|
|
|
960
|
-
Transparent.scrollTo({top:0, left:0, duration:0});
|
|
961
1007
|
Transparent.activeOut();
|
|
962
1008
|
}
|
|
963
1009
|
|
|
@@ -977,19 +1023,18 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
977
1023
|
var maxScrollY = $(el).prop("scrollHeight") - Math.round($(el).prop("clientHeight"));
|
|
978
1024
|
if (maxScrollY == 0) maxScrollY = Math.round($(el).prop("clientHeight"));
|
|
979
1025
|
|
|
980
|
-
|
|
981
|
-
|
|
1026
|
+
scrollTop = Math.max(0, Math.min(dict["top"] ?? $(el).prop("scrollTop"), maxScrollY));
|
|
1027
|
+
scrollLeft = Math.max(0, Math.min(dict["left"] ?? $(el).prop("scrollLeft"), maxScrollX));
|
|
982
1028
|
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
1029
|
+
speed = parseFloat(dict["speed"] ?? 0);
|
|
1030
|
+
easing = dict["easing"] ?? "swing";
|
|
1031
|
+
debounce = dict["debounce"] ?? 0;
|
|
986
1032
|
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
1033
|
+
duration = 1000*Transparent.parseDuration(dict["duration"] ?? 0);
|
|
1034
|
+
durationX = 1000*Transparent.parseDuration(dict["duration-x"] ?? dict["duration"] ?? 0);
|
|
1035
|
+
durationY = 1000*Transparent.parseDuration(dict["duration-y"] ?? dict["duration"] ?? 0);
|
|
990
1036
|
|
|
991
1037
|
if(speed) {
|
|
992
|
-
var distanceX = 0, distanceY = 0;
|
|
993
1038
|
|
|
994
1039
|
var currentScrollX = $(el)[0].scrollLeft;
|
|
995
1040
|
if(currentScrollX < scrollLeft || scrollLeft == 0) // Going to the right
|
|
@@ -1234,6 +1279,15 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1234
1279
|
|
|
1235
1280
|
// Replace head..
|
|
1236
1281
|
var head = $(dom).find("head");
|
|
1282
|
+
|
|
1283
|
+
// Snapshot hrefs of already-loaded stylesheets so we can detect new ones
|
|
1284
|
+
// added by the head merge and wait for them to finish loading before
|
|
1285
|
+
// making #page visible (prevents FOUC on cold-cache layout transitions).
|
|
1286
|
+
var _existingStyleHrefs = {};
|
|
1287
|
+
$("head").children("link[rel='stylesheet']").each(function() {
|
|
1288
|
+
var h = this.getAttribute("href"); if(h) _existingStyleHrefs[h] = true;
|
|
1289
|
+
});
|
|
1290
|
+
|
|
1237
1291
|
$("head").children().each(function() {
|
|
1238
1292
|
|
|
1239
1293
|
var el = this;
|
|
@@ -1242,9 +1296,17 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1242
1296
|
head.children().each(function() {
|
|
1243
1297
|
|
|
1244
1298
|
found = this.isEqualNode(el);
|
|
1299
|
+
// Also match identical <style> tags by content (Brevo styles are identical across pages)
|
|
1300
|
+
if(!found && el.tagName === 'STYLE' && this.tagName === 'STYLE' &&
|
|
1301
|
+
el.textContent && this.textContent &&
|
|
1302
|
+
el.textContent.length > 100 && this.textContent.length === el.textContent.length) {
|
|
1303
|
+
found = this.textContent === el.textContent;
|
|
1304
|
+
}
|
|
1245
1305
|
return !found;
|
|
1246
1306
|
});
|
|
1247
1307
|
|
|
1308
|
+
// Preserve headlocked nodes (dynamically injected widgets, url-matched, etc.)
|
|
1309
|
+
if(!found && Transparent.isHeadlocked(el)) found = true;
|
|
1248
1310
|
if(!found) this.remove();
|
|
1249
1311
|
});
|
|
1250
1312
|
|
|
@@ -1256,18 +1318,45 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1256
1318
|
$("head").children().each(function() { found |= this.isEqualNode(el); });
|
|
1257
1319
|
if(!found) {
|
|
1258
1320
|
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1321
|
+
if(this.tagName == "SCRIPT" && Settings["global_code"] != true) {
|
|
1322
|
+
|
|
1323
|
+
// For inline scripts (without src), create and execute
|
|
1324
|
+
if(!this.src || this.src === '') {
|
|
1325
|
+
var script = document.createElement("script");
|
|
1326
|
+
script.text = this.innerHTML;
|
|
1327
|
+
var i = -1, attrs = this.attributes, attr;
|
|
1328
|
+
var N = attrs.length;
|
|
1329
|
+
while ( ++i < N ) {
|
|
1330
|
+
if(attrs[i].name !== 'src') {
|
|
1331
|
+
script.setAttribute( attrs[i].name, attrs[i].value );
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
$("head").append(script);
|
|
1335
|
+
originalHeadNodes.add(script);
|
|
1336
|
+
} else {
|
|
1337
|
+
$("head").append(this);
|
|
1338
|
+
originalHeadNodes.add(this);
|
|
1339
|
+
}
|
|
1263
1340
|
|
|
1264
1341
|
} else {
|
|
1265
1342
|
|
|
1266
|
-
|
|
1343
|
+
var clonedEl = this.cloneNode(true);
|
|
1344
|
+
$("head").append(clonedEl);
|
|
1345
|
+
// Register as an "original" node so it falls through to URL-pattern
|
|
1346
|
+
// matching on future transitions — prevents layout CSS added by
|
|
1347
|
+
// Transparent itself from being auto-headlocked as third-party content.
|
|
1348
|
+
originalHeadNodes.add(clonedEl);
|
|
1267
1349
|
}
|
|
1268
1350
|
}
|
|
1269
1351
|
});
|
|
1270
1352
|
|
|
1353
|
+
// Collect link[rel="stylesheet"] elements inserted by the head merge above
|
|
1354
|
+
var _newStyleLinks = [];
|
|
1355
|
+
$("head").children("link[rel='stylesheet']").each(function() {
|
|
1356
|
+
var h = this.getAttribute("href");
|
|
1357
|
+
if(h && !_existingStyleHrefs[h]) _newStyleLinks.push(this);
|
|
1358
|
+
});
|
|
1359
|
+
|
|
1271
1360
|
var bodyScript = $(dom).find("body > script");
|
|
1272
1361
|
bodyScript.each(function() {
|
|
1273
1362
|
|
|
@@ -1277,10 +1366,27 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1277
1366
|
$("body").children().each(function() { found |= this.isEqualNode(el); });
|
|
1278
1367
|
if(!found) {
|
|
1279
1368
|
|
|
1280
|
-
if(this.tagName
|
|
1281
|
-
|
|
1369
|
+
if(this.tagName == "SCRIPT" && Settings["global_code"] != true) {
|
|
1370
|
+
|
|
1371
|
+
// For inline scripts (without src), create and execute
|
|
1372
|
+
if(!this.src || this.src === '') {
|
|
1373
|
+
var script = document.createElement("script");
|
|
1374
|
+
script.text = this.innerHTML;
|
|
1375
|
+
var i = -1, attrs = this.attributes, attr;
|
|
1376
|
+
var N = attrs.length;
|
|
1377
|
+
while ( ++i < N ) {
|
|
1378
|
+
if(attrs[i].name !== 'src') {
|
|
1379
|
+
script.setAttribute( attrs[i].name, attrs[i].value );
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
$("body").append(script);
|
|
1383
|
+
} else {
|
|
1384
|
+
$("body").append(this);
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1282
1387
|
} else {
|
|
1283
|
-
|
|
1388
|
+
|
|
1389
|
+
$("body").append(this.cloneNode(true));
|
|
1284
1390
|
}
|
|
1285
1391
|
}
|
|
1286
1392
|
});
|
|
@@ -1323,7 +1429,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1323
1429
|
var scrollableElements = Transparent.getScrollableElement();
|
|
1324
1430
|
var scrollableElementsXY = Transparent.getResponsePosition(uuid);
|
|
1325
1431
|
|
|
1326
|
-
for(
|
|
1432
|
+
for(i = 0; i < scrollableElements.length; i++) {
|
|
1327
1433
|
|
|
1328
1434
|
var el = scrollableElements[i];
|
|
1329
1435
|
var positionXY = undefined;
|
|
@@ -1345,18 +1451,41 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1345
1451
|
}
|
|
1346
1452
|
}
|
|
1347
1453
|
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1454
|
+
// Wait for any newly added layout stylesheets to finish loading before
|
|
1455
|
+
// calling callback() / activeOut() — otherwise #page becomes visible while
|
|
1456
|
+
// the new CSS is still being parsed, causing a flash of unstyled content.
|
|
1457
|
+
(function() {
|
|
1458
|
+
function doCallback() {
|
|
1459
|
+
$('head').append(function() {
|
|
1460
|
+
$(Settings.identifier).append(function() {
|
|
1461
|
+
callback();
|
|
1462
|
+
dispatchEvent(new Event('transparent:load'));
|
|
1463
|
+
dispatchEvent(new Event('load'));
|
|
1464
|
+
});
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
if(_newStyleLinks.length === 0) {
|
|
1468
|
+
doCallback();
|
|
1469
|
+
} else {
|
|
1470
|
+
var remaining = _newStyleLinks.length;
|
|
1471
|
+
var fired = false;
|
|
1472
|
+
// Safety valve: if a stylesheet fails or stalls, don't block forever.
|
|
1473
|
+
var guard = setTimeout(function() {
|
|
1474
|
+
if(!fired) { fired = true; doCallback(); }
|
|
1475
|
+
}, 3000);
|
|
1476
|
+
_newStyleLinks.forEach(function(link) {
|
|
1477
|
+
function onDone() {
|
|
1478
|
+
if(--remaining <= 0 && !fired) {
|
|
1479
|
+
fired = true;
|
|
1480
|
+
clearTimeout(guard);
|
|
1481
|
+
doCallback();
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
link.addEventListener('load', onDone, {once:true});
|
|
1485
|
+
link.addEventListener('error', onDone, {once:true});
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1488
|
+
})();
|
|
1360
1489
|
|
|
1361
1490
|
}.bind(this), activeInRemainingTime > 0 ? activeInRemainingTime : 1);
|
|
1362
1491
|
}
|
|
@@ -1461,7 +1590,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1461
1590
|
var elementsXY = [];
|
|
1462
1591
|
var elements = Transparent.getScrollableElement();
|
|
1463
1592
|
|
|
1464
|
-
for(
|
|
1593
|
+
for(i = 0; i < elements.length; i++)
|
|
1465
1594
|
elementsXY.push([$(elements[i]).scrollTop(), $(elements[i]).scrollLeft()]);
|
|
1466
1595
|
|
|
1467
1596
|
return elementsXY;
|
|
@@ -1493,10 +1622,8 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1493
1622
|
// Wait for transparent window event to be triggered
|
|
1494
1623
|
if (!isReady) return;
|
|
1495
1624
|
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
e.type !== Transparent.state.HASHCHANGE &&
|
|
1499
|
-
!$ctx.find(Settings.identifier).length) return;
|
|
1625
|
+
if (e.type != Transparent.state.POPSTATE &&
|
|
1626
|
+
e.type != Transparent.state.HASHCHANGE && !$(this).find(Settings.identifier).length) return;
|
|
1500
1627
|
|
|
1501
1628
|
var form = target != undefined && target.tagName == "FORM" ? target : undefined;
|
|
1502
1629
|
var formTrigger = undefined;
|
|
@@ -1596,34 +1723,35 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1596
1723
|
catch (e) { return false; }
|
|
1597
1724
|
}
|
|
1598
1725
|
|
|
1599
|
-
function handleResponse(uuid, status = 200, method = null, data = null,
|
|
1726
|
+
function handleResponse(uuid, status = 200, method = null, data = null, xhr = null, request = null) {
|
|
1600
1727
|
|
|
1601
1728
|
ajaxSemaphore = false;
|
|
1729
|
+
|
|
1730
|
+
var responseURL;
|
|
1731
|
+
responseURL = xhr !== null ? xhr.responseURL : url.href;
|
|
1602
1732
|
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
var responseText = Transparent.getResponseText(uuid);
|
|
1733
|
+
responseText = Transparent.getResponseText(uuid);
|
|
1606
1734
|
|
|
1607
|
-
|
|
1608
|
-
var strippedResponseUrl = (
|
|
1735
|
+
var fragmentPos = responseURL.indexOf("#");
|
|
1736
|
+
var strippedResponseUrl = (fragmentPos < 0 ? responseURL : responseURL.substring(0, fragmentPos)).trimEnd("/");
|
|
1609
1737
|
|
|
1610
|
-
|
|
1611
|
-
var strippedUrlHref = (
|
|
1738
|
+
var fragmentPos = url.href.indexOf("#");
|
|
1739
|
+
var strippedUrlHref = (fragmentPos < 0 ? url.href : url.href.substring(0, fragmentPos)).trimEnd("/");
|
|
1612
1740
|
if( strippedUrlHref == strippedResponseUrl )
|
|
1613
|
-
responseURL = url.href; // NB:
|
|
1741
|
+
responseURL = url.href; // NB: xhr.responseURL strips away #fragments
|
|
1614
1742
|
|
|
1615
1743
|
if(!responseText) {
|
|
1616
1744
|
|
|
1617
|
-
if(!
|
|
1745
|
+
if(!request && responseText === null) {
|
|
1618
1746
|
|
|
1619
1747
|
setTimeout(function() { window.location.href = responseURL; }, Settings["throttle"]);
|
|
1620
1748
|
return;
|
|
1621
1749
|
}
|
|
1622
1750
|
|
|
1623
|
-
responseText =
|
|
1751
|
+
responseText = request.responseText;
|
|
1624
1752
|
if(status >= 500) {
|
|
1625
1753
|
|
|
1626
|
-
console.error("Unexpected response from "+uuid+": error code "+status);
|
|
1754
|
+
console.error("Unexpected XHR response from "+uuid+": error code "+request.status);
|
|
1627
1755
|
console.error(sessionStorage);
|
|
1628
1756
|
}
|
|
1629
1757
|
|
|
@@ -1632,7 +1760,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1632
1760
|
}
|
|
1633
1761
|
|
|
1634
1762
|
var dom = new DOMParser().parseFromString(responseText, "text/html");
|
|
1635
|
-
if(
|
|
1763
|
+
if(request && request.getResponseHeader("Content-Type") == "application/json") {
|
|
1636
1764
|
|
|
1637
1765
|
if(!isJsonResponse(responseText)) {
|
|
1638
1766
|
console.error("Invalid response received for "+ responseURL);
|
|
@@ -1658,7 +1786,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1658
1786
|
}
|
|
1659
1787
|
|
|
1660
1788
|
// Invalid html page returned
|
|
1661
|
-
if(
|
|
1789
|
+
if(request && request.getResponseHeader("Content-Type") == "text/html") {
|
|
1662
1790
|
|
|
1663
1791
|
if (!responseText.includes("<html") && !responseText.includes("<body") && !responseText.includes("<head"))
|
|
1664
1792
|
return Transparent.rescue(dom);
|
|
@@ -1677,7 +1805,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1677
1805
|
|
|
1678
1806
|
// From here the page is valid..
|
|
1679
1807
|
// so the new page is added to history..
|
|
1680
|
-
if(
|
|
1808
|
+
if(xhr)
|
|
1681
1809
|
history.pushState({uuid: uuid, status:status, method: method, data: {}, href: responseURL}, '', responseURL);
|
|
1682
1810
|
|
|
1683
1811
|
// Page not recognized.. just go fetch by yourself.. no POST information transmitted..
|
|
@@ -1721,6 +1849,24 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1721
1849
|
if($(dom).find("html").hasClass(Transparent.state.RELOAD) || $(dom).find("html").hasClass(Transparent.state.DISABLE))
|
|
1722
1850
|
return window.location.reload();
|
|
1723
1851
|
|
|
1852
|
+
// Kick off preloads for stylesheets the new page needs but aren't yet in <head>.
|
|
1853
|
+
// They download in parallel during the activeIn animation so onLoad() finds them
|
|
1854
|
+
// already cached — eliminating FOUC on cold-cache layout transitions.
|
|
1855
|
+
(function() {
|
|
1856
|
+
var loaded = {};
|
|
1857
|
+
$("head").children("link[rel='stylesheet']").each(function() {
|
|
1858
|
+
var h = this.getAttribute("href"); if(h) loaded[h] = true;
|
|
1859
|
+
});
|
|
1860
|
+
$(dom).find("head").children("link[rel='stylesheet']").each(function() {
|
|
1861
|
+
var h = this.getAttribute("href");
|
|
1862
|
+
if(!h || loaded[h]) return;
|
|
1863
|
+
if($("head").find("link[rel='preload'][href='" + h.replace(/'/g, "\\'") + "']").length) return;
|
|
1864
|
+
var pl = document.createElement("link");
|
|
1865
|
+
pl.rel = "preload"; pl.as = "style"; pl.href = h;
|
|
1866
|
+
document.head.appendChild(pl);
|
|
1867
|
+
});
|
|
1868
|
+
})();
|
|
1869
|
+
|
|
1724
1870
|
return Transparent.onLoad(uuid, dom, function() {
|
|
1725
1871
|
|
|
1726
1872
|
Transparent.activeOut(function() {
|
|
@@ -1749,20 +1895,20 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1749
1895
|
$(Transparent.html).prop("user-scroll", false); // make sure to avoid page jump during transition (cancelled in activeIn callback)
|
|
1750
1896
|
|
|
1751
1897
|
// Submit ajax request..
|
|
1752
|
-
ajaxSemaphore = true; // Raise before dispatching synthetic submit to prevent double-submission
|
|
1753
1898
|
if(form) form.dispatchEvent(new SubmitEvent("submit", { submitter: formTrigger }));
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
handleResponse(uuid,
|
|
1899
|
+
var xhr = new XMLHttpRequest();
|
|
1900
|
+
|
|
1901
|
+
ajaxSemaphore = true;
|
|
1902
|
+
return jQuery.ajax({
|
|
1903
|
+
url: url.href,
|
|
1904
|
+
type: type,
|
|
1905
|
+
data: data,
|
|
1906
|
+
contentType: false,
|
|
1907
|
+
processData: false,
|
|
1908
|
+
headers: Settings["headers"] || {},
|
|
1909
|
+
xhr: function () { return xhr; },
|
|
1910
|
+
success: function (html, status, request) { return handleResponse(uuid, request.status, type, data, xhr, request); },
|
|
1911
|
+
error: function (request, ajaxOptions, thrownError) { return handleResponse(uuid, request.status, type, data, xhr, request); }
|
|
1766
1912
|
});
|
|
1767
1913
|
}
|
|
1768
1914
|
|
|
@@ -1782,8 +1928,8 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1782
1928
|
|
|
1783
1929
|
if(Settings.debug) console.debug("Transparent is disabled..");
|
|
1784
1930
|
|
|
1785
|
-
|
|
1786
|
-
|
|
1931
|
+
var states = Object.values(Transparent.state);
|
|
1932
|
+
var htmlClass = Array.from(($("html").attr("class") || "").split(" ")).filter(x => !states.includes(x));
|
|
1787
1933
|
Transparent.html.removeClass(states).addClass(htmlClass.join(" ")+" "+Transparent.state.ROOT+" "+Transparent.state.READY+" "+Transparent.state.DISABLE);
|
|
1788
1934
|
|
|
1789
1935
|
} else {
|
|
@@ -1869,7 +2015,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1869
2015
|
var fieldValueBefore = formDataBefore[fieldName];
|
|
1870
2016
|
if(fieldValueBefore instanceof File) {
|
|
1871
2017
|
|
|
1872
|
-
if(!
|
|
2018
|
+
if(!fieldValueAfter instanceof File) preventDefault = true;
|
|
1873
2019
|
else if (fieldValueBefore.size != fieldValueAfter.size) preventDefault = true;
|
|
1874
2020
|
|
|
1875
2021
|
} else if(fieldValueBefore != fieldValueAfter) {
|
|
@@ -1890,7 +2036,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
|
|
|
1890
2036
|
|
|
1891
2037
|
document.addEventListener('click', __main__, false);
|
|
1892
2038
|
|
|
1893
|
-
$(
|
|
2039
|
+
$("form").on("submit", __main__);
|
|
1894
2040
|
}
|
|
1895
2041
|
|
|
1896
2042
|
|