@glitchr/transparent 1.0.44 → 1.0.45

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.44",
3
+ "version": "1.0.45",
4
4
  "description": "Transparent SPA Application",
5
5
  "main": "src/index.js",
6
6
  "access": "public",
@@ -419,6 +419,12 @@
419
419
  Transparent.configure({'x-ajax-request': true});
420
420
  Transparent.configure(options);
421
421
 
422
+ if(Settings.debug) {
423
+
424
+ if (Settings.disable) console.debug("Transparent is disabled..");
425
+ else console.debug("Transparent is running..");
426
+ }
427
+
422
428
  isReady = true;
423
429
 
424
430
  dispatchEvent(new Event('transparent:'+Transparent.state.READY));
@@ -1453,7 +1459,7 @@
1453
1459
  } else if(this.type == "file") {
1454
1460
 
1455
1461
  for(var i = 0; i < this.files.length; i++)
1456
- data.append(this.name, field.files[i]);
1462
+ data.append(this.name, this.files[i]);
1457
1463
 
1458
1464
  } else data.append(this.name, this.value);
1459
1465
  });
@@ -1686,12 +1692,16 @@
1686
1692
  // Overload onpopstate
1687
1693
  if(Settings.disable) {
1688
1694
 
1695
+ if(Settings.debug) console.debug("Transparent is disabled..");
1696
+
1689
1697
  var states = Object.values(Transparent.state);
1690
1698
  var htmlClass = Array.from(($("html").attr("class") || "").split(" ")).filter(x => !states.includes(x));
1691
1699
  Transparent.html.removeClass(states).addClass(htmlClass.join(" ")+" "+Transparent.state.ROOT+" "+Transparent.state.READY+" "+Transparent.state.DISABLE);
1692
1700
 
1693
1701
  } else {
1694
1702
 
1703
+ if(Settings.debug) console.debug("Transparent is running..");
1704
+
1695
1705
  window.onpopstate = __main__; // Onpopstate pop out straight to previous page.. this creates a jump while changing pages with hash..
1696
1706
  window.onhashchange = __main__;
1697
1707
 
@@ -1708,13 +1718,16 @@
1708
1718
  if(this.type == "file") {
1709
1719
 
1710
1720
  for(var i = 0; i < this.files.length; i++)
1711
- formData.append(this.name, field.files[i]);
1721
+ formData.append(this.name+"["+i+"]", this.files[i].name+";"+this.files[i].size+";"+this.files[i].lastModified);
1712
1722
 
1713
1723
  } else formData.append(this.name, this.value);
1714
1724
  });
1715
1725
 
1716
- for (var [fieldName,fieldValue] of formData.entries())
1717
- formDataBefore[fieldName] = fieldValue;
1726
+ for (var [fieldName,fieldValue] of formData.entries()) {
1727
+
1728
+ if(!fieldName.endsWith("[]") && fieldName != "undefined")
1729
+ formDataBefore[fieldName] = fieldValue;
1730
+ }
1718
1731
  });
1719
1732
  });
1720
1733
 
@@ -1734,20 +1747,31 @@
1734
1747
  if(this.type == "file") {
1735
1748
 
1736
1749
  for(var i = 0; i < this.files.length; i++)
1737
- formData.append(this.name, field.files[i]);
1750
+ formData.append(this.name+"["+i+"]", this.files[i].name+";"+this.files[i].size+";"+this.files[i].lastModified);
1738
1751
 
1739
1752
  } else formData.append(this.name, this.value);
1740
1753
  });
1741
1754
 
1742
1755
  for (var [fieldName,fieldValue] of formData.entries()) {
1743
- formDataAfter[fieldName] = fieldValue;
1756
+
1757
+ if(!fieldName.endsWith("[]") && fieldName != "undefined")
1758
+ formDataAfter[fieldName] = fieldValue;
1744
1759
  }
1745
1760
  });
1746
1761
 
1747
- var formDataBeforeKeys = Object.entries(formDataBefore).keys();
1748
- var formDataAfterKeys = Object.entries(formDataAfter).keys();
1762
+ var formDataBeforeKeys = Object.keys(formDataBefore);
1763
+ var formDataAfterKeys = Object.keys(formDataAfter);
1764
+ var formDataBeforeEntries = Object.entries(formDataBefore);
1765
+ var formDataAfterEntries = Object.entries(formDataAfter);
1766
+ function compare(a, b) { return JSON.stringify(a) === JSON.stringify(b); }
1767
+ function compareKeys(a, b) {
1768
+
1769
+ var aKeys = Object.keys(a).sort();
1770
+ var bKeys = Object.keys(b).sort();
1771
+ return JSON.stringify(aKeys) === JSON.stringify(bKeys);
1772
+ }
1749
1773
 
1750
- if(formDataAfterKeys != formDataAfterKeys) preventDefault = true;
1774
+ if(!compareKeys(formDataBeforeKeys, formDataAfterKeys)) preventDefault = true;
1751
1775
  else {
1752
1776
 
1753
1777
  for (var [fieldName,fieldValueAfter] of Object.entries(formDataAfter)) {