@glitchr/transparent 1.0.44 → 1.0.46

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.46",
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));
@@ -463,6 +469,10 @@
463
469
  case "INPUT":
464
470
  case "BUTTON":
465
471
  var form = $(el).closest("form");
472
+ if (form.length) return form[0];
473
+
474
+ var formName = $(el).attr("name").split("[")[0];
475
+ form = $("form[name="+formName+"]");
466
476
  return (form.length ? form[0] : undefined);
467
477
  }
468
478
 
@@ -1453,7 +1463,7 @@
1453
1463
  } else if(this.type == "file") {
1454
1464
 
1455
1465
  for(var i = 0; i < this.files.length; i++)
1456
- data.append(this.name, field.files[i]);
1466
+ data.append(this.name, this.files[i]);
1457
1467
 
1458
1468
  } else data.append(this.name, this.value);
1459
1469
  });
@@ -1628,7 +1638,7 @@
1628
1638
 
1629
1639
  dispatchEvent(new Event('transparent:'+switchLayout));
1630
1640
 
1631
- if($(dom).find("html").hasClass(Transparent.state.RELOAD))
1641
+ if($(dom).find("html").hasClass(Transparent.state.RELOAD) || $(dom).find("html").hasClass(Transparent.state.DISABLE))
1632
1642
  return window.location.reload();
1633
1643
 
1634
1644
  return Transparent.onLoad(uuid, dom, function() {
@@ -1652,7 +1662,7 @@
1652
1662
  // It is null when dev is pushing or replacing state
1653
1663
  var addNewState = !e.state;
1654
1664
  if (addNewState) {
1655
-
1665
+
1656
1666
  if(history.state)
1657
1667
  Transparent.setResponse(history.state.uuid, Transparent.html[0], Transparent.getScrollableElementXY());
1658
1668
 
@@ -1683,15 +1693,22 @@
1683
1693
  if (href != location.origin + location.pathname + location.hash)
1684
1694
  history.replaceState({uuid: uuidv4(), status: history.state ? history.state.status : 200, data:{}, method: history.state ? history.state.method : "GET", href: location.origin + location.pathname + location.hash}, '', location.origin + location.pathname + location.hash);
1685
1695
 
1696
+ if($("html").hasClass(Transparent.state.DISABLE))
1697
+ Settings.disable = true;
1698
+
1686
1699
  // Overload onpopstate
1687
1700
  if(Settings.disable) {
1688
1701
 
1702
+ if(Settings.debug) console.debug("Transparent is disabled..");
1703
+
1689
1704
  var states = Object.values(Transparent.state);
1690
1705
  var htmlClass = Array.from(($("html").attr("class") || "").split(" ")).filter(x => !states.includes(x));
1691
1706
  Transparent.html.removeClass(states).addClass(htmlClass.join(" ")+" "+Transparent.state.ROOT+" "+Transparent.state.READY+" "+Transparent.state.DISABLE);
1692
1707
 
1693
1708
  } else {
1694
1709
 
1710
+ if(Settings.debug) console.debug("Transparent is running..");
1711
+
1695
1712
  window.onpopstate = __main__; // Onpopstate pop out straight to previous page.. this creates a jump while changing pages with hash..
1696
1713
  window.onhashchange = __main__;
1697
1714
 
@@ -1708,13 +1725,16 @@
1708
1725
  if(this.type == "file") {
1709
1726
 
1710
1727
  for(var i = 0; i < this.files.length; i++)
1711
- formData.append(this.name, field.files[i]);
1728
+ formData.append(this.name+"["+i+"]", this.files[i].name+";"+this.files[i].size+";"+this.files[i].lastModified);
1712
1729
 
1713
1730
  } else formData.append(this.name, this.value);
1714
1731
  });
1715
1732
 
1716
- for (var [fieldName,fieldValue] of formData.entries())
1717
- formDataBefore[fieldName] = fieldValue;
1733
+ for (var [fieldName,fieldValue] of formData.entries()) {
1734
+
1735
+ if(!fieldName.endsWith("[]") && fieldName != "undefined")
1736
+ formDataBefore[fieldName] = fieldValue;
1737
+ }
1718
1738
  });
1719
1739
  });
1720
1740
 
@@ -1734,20 +1754,31 @@
1734
1754
  if(this.type == "file") {
1735
1755
 
1736
1756
  for(var i = 0; i < this.files.length; i++)
1737
- formData.append(this.name, field.files[i]);
1757
+ formData.append(this.name+"["+i+"]", this.files[i].name+";"+this.files[i].size+";"+this.files[i].lastModified);
1738
1758
 
1739
1759
  } else formData.append(this.name, this.value);
1740
1760
  });
1741
1761
 
1742
1762
  for (var [fieldName,fieldValue] of formData.entries()) {
1743
- formDataAfter[fieldName] = fieldValue;
1763
+
1764
+ if(!fieldName.endsWith("[]") && fieldName != "undefined")
1765
+ formDataAfter[fieldName] = fieldValue;
1744
1766
  }
1745
1767
  });
1746
1768
 
1747
- var formDataBeforeKeys = Object.entries(formDataBefore).keys();
1748
- var formDataAfterKeys = Object.entries(formDataAfter).keys();
1769
+ var formDataBeforeKeys = Object.keys(formDataBefore);
1770
+ var formDataAfterKeys = Object.keys(formDataAfter);
1771
+ var formDataBeforeEntries = Object.entries(formDataBefore);
1772
+ var formDataAfterEntries = Object.entries(formDataAfter);
1773
+ function compare(a, b) { return JSON.stringify(a) === JSON.stringify(b); }
1774
+ function compareKeys(a, b) {
1775
+
1776
+ var aKeys = Object.keys(a).sort();
1777
+ var bKeys = Object.keys(b).sort();
1778
+ return JSON.stringify(aKeys) === JSON.stringify(bKeys);
1779
+ }
1749
1780
 
1750
- if(formDataAfterKeys != formDataAfterKeys) preventDefault = true;
1781
+ if(!compareKeys(formDataBeforeKeys, formDataAfterKeys)) preventDefault = true;
1751
1782
  else {
1752
1783
 
1753
1784
  for (var [fieldName,fieldValueAfter] of Object.entries(formDataAfter)) {