@glitchr/transparent 1.0.54 → 1.0.55

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glitchr/transparent",
3
- "version": "1.0.54",
3
+ "version": "1.0.55",
4
4
  "description": "Transparent SPA Application",
5
5
  "main": "src/index.js",
6
6
  "access": "public",
@@ -1,3 +1,10 @@
1
+ // Modern browser: use passive event listeners where appropriate for better performance
2
+ jQuery.event.special.touchstart = { setup: function( _, ns, handle ) { this.addEventListener("touchstart", handle, { passive: !ns.includes("noPreventDefault") }); } };
3
+ jQuery.event.special.touchmove = { setup: function( _, ns, handle ) { this.addEventListener("touchmove", handle, { passive: !ns.includes("noPreventDefault") }); } };
4
+ jQuery.event.special.wheel = { setup: function( _, ns, handle ) { this.addEventListener("wheel", handle, { passive: true }); } };
5
+ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addEventListener("mousewheel", handle, { passive: true }); } };
6
+
7
+ // Transparent.js
1
8
  (function (root, factory) {
2
9
 
3
10
  if (typeof define === 'function' && define.amd) {
@@ -1495,10 +1502,16 @@
1495
1502
  }
1496
1503
 
1497
1504
  // Specific page exception
1498
- for(i = 0; i < Settings.exceptions.length; i++) {
1499
-
1500
- exception = Settings.exceptions[i];
1501
- if (url.pathname.startsWith(exception)) return;
1505
+ for (let i = 0; i < Settings.exceptions.length; i++) {
1506
+ let exception = Settings.exceptions[i];
1507
+ if (exception instanceof RegExp) {
1508
+ if (exception.test(url.pathname)) return;
1509
+ } else {
1510
+ // Simple wildcard support: * matches any sequence of characters
1511
+ let pattern = exception.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
1512
+ let regex = new RegExp('^' + pattern + '$');
1513
+ if (regex.test(url.pathname)) return;
1514
+ }
1502
1515
  }
1503
1516
 
1504
1517
  // Ressources files rejected
@@ -1532,8 +1545,9 @@
1532
1545
  if(e.metaKey && e.shiftKey) return window.open(url, '_blank').focus(); // Safari not focusing..
1533
1546
  if(e.metaKey || $(target).attr("target") == "_blank") return window.open(url, '_blank');
1534
1547
 
1535
- dispatchEvent(new Event('transparent:onbeforeunload'));
1536
- dispatchEvent(new Event('onbeforeunload'));
1548
+ // right (still limited by browser policy):
1549
+ dispatchEvent(new Event('transparent:beforeunload'));
1550
+ dispatchEvent(new Event('beforeunload', { cancelable: true }));
1537
1551
 
1538
1552
  $(Transparent.html).prop("user-scroll", true);
1539
1553
  $(Transparent.html).stop();
@@ -1772,6 +1786,8 @@
1772
1786
 
1773
1787
  window.onbeforeunload = function(e) {
1774
1788
 
1789
+ if(Settings.debug) console.log("Transparent onbeforeunload event called..");
1790
+
1775
1791
  if(formSubmission) return; // Do not display on form submission
1776
1792
  if(Settings.disable) return;
1777
1793
 
@@ -1802,8 +1818,6 @@
1802
1818
 
1803
1819
  var formDataBeforeKeys = Object.keys(formDataBefore);
1804
1820
  var formDataAfterKeys = Object.keys(formDataAfter);
1805
- var formDataBeforeEntries = Object.entries(formDataBefore);
1806
- var formDataAfterEntries = Object.entries(formDataAfter);
1807
1821
  function same(a, b) { return JSON.stringify(a) === JSON.stringify(b); }
1808
1822
  function sameKeys(a, b) {
1809
1823