@glitchr/transparent 1.0.35 → 1.0.36

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.35",
3
+ "version": "1.0.36",
4
4
  "description": "Transparent SPA Application",
5
5
  "main": "src/index.js",
6
6
  "access": "public",
@@ -160,7 +160,7 @@
160
160
  "data": {},
161
161
  "disable": false,
162
162
  "global_code": true,
163
- "debug": true,
163
+ "debug": false,
164
164
  "lazyload": true,
165
165
  "response_text": {},
166
166
  "response_limit": 25,
@@ -1546,7 +1546,7 @@
1546
1546
  }
1547
1547
 
1548
1548
  var response = JSON.parse(responseText);
1549
- if(Settings.debug) console.log(response);
1549
+ if(Settings.debug) console.debug(response);
1550
1550
 
1551
1551
  if(response.code == "302") {
1552
1552
 
@@ -1668,10 +1668,59 @@
1668
1668
 
1669
1669
  window.onpopstate = __main__; // Onpopstate pop out straight to previous page.. this creates a jump while changing pages with hash..
1670
1670
  window.onhashchange = __main__;
1671
+
1672
+ var formDataBefore = {};
1673
+ $(window).on("DOMContentLoaded", function() {
1674
+
1675
+ formDataBefore = {};
1676
+ $("form").each(function() {
1677
+
1678
+ var formData = new FormData(this);
1679
+ for (var [fieldName,fieldValue] of formData.entries()) {
1680
+ formDataBefore[fieldName] = fieldValue;
1681
+ }
1682
+ });
1683
+ });
1684
+
1685
+ window.onbeforeunload = function() {
1686
+
1687
+ var preventDefault = false;
1688
+ var formDataAfter = [];
1689
+ $("form").each(function() {
1690
+
1691
+ var formData = new FormData(this);
1692
+ for (var [fieldName,fieldValue] of formData.entries()) {
1693
+ formDataAfter[fieldName] = fieldValue;
1694
+ }
1695
+ });
1696
+
1697
+ var formDataBeforeKeys = Object.entries(formDataBefore).keys();
1698
+ var formDataAfterKeys = Object.entries(formDataAfter).keys();
1699
+
1700
+ if(formDataAfterKeys != formDataAfterKeys) preventDefault = true;
1701
+ else {
1702
+
1703
+ for (var [fieldName,fieldValueAfter] of Object.entries(formDataAfter)) {
1704
+
1705
+ var fieldValueBefore = formDataBefore[fieldName];
1706
+ if(fieldValueBefore instanceof File) {
1707
+
1708
+ if(!fieldValueAfter instanceof File) preventDefault = true;
1709
+ else if (fieldValueBefore.size != fieldValueAfter.size) preventDefault = true;
1710
+
1711
+ } else if(fieldValueBefore != fieldValueAfter) preventDefault = true;
1712
+ }
1713
+ }
1714
+
1715
+ if(Settings.debug || preventDefault)
1716
+ return "Dude, are you sure you want to leave? Think of the kittens!";
1717
+ }
1718
+
1671
1719
  document.addEventListener('click', __main__, false);
1672
1720
 
1673
1721
  $("form").on("submit", __main__);
1674
1722
  }
1675
1723
 
1724
+
1676
1725
  return Transparent;
1677
1726
  });