@glitchr/transparent 1.0.34 → 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.34",
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,
@@ -1208,9 +1208,16 @@
1208
1208
 
1209
1209
  $("head").children().each(function() { found |= this.isEqualNode(el); });
1210
1210
  if(!found) {
1211
+
1212
+
1213
+ if(this.tagName != "SCRIPT" || Settings["global_code"] == true) {
1214
+
1215
+ $("head").append(this.cloneNode(true));
1216
+
1217
+ } else {
1211
1218
 
1212
- if(this.tagName != "SCRIPT" || Settings["global_code"] == true) $("head").append(this.cloneNode(true));
1213
- else $("head").append(this);
1219
+ $("head").append(this);
1220
+ }
1214
1221
  }
1215
1222
  });
1216
1223
 
@@ -1221,7 +1228,14 @@
1221
1228
  var found = false;
1222
1229
 
1223
1230
  $("body").children().each(function() { found |= this.isEqualNode(el); });
1224
- if(!found) $("body").append(this);
1231
+ if(!found) {
1232
+
1233
+ if(this.tagName != "SCRIPT" || Settings["global_code"] == true) {
1234
+ $("body").append(this.cloneNode(true));
1235
+ } else {
1236
+ $("body").append(this);
1237
+ }
1238
+ }
1225
1239
  });
1226
1240
 
1227
1241
  // Replace canvases..
@@ -1252,7 +1266,7 @@
1252
1266
 
1253
1267
  if(Settings["global_code"] == true) Transparent.evalScript($(page)[0]);
1254
1268
  document.dispatchEvent(new Event('DOMContentLoaded'));
1255
- window.dispatchEvent(new Event('DOMContentLoaded'));
1269
+ window.dispatchEvent(new Event('DOMContentLoaded'));
1256
1270
 
1257
1271
  Transparent.addLayout();
1258
1272
 
@@ -1532,7 +1546,7 @@
1532
1546
  }
1533
1547
 
1534
1548
  var response = JSON.parse(responseText);
1535
- if(Settings.debug) console.log(response);
1549
+ if(Settings.debug) console.debug(response);
1536
1550
 
1537
1551
  if(response.code == "302") {
1538
1552
 
@@ -1654,10 +1668,59 @@
1654
1668
 
1655
1669
  window.onpopstate = __main__; // Onpopstate pop out straight to previous page.. this creates a jump while changing pages with hash..
1656
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
+
1657
1719
  document.addEventListener('click', __main__, false);
1658
1720
 
1659
1721
  $("form").on("submit", __main__);
1660
1722
  }
1661
1723
 
1724
+
1662
1725
  return Transparent;
1663
1726
  });