@glitchr/transparent 1.0.47 → 1.0.49

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.47",
3
+ "version": "1.0.49",
4
4
  "description": "Transparent SPA Application",
5
5
  "main": "src/index.js",
6
6
  "access": "public",
@@ -1453,20 +1453,25 @@
1453
1453
  if (form) {
1454
1454
 
1455
1455
  data = new FormData();
1456
- var formInput = $(form).find(":input, [name^='"+form.name+"\[']");
1457
- formInput.each(function() {
1456
+ var formAmbiguity = $("form[name='"+form.name+"']").length > 1;
1457
+
1458
+ var formInput = undefined; // In case of form ambiguity (two form with same name, restrict the data to the target form, if not extends it to each element with standard name)
1459
+ if(formAmbiguity) formInput = $(form).find(":input, [name^='"+form.name+"\[']");
1460
+ else formInput = $("form[name='"+form.name+"'] :input, [name^='"+form.name+"\[']");
1461
+
1462
+ formInput.each(function() {
1458
1463
 
1459
- if(this.tagName == "BUTTON") {
1464
+ if(this.tagName == "BUTTON") {
1460
1465
 
1461
- if(this == e.target) data.append(this.name, this.value);
1466
+ if(this == e.target) data.append(this.name, this.value);
1462
1467
 
1463
- } else if(this.type == "file") {
1468
+ } else if(this.type == "file") {
1464
1469
 
1465
- for(var i = 0; i < this.files.length; i++)
1466
- data.append(this.name, this.files[i]);
1470
+ for(var i = 0; i < this.files.length; i++)
1471
+ data.append(this.name, this.files[i]);
1467
1472
 
1468
- } else data.append(this.name, this.value);
1469
- });
1473
+ } else data.append(this.name, this.value);
1474
+ });
1470
1475
 
1471
1476
  // Force page reload
1472
1477
  formSubmission = true; // mark as form submission
@@ -1713,7 +1718,7 @@
1713
1718
  window.onhashchange = __main__;
1714
1719
 
1715
1720
  var formDataBefore = {};
1716
- $(window).on("DOMContentLoaded", function() {
1721
+ $(window).on("load", function() {
1717
1722
 
1718
1723
  formDataBefore = {};
1719
1724
  $("form").each(function() {
@@ -1743,6 +1748,8 @@
1743
1748
  if(formSubmission) return; // Do not display on form submission
1744
1749
  if(Settings.disable) return;
1745
1750
 
1751
+ if(e.currentTarget == window) return;
1752
+
1746
1753
  var preventDefault = false;
1747
1754
  var formDataAfter = [];
1748
1755
  $("form").each(function() {
@@ -1770,15 +1777,15 @@
1770
1777
  var formDataAfterKeys = Object.keys(formDataAfter);
1771
1778
  var formDataBeforeEntries = Object.entries(formDataBefore);
1772
1779
  var formDataAfterEntries = Object.entries(formDataAfter);
1773
- function compare(a, b) { return JSON.stringify(a) === JSON.stringify(b); }
1774
- function compareKeys(a, b) {
1780
+ function same(a, b) { return JSON.stringify(a) === JSON.stringify(b); }
1781
+ function sameKeys(a, b) {
1775
1782
 
1776
1783
  var aKeys = Object.keys(a).sort();
1777
1784
  var bKeys = Object.keys(b).sort();
1778
1785
  return JSON.stringify(aKeys) === JSON.stringify(bKeys);
1779
1786
  }
1780
1787
 
1781
- if(!compareKeys(formDataBeforeKeys, formDataAfterKeys)) preventDefault = true;
1788
+ if(!sameKeys(formDataBeforeKeys, formDataAfterKeys)) preventDefault = true;
1782
1789
  else {
1783
1790
 
1784
1791
  for (var [fieldName,fieldValueAfter] of Object.entries(formDataAfter)) {
@@ -1789,7 +1796,9 @@
1789
1796
  if(!fieldValueAfter instanceof File) preventDefault = true;
1790
1797
  else if (fieldValueBefore.size != fieldValueAfter.size) preventDefault = true;
1791
1798
 
1792
- } else if(fieldValueBefore != fieldValueAfter) preventDefault = true;
1799
+ } else if(fieldValueBefore != fieldValueAfter) {
1800
+ preventDefault = true;
1801
+ }
1793
1802
  }
1794
1803
  }
1795
1804