@glitchr/transparent 1.0.65 → 1.0.66

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.65",
3
+ "version": "1.0.66",
4
4
  "description": "Transparent SPA Application",
5
5
  "main": "src/index.js",
6
6
  "access": "public",
@@ -182,7 +182,48 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
182
182
  "smoothscroll_duration": "200ms",
183
183
  "smoothscroll_speed" : 0,
184
184
  "smoothscroll_easing" : "swing",
185
- "exceptions": []
185
+ "exceptions": [],
186
+ // headlock: list of url substrings/regex to preserve in <head> across page transitions
187
+ // (e.g. third-party widgets like Brevo that inject <style>/<link> dynamically).
188
+ // In addition, head nodes injected dynamically AFTER initial DOMContentLoaded are
189
+ // preserved automatically. Use data-headlock="false" on a head element to opt-out.
190
+ "headlock": []
191
+ };
192
+
193
+ // Set of <head> children present on initial load. Anything added after is treated
194
+ // as dynamically injected (e.g. Brevo widget) and preserved across transitions.
195
+ var originalHeadNodes = new WeakSet();
196
+ function snapshotHeadNodes() {
197
+ var head = document.head;
198
+ if(!head) return;
199
+ for(var i = 0; i < head.children.length; i++)
200
+ originalHeadNodes.add(head.children[i]);
201
+ }
202
+ if(document.readyState === "loading")
203
+ document.addEventListener("DOMContentLoaded", snapshotHeadNodes, { once: true });
204
+ else
205
+ snapshotHeadNodes();
206
+
207
+ Transparent.isHeadlocked = function(el) {
208
+ if(!el || el.nodeType !== 1) return false;
209
+ // Explicit opt-out
210
+ var attr = el.getAttribute && el.getAttribute("data-headlock");
211
+ if(attr === "false") return false;
212
+ // Explicit opt-in via attribute
213
+ if(attr !== null && attr !== undefined) return true;
214
+ // Dynamically injected after initial load
215
+ if(!originalHeadNodes.has(el)) return true;
216
+ // URL pattern match
217
+ var patterns = Settings["headlock"] || [];
218
+ if(!patterns.length) return false;
219
+ var url = el.getAttribute && (el.getAttribute("src") || el.getAttribute("href"));
220
+ if(!url) return false;
221
+ for(var i = 0; i < patterns.length; i++) {
222
+ var p = patterns[i];
223
+ if(p instanceof RegExp) { if(p.test(url)) return true; }
224
+ else if(typeof p === "string" && p.length && url.indexOf(p) !== -1) return true;
225
+ }
226
+ return false;
186
227
  };
187
228
 
188
229
  const State = Transparent.state = {
@@ -282,37 +323,6 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
282
323
  }
283
324
 
284
325
  Transparent.setResponse = function(uuid, responseText, scrollableXY = [], exceptionRaised = false)
285
- {
286
- if(isDomEntity(responseText))
287
- responseText = responseText.outerHTML;
288
-
289
- var array = JSON.parse(sessionStorage.getItem('transparent')) || [];
290
- array.push(uuid);
291
-
292
- while(array.length > Settings["response_limit"])
293
- sessionStorage.removeItem('transparent['+array.shift()+']');
294
-
295
- try {
296
-
297
- if(isLocalStorageNameSupported()) {
298
-
299
- sessionStorage.setItem('transparent', JSON.stringify(array));
300
- sessionStorage.setItem('transparent[response]['+uuid+']', responseText);
301
- sessionStorage.setItem('transparent[position]['+uuid+']', JSON.stringify(scrollableXY));
302
- }
303
-
304
- } catch(e) {
305
-
306
- if (e.name === 'QuotaExceededError')
307
- sessionStorage.clear();
308
-
309
- return exceptionRaised === false ? Transparent.setResponse(uuid, responseText, scrollableXY, true) : this;
310
- }
311
-
312
- return this;
313
- }
314
-
315
- Transparent.setResponse = function(uuid, responseText, scrollableXY, exceptionRaised = false)
316
326
  {
317
327
  if(isDomEntity(responseText))
318
328
  responseText = responseText.outerHTML;
@@ -943,7 +953,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
943
953
  var head = $(dom).find("head").html();
944
954
  var body = $(dom).find("body").html();
945
955
 
946
- if(head == undefined || body == "undefined") {
956
+ if(head == undefined || body == undefined) {
947
957
 
948
958
  $(Settings.identifier).html("<div class='error'></div>");
949
959
 
@@ -1245,6 +1255,9 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
1245
1255
  return !found;
1246
1256
  });
1247
1257
 
1258
+ // Preserve headlocked nodes (dynamically injected widgets, url-matched, etc.)
1259
+ if(!found && Transparent.isHeadlocked(el)) found = true;
1260
+
1248
1261
  if(!found) this.remove();
1249
1262
  });
1250
1263
 
@@ -1481,7 +1494,7 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
1481
1494
  return;
1482
1495
  }
1483
1496
 
1484
- dispatchEvent(new CustomEvent('transparent:link', {link:link}));
1497
+ dispatchEvent(new CustomEvent('transparent:link', {detail: {link: link}}));
1485
1498
 
1486
1499
  const uuid = uuidv4();
1487
1500
  const type = link[0];