@glitchr/transparent 1.0.60 → 1.0.63

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.60",
3
+ "version": "1.0.63",
4
4
  "description": "Transparent SPA Application",
5
5
  "main": "src/index.js",
6
6
  "access": "public",
@@ -578,7 +578,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
578
578
  }
579
579
  }
580
580
 
581
- closestEl = $(el).closest("a");
581
+ var closestEl = $(el).closest("a");
582
582
  if(!closestEl.length) closestEl = $(el).closest("button");
583
583
  if(!closestEl.length) closestEl = $(el).closest("input");
584
584
  if (closestEl.length) el = closestEl[0];
@@ -893,7 +893,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
893
893
  } else {
894
894
 
895
895
  if(dom === undefined)
896
- console.alert("Response missing..");
896
+ console.error("Response missing..");
897
897
 
898
898
  var parent = Transparent.findElementFromParents(dom, $(this).parents(), 3);
899
899
  if (parent === undefined) {
@@ -977,19 +977,19 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
977
977
  var maxScrollY = $(el).prop("scrollHeight") - Math.round($(el).prop("clientHeight"));
978
978
  if (maxScrollY == 0) maxScrollY = Math.round($(el).prop("clientHeight"));
979
979
 
980
- scrollTop = Math.max(0, Math.min(dict["top"] ?? $(el).prop("scrollTop"), maxScrollY));
981
- scrollLeft = Math.max(0, Math.min(dict["left"] ?? $(el).prop("scrollLeft"), maxScrollX));
980
+ var scrollTop = Math.max(0, Math.min(dict["top"] ?? $(el).prop("scrollTop"), maxScrollY));
981
+ var scrollLeft = Math.max(0, Math.min(dict["left"] ?? $(el).prop("scrollLeft"), maxScrollX));
982
982
 
983
- speed = parseFloat(dict["speed"] ?? 0);
984
- easing = dict["easing"] ?? "swing";
985
- debounce = dict["debounce"] ?? 0;
983
+ var speed = parseFloat(dict["speed"] ?? 0);
984
+ var easing = dict["easing"] ?? "swing";
985
+ var debounce = dict["debounce"] ?? 0;
986
986
 
987
- duration = 1000*Transparent.parseDuration(dict["duration"] ?? 0);
988
- durationX = 1000*Transparent.parseDuration(dict["duration-x"] ?? dict["duration"] ?? 0);
989
- durationY = 1000*Transparent.parseDuration(dict["duration-y"] ?? dict["duration"] ?? 0);
987
+ var duration = 1000*Transparent.parseDuration(dict["duration"] ?? 0);
988
+ var durationX = 1000*Transparent.parseDuration(dict["duration-x"] ?? dict["duration"] ?? 0);
989
+ var durationY = 1000*Transparent.parseDuration(dict["duration-y"] ?? dict["duration"] ?? 0);
990
990
 
991
991
  if(speed) {
992
-
992
+
993
993
  var currentScrollX = $(el)[0].scrollLeft;
994
994
  if(currentScrollX < scrollLeft || scrollLeft == 0) // Going to the right
995
995
  distanceX = Math.abs(scrollLeft - currentScrollX);
@@ -1322,7 +1322,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
1322
1322
  var scrollableElements = Transparent.getScrollableElement();
1323
1323
  var scrollableElementsXY = Transparent.getResponsePosition(uuid);
1324
1324
 
1325
- for(i = 0; i < scrollableElements.length; i++) {
1325
+ for(var i = 0; i < scrollableElements.length; i++) {
1326
1326
 
1327
1327
  var el = scrollableElements[i];
1328
1328
  var positionXY = undefined;
@@ -1460,7 +1460,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
1460
1460
  var elementsXY = [];
1461
1461
  var elements = Transparent.getScrollableElement();
1462
1462
 
1463
- for(i = 0; i < elements.length; i++)
1463
+ for(var i = 0; i < elements.length; i++)
1464
1464
  elementsXY.push([$(elements[i]).scrollTop(), $(elements[i]).scrollLeft()]);
1465
1465
 
1466
1466
  return elementsXY;
@@ -1492,8 +1492,10 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
1492
1492
  // Wait for transparent window event to be triggered
1493
1493
  if (!isReady) return;
1494
1494
 
1495
- if (e.type != Transparent.state.POPSTATE &&
1496
- e.type != Transparent.state.HASHCHANGE && !$(this).find(Settings.identifier).length) return;
1495
+ const $ctx = (e.type === Transparent.state.SUBMIT) ? $(document) : $(this);
1496
+ if (e.type !== Transparent.state.POPSTATE &&
1497
+ e.type !== Transparent.state.HASHCHANGE &&
1498
+ !$ctx.find(Settings.identifier).length) return;
1497
1499
 
1498
1500
  var form = target != undefined && target.tagName == "FORM" ? target : undefined;
1499
1501
  var formTrigger = undefined;
@@ -1593,35 +1595,34 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
1593
1595
  catch (e) { return false; }
1594
1596
  }
1595
1597
 
1596
- function handleResponse(uuid, status = 200, method = null, data = null, xhr = null, request = null) {
1598
+ function handleResponse(uuid, status = 200, method = null, data = null, responseURL = null, contentType = null, fetchedResponseText = null) {
1597
1599
 
1598
1600
  ajaxSemaphore = false;
1599
-
1600
- var responseURL;
1601
- responseURL = xhr !== null ? xhr.responseURL : url.href;
1602
1601
 
1603
- responseText = Transparent.getResponseText(uuid);
1602
+ responseURL = responseURL ?? url.href;
1603
+
1604
+ var responseText = Transparent.getResponseText(uuid);
1604
1605
 
1605
- var fragmentPos = responseURL.indexOf("#");
1606
- var strippedResponseUrl = (fragmentPos < 0 ? responseURL : responseURL.substring(0, fragmentPos)).trimEnd("/");
1606
+ const fragmentPosResp = responseURL.indexOf("#");
1607
+ var strippedResponseUrl = (fragmentPosResp < 0 ? responseURL : responseURL.substring(0, fragmentPosResp)).trimEnd("/");
1607
1608
 
1608
- var fragmentPos = url.href.indexOf("#");
1609
- var strippedUrlHref = (fragmentPos < 0 ? url.href : url.href.substring(0, fragmentPos)).trimEnd("/");
1609
+ const fragmentPosReq = url.href.indexOf("#");
1610
+ var strippedUrlHref = (fragmentPosReq < 0 ? url.href : url.href.substring(0, fragmentPosReq)).trimEnd("/");
1610
1611
  if( strippedUrlHref == strippedResponseUrl )
1611
- responseURL = url.href; // NB: xhr.responseURL strips away #fragments
1612
+ responseURL = url.href; // NB: fetch response.url strips away #fragments
1612
1613
 
1613
1614
  if(!responseText) {
1614
1615
 
1615
- if(!request && responseText === null) {
1616
+ if(!fetchedResponseText && responseText === null) {
1616
1617
 
1617
1618
  setTimeout(function() { window.location.href = responseURL; }, Settings["throttle"]);
1618
1619
  return;
1619
1620
  }
1620
1621
 
1621
- responseText = request.responseText;
1622
+ responseText = fetchedResponseText;
1622
1623
  if(status >= 500) {
1623
1624
 
1624
- console.error("Unexpected XHR response from "+uuid+": error code "+request.status);
1625
+ console.error("Unexpected response from "+uuid+": error code "+status);
1625
1626
  console.error(sessionStorage);
1626
1627
  }
1627
1628
 
@@ -1630,7 +1631,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
1630
1631
  }
1631
1632
 
1632
1633
  var dom = new DOMParser().parseFromString(responseText, "text/html");
1633
- if(request && request.getResponseHeader("Content-Type") == "application/json") {
1634
+ if(contentType && contentType.includes("application/json")) {
1634
1635
 
1635
1636
  if(!isJsonResponse(responseText)) {
1636
1637
  console.error("Invalid response received for "+ responseURL);
@@ -1656,7 +1657,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
1656
1657
  }
1657
1658
 
1658
1659
  // Invalid html page returned
1659
- if(request && request.getResponseHeader("Content-Type") == "text/html") {
1660
+ if(contentType && contentType.includes("text/html")) {
1660
1661
 
1661
1662
  if (!responseText.includes("<html") && !responseText.includes("<body") && !responseText.includes("<head"))
1662
1663
  return Transparent.rescue(dom);
@@ -1675,7 +1676,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
1675
1676
 
1676
1677
  // From here the page is valid..
1677
1678
  // so the new page is added to history..
1678
- if(xhr)
1679
+ if(fetchedResponseText !== null)
1679
1680
  history.pushState({uuid: uuid, status:status, method: method, data: {}, href: responseURL}, '', responseURL);
1680
1681
 
1681
1682
  // Page not recognized.. just go fetch by yourself.. no POST information transmitted..
@@ -1747,20 +1748,20 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
1747
1748
  $(Transparent.html).prop("user-scroll", false); // make sure to avoid page jump during transition (cancelled in activeIn callback)
1748
1749
 
1749
1750
  // Submit ajax request..
1751
+ ajaxSemaphore = true; // Raise before dispatching synthetic submit to prevent double-submission
1750
1752
  if(form) form.dispatchEvent(new SubmitEvent("submit", { submitter: formTrigger }));
1751
- var xhr = new XMLHttpRequest();
1752
-
1753
- ajaxSemaphore = true;
1754
- return jQuery.ajax({
1755
- url: url.href,
1756
- type: type,
1757
- data: data,
1758
- contentType: false,
1759
- processData: false,
1760
- headers: Settings["headers"] || {},
1761
- xhr: function () { return xhr; },
1762
- success: function (html, status, request) { return handleResponse(uuid, request.status, type, data, xhr, request); },
1763
- error: function (request, ajaxOptions, thrownError) { return handleResponse(uuid, request.status, type, data, xhr, request); }
1753
+
1754
+ return fetch(url.href, {
1755
+ method: type,
1756
+ body: type === "GET" ? undefined : data,
1757
+ headers: Settings["headers"] || {}
1758
+ })
1759
+ .then(async (response) => {
1760
+ const responseText = await response.text();
1761
+ return handleResponse(uuid, response.status, type, data, response.url, response.headers.get("Content-Type"), responseText);
1762
+ })
1763
+ .catch(() => {
1764
+ handleResponse(uuid, 500, type, data, url.href, null, null);
1764
1765
  });
1765
1766
  }
1766
1767
 
@@ -1780,8 +1781,8 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
1780
1781
 
1781
1782
  if(Settings.debug) console.debug("Transparent is disabled..");
1782
1783
 
1783
- var states = Object.values(Transparent.state);
1784
- var htmlClass = Array.from(($("html").attr("class") || "").split(" ")).filter(x => !states.includes(x));
1784
+ const statesSet = new Set(Object.values(Transparent.state));
1785
+ const htmlClass = ($("html").attr("class") || "").split(" ").filter(x => !statesSet.has(x));
1785
1786
  Transparent.html.removeClass(states).addClass(htmlClass.join(" ")+" "+Transparent.state.ROOT+" "+Transparent.state.READY+" "+Transparent.state.DISABLE);
1786
1787
 
1787
1788
  } else {
@@ -1867,7 +1868,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
1867
1868
  var fieldValueBefore = formDataBefore[fieldName];
1868
1869
  if(fieldValueBefore instanceof File) {
1869
1870
 
1870
- if(!fieldValueAfter instanceof File) preventDefault = true;
1871
+ if(!(fieldValueAfter instanceof File)) preventDefault = true;
1871
1872
  else if (fieldValueBefore.size != fieldValueAfter.size) preventDefault = true;
1872
1873
 
1873
1874
  } else if(fieldValueBefore != fieldValueAfter) {
@@ -1888,7 +1889,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
1888
1889
 
1889
1890
  document.addEventListener('click', __main__, false);
1890
1891
 
1891
- $("form").on("submit", __main__);
1892
+ $(document).on("submit", "form", __main__);
1892
1893
  }
1893
1894
 
1894
1895