@glitchr/transparent 1.0.39 → 1.0.41

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.39",
3
+ "version": "1.0.41",
4
4
  "description": "Transparent SPA Application",
5
5
  "main": "src/index.js",
6
6
  "access": "public",
@@ -12,23 +12,23 @@
12
12
 
13
13
  window.replaceHash = function(newHash, triggerHashChange = true, skipIfEmptyIdentifier = true) {
14
14
 
15
+ var oldHash = location.hash;
16
+ var oldURL = location.origin+location.pathname+location.hash;
17
+ var oldHashElement = $(oldHash);
18
+
15
19
  if(!newHash) newHash = "";
16
20
  if (newHash !== "" && (''+newHash).charAt(0) !== '#')
17
21
  newHash = '#' + newHash;
18
-
19
- var oldURL = location.origin+location.pathname+location.hash;
20
22
  var newURL = location.origin+location.pathname+newHash;
23
+ var newHashElement = $(newHash);
21
24
 
22
25
  var fallback = $(newHash).length === 0;
23
-
24
- var hashElement = $(newHash)[0] ?? undefined;
25
- // if (hashElement !== undefined) // Update hash only if element is displayed
26
- // fallback |= window.getComputedStyle(hashElement)["display"] == "none";
26
+ fallback |= newHashElement.has(oldHashElement).length > 0;
27
27
 
28
28
  if((skipIfEmptyIdentifier && !newHash) || fallback){
29
29
 
30
30
  dispatchEvent(new HashChangeEvent("hashfallback", {oldURL:oldURL, newURL:newURL}));
31
- newHash = "";
31
+ newHash = skipIfEmptyIdentifier && !newHash ? "" : (newHashElement.length == 0 ? "" : oldHash);
32
32
 
33
33
  oldURL = location.origin+location.pathname+location.hash;
34
34
  newURL = location.origin+location.pathname+newHash;
@@ -1208,12 +1208,12 @@
1208
1208
 
1209
1209
  $("head").children().each(function() { found |= this.isEqualNode(el); });
1210
1210
  if(!found) {
1211
-
1212
-
1211
+
1212
+
1213
1213
  if(this.tagName != "SCRIPT" || Settings["global_code"] == true) {
1214
-
1214
+
1215
1215
  $("head").append(this.cloneNode(true));
1216
-
1216
+
1217
1217
  } else {
1218
1218
 
1219
1219
  $("head").append(this);
@@ -1569,21 +1569,21 @@
1569
1569
  }
1570
1570
 
1571
1571
  // Invalid html page returned
1572
- if(!responseText.includes("<html>") || !responseText.includes("<body>") || !responseText.includes("<head>"))
1572
+ if(!responseText.includes("<html") || !responseText.includes("<body") || !responseText.includes("<head"))
1573
1573
  return Transparent.rescue(dom);
1574
1574
 
1575
- if(status >= 400) // Blatant error received..
1575
+ if(status != 200) // Blatant error received..
1576
1576
  return Transparent.rescue(dom);
1577
1577
 
1578
- // Page not recognized.. just go fetch by yourself.. no POST information transmitted..
1579
- if(!Transparent.isPage(dom))
1580
- return window.location.href = url;
1581
-
1582
1578
  // From here the page is valid..
1583
1579
  // so the new page is added to history..
1584
1580
  if(xhr)
1585
1581
  history.pushState({uuid: uuid, status:status, method: method, data: {}, href: responseURL}, '', responseURL);
1586
1582
 
1583
+ // Page not recognized.. just go fetch by yourself.. no POST information transmitted..
1584
+ if(!Transparent.isPage(dom))
1585
+ return window.location.href = url;
1586
+
1587
1587
  // Layout not compatible.. needs to be reloaded (exception when POST is detected..)
1588
1588
  if(!Transparent.isCompatiblePage(dom, method, data))
1589
1589
  return window.location.href = url;
@@ -1708,7 +1708,7 @@
1708
1708
 
1709
1709
  window.onbeforeunload = function() {
1710
1710
 
1711
- if(Transparent.get("disable")) return;
1711
+ if(Settings.disable) return;
1712
1712
 
1713
1713
  var preventDefault = false;
1714
1714
  var formDataAfter = [];