@glitchr/transparent 1.0.33 → 1.0.35

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.33",
3
+ "version": "1.0.35",
4
4
  "description": "Transparent SPA Application",
5
5
  "main": "src/index.js",
6
6
  "access": "public",
@@ -910,7 +910,6 @@
910
910
  var head = $(dom).find("head").html();
911
911
  var body = $(dom).find("body").html();
912
912
 
913
- console.log(head, body);
914
913
  if(head == undefined || body == "undefined") {
915
914
 
916
915
  $(Settings.identifier).html("<div class='error'></div>");
@@ -1180,125 +1179,139 @@
1180
1179
  window.previousLocation = window.location.toString();
1181
1180
  if(callback === null) callback = function() {};
1182
1181
 
1183
- // Transfert attributes
1184
- Transparent.transferAttributes(dom);
1182
+ activeInRemainingTime = activeInRemainingTime - (Date.now() - activeInTime);
1183
+ setTimeout(function() {
1185
1184
 
1186
- // Replace head..
1187
- var head = $(dom).find("head");
1188
- $("head").children().each(function() {
1185
+ // Transfert attributes
1186
+ Transparent.transferAttributes(dom);
1189
1187
 
1190
- var el = this;
1191
- var found = false;
1188
+ // Replace head..
1189
+ var head = $(dom).find("head");
1190
+ $("head").children().each(function() {
1192
1191
 
1193
- head.children().each(function() {
1192
+ var el = this;
1193
+ var found = false;
1194
1194
 
1195
- found = this.isEqualNode(el);
1196
- return !found;
1195
+ head.children().each(function() {
1196
+
1197
+ found = this.isEqualNode(el);
1198
+ return !found;
1199
+ });
1200
+
1201
+ if(!found) this.remove();
1197
1202
  });
1198
1203
 
1199
- if(!found) this.remove();
1200
- });
1204
+ head.children().each(function() {
1201
1205
 
1202
- head.children().each(function() {
1206
+ var el = this;
1207
+ var found = false;
1203
1208
 
1204
- var el = this;
1205
- var found = false;
1209
+ $("head").children().each(function() { found |= this.isEqualNode(el); });
1210
+ if(!found) {
1211
+
1212
+
1213
+ if(this.tagName != "SCRIPT" || Settings["global_code"] == true) {
1214
+
1215
+ $("head").append(this.cloneNode(true));
1216
+
1217
+ } else {
1206
1218
 
1207
- $("head").children().each(function() { found |= this.isEqualNode(el); });
1208
- if(!found) {
1219
+ $("head").append(this);
1220
+ }
1221
+ }
1222
+ });
1209
1223
 
1210
- if(this.tagName != "SCRIPT" || Settings["global_code"] == true) $("head").append(this.cloneNode(true));
1211
- else $("head").append(this);
1212
- }
1213
- });
1224
+ var bodyScript = $(dom).find("body > script");
1225
+ bodyScript.each(function() {
1214
1226
 
1215
- var bodyScript = $(dom).find("body > script");
1216
- bodyScript.each(function() {
1227
+ var el = this;
1228
+ var found = false;
1217
1229
 
1218
- var el = this;
1219
- var found = false;
1230
+ $("body").children().each(function() { found |= this.isEqualNode(el); });
1231
+ if(!found) {
1220
1232
 
1221
- $("body").children().each(function() { found |= this.isEqualNode(el); });
1222
- if(!found) $("body").append(this);
1223
- });
1233
+ if(this.tagName != "SCRIPT" || Settings["global_code"] == true) {
1234
+ $("body").append(this.cloneNode(true));
1235
+ } else {
1236
+ $("body").append(this);
1237
+ }
1238
+ }
1239
+ });
1224
1240
 
1225
- // Replace canvases..
1226
- Transparent.replaceCanvases(dom);
1241
+ // Replace canvases..
1242
+ Transparent.replaceCanvases(dom);
1227
1243
 
1228
- // Extract page block to be loaded
1229
- var page = $(dom).find(Settings.identifier);
1230
- if(dom == undefined || page == undefined) window.reload(); // Error a posteriori
1244
+ // Extract page block to be loaded
1245
+ var page = $(dom).find(Settings.identifier);
1246
+ if(dom == undefined || page == undefined) window.reload(); // Error a posteriori
1231
1247
 
1232
- var oldPage = $(Settings.identifier);
1248
+ var oldPage = $(Settings.identifier);
1233
1249
 
1234
- // Make sure name/layout keep the same after a page change (tolerance for POST or GET requests)
1235
- if(oldPage.attr("data-layout") != undefined && page.attr("data-layout") != undefined) {
1250
+ // Make sure name/layout keep the same after a page change (tolerance for POST or GET requests)
1251
+ if(oldPage.attr("data-layout") != undefined && page.attr("data-layout") != undefined) {
1236
1252
 
1237
- var switchLayout = Transparent.state.SWITCH.replace("X", page.attr("data-layout")).replace("Y", oldPage.attr("data-layout"));
1238
- page.attr("data-layout-prev", oldPage.attr("data-layout"));
1239
- }
1253
+ var switchLayout = Transparent.state.SWITCH.replace("X", page.attr("data-layout")).replace("Y", oldPage.attr("data-layout"));
1254
+ page.attr("data-layout-prev", oldPage.attr("data-layout"));
1255
+ }
1240
1256
 
1241
- var states = Object.values(Transparent.state);
1242
- var htmlClass = Array.from(($(dom).find("html").attr("class") || "").split(" ")).filter(x => !states.includes(x));
1243
- var oldHtmlClass = Array.from(($(Transparent.html).attr("class") || "").split(" "));
1244
- var removeHtmlClass = oldHtmlClass.filter(x => !htmlClass.includes(x) && switchLayout != x && !states.includes(x));
1257
+ var states = Object.values(Transparent.state);
1258
+ var htmlClass = Array.from(($(dom).find("html").attr("class") || "").split(" ")).filter(x => !states.includes(x));
1259
+ var oldHtmlClass = Array.from(($(Transparent.html).attr("class") || "").split(" "));
1260
+ var removeHtmlClass = oldHtmlClass.filter(x => !htmlClass.includes(x) && switchLayout != x && !states.includes(x));
1245
1261
 
1246
- Transparent.html.removeClass(removeHtmlClass).addClass(htmlClass);
1247
- $(page).insertBefore(oldPage);
1262
+ Transparent.html.removeClass(removeHtmlClass).addClass(htmlClass);
1263
+ $(page).insertBefore(oldPage);
1248
1264
 
1249
- oldPage.remove();
1265
+ oldPage.remove();
1250
1266
 
1251
- if(Settings["global_code"] == true) Transparent.evalScript($(page)[0]);
1252
- document.dispatchEvent(new Event('DOMContentLoaded'));
1253
- window.dispatchEvent(new Event('DOMContentLoaded'));
1267
+ if(Settings["global_code"] == true) Transparent.evalScript($(page)[0]);
1268
+ document.dispatchEvent(new Event('DOMContentLoaded'));
1269
+ window.dispatchEvent(new Event('DOMContentLoaded'));
1254
1270
 
1255
- Transparent.addLayout();
1271
+ Transparent.addLayout();
1256
1272
 
1257
- if(scrollTo) {
1273
+ if(scrollTo) {
1258
1274
 
1259
- // Go back to top of the page..
1260
- var scrollableElements = Transparent.getScrollableElement();
1261
- var scrollableElementsXY = Transparent.getResponsePosition(uuid);
1275
+ // Go back to top of the page..
1276
+ var scrollableElements = Transparent.getScrollableElement();
1277
+ var scrollableElementsXY = Transparent.getResponsePosition(uuid);
1262
1278
 
1263
- for(i = 0; i < scrollableElements.length; i++) {
1279
+ for(i = 0; i < scrollableElements.length; i++) {
1264
1280
 
1265
- var el = scrollableElements[i];
1266
- var positionXY = undefined;
1281
+ var el = scrollableElements[i];
1282
+ var positionXY = undefined;
1267
1283
 
1268
- if(scrollableElementsXY.length == scrollableElements.length)
1269
- positionXY = scrollableElementsXY[i] || undefined;
1284
+ if(scrollableElementsXY.length == scrollableElements.length)
1285
+ positionXY = scrollableElementsXY[i] || undefined;
1270
1286
 
1271
- if(el == window || el == document.documentElement) {
1287
+ if(el == window || el == document.documentElement) {
1272
1288
 
1273
- if(positionXY != undefined) Transparent.scrollTo({top:positionXY[0], left:positionXY[1], duration:0});
1274
- else if (location.hash) Transparent.scrollToHash(location.hash, {duration:0});
1275
- else Transparent.scrollTo({top:0, left:0, duration:0});
1289
+ if(positionXY != undefined) Transparent.scrollTo({top:positionXY[0], left:positionXY[1], duration:0});
1290
+ else if (location.hash) Transparent.scrollToHash(location.hash, {duration:0});
1291
+ else Transparent.scrollTo({top:0, left:0, duration:0});
1276
1292
 
1277
- } else {
1293
+ } else {
1278
1294
 
1279
- if(positionXY != undefined) Transparent.scrollTo({top:positionXY[0], left:positionXY[1], duration:0}, el);
1280
- else Transparent.scrollTo({top:0, left:0, duration:0}, el);
1295
+ if(positionXY != undefined) Transparent.scrollTo({top:positionXY[0], left:positionXY[1], duration:0}, el);
1296
+ else Transparent.scrollTo({top:0, left:0, duration:0}, el);
1297
+ }
1281
1298
  }
1282
1299
  }
1283
- }
1284
-
1285
- $('head').append(function() {
1286
1300
 
1287
- $(Settings.identifier).append(function() {
1301
+ $('head').append(function() {
1288
1302
 
1289
- activeInRemainingTime = activeInRemainingTime - (Date.now() - activeInTime);
1290
- setTimeout(function() {
1303
+ $(Settings.identifier).append(function() {
1291
1304
 
1292
- // Callback if needed, or any other actions
1293
- callback();
1294
-
1295
- // Trigger onload event
1296
- dispatchEvent(new Event('transparent:load'));
1297
- dispatchEvent(new Event('load'));
1305
+ // Callback if needed, or any other actions
1306
+ callback();
1298
1307
 
1299
- }.bind(this), activeInRemainingTime > 0 ? activeInRemainingTime : 1);
1308
+ // Trigger onload event
1309
+ dispatchEvent(new Event('transparent:load'));
1310
+ dispatchEvent(new Event('load'));
1311
+ });
1300
1312
  });
1301
- });
1313
+
1314
+ }.bind(this), activeInRemainingTime > 0 ? activeInRemainingTime : 1);
1302
1315
  }
1303
1316
 
1304
1317
  function uuidv4() {