@lmjs/core 2.1.24 → 2.2.1

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/src/dom-shim.js CHANGED
@@ -21,8 +21,74 @@
21
21
  return [x];
22
22
  }
23
23
 
24
+ // jQuery-only selector extensions real V1 code uses (native
25
+ // querySelectorAll throws on these): the positional :first/:last/
26
+ // :eq(n)/:gt(n)/:lt(n)/:even/:odd filter the set matched so far; the
27
+ // type/state ones map onto real CSS.
28
+ var JQ_POSITIONAL = /:(first|last|even|odd|eq\((-?\d+)\)|gt\((-?\d+)\)|lt\((-?\d+)\))(?![-\w])/;
29
+ var JQ_REWRITES = [
30
+ [/:checkbox(?![-\w])/g, '[type="checkbox"]'], [/:radio(?![-\w])/g, '[type="radio"]'],
31
+ [/:selected(?![-\w])/g, ':checked'], [/:password(?![-\w])/g, '[type="password"]'],
32
+ [/:text(?![-\w])/g, '[type="text"]'], [/:submit(?![-\w])/g, '[type="submit"]'],
33
+ [/:file(?![-\w])/g, '[type="file"]'], [/:button(?![-\w])/g, 'button'],
34
+ ];
35
+ function _splitTopLevel(sel, ch) {
36
+ var out = [], depth = 0, quote = null, cur = '';
37
+ for (var i = 0; i < sel.length; i++) {
38
+ var c = sel[i];
39
+ if (quote) { if (c === quote) quote = null; cur += c; continue; }
40
+ if (c === '"' || c === "'") { quote = c; cur += c; continue; }
41
+ if (c === '(' || c === '[') depth++;
42
+ else if (c === ')' || c === ']') depth--;
43
+ if (c === ch && depth === 0) { out.push(cur); cur = ''; continue; }
44
+ cur += c;
45
+ }
46
+ out.push(cur);
47
+ return out;
48
+ }
49
+ function _applyPositional(els, m) {
50
+ var n = els.length;
51
+ if (m[1] === 'first') return els.slice(0, 1);
52
+ if (m[1] === 'last') return n ? els.slice(n - 1) : [];
53
+ if (m[1] === 'even') return els.filter(function (_, i) { return i % 2 === 0; });
54
+ if (m[1] === 'odd') return els.filter(function (_, i) { return i % 2 === 1; });
55
+ if (m[2] !== undefined) { var i = +m[2]; if (i < 0) i += n; return els[i] ? [els[i]] : []; }
56
+ if (m[3] !== undefined) { var g = +m[3]; if (g < 0) g += n; return els.slice(g + 1); }
57
+ var l = +m[4]; if (l < 0) l += n; return els.slice(0, Math.max(0, l));
58
+ }
59
+ function _jqSelect(root, selector) {
60
+ var sel = selector;
61
+ for (var r = 0; r < JQ_REWRITES.length; r++) sel = sel.replace(JQ_REWRITES[r][0], JQ_REWRITES[r][1]);
62
+ if (!JQ_POSITIONAL.test(sel)) return toArray(root.querySelectorAll(sel));
63
+ var out = [];
64
+ _splitTopLevel(sel, ',').forEach(function (part) {
65
+ var rest = part.trim(), current = null;
66
+ while (rest.length) {
67
+ var m = JQ_POSITIONAL.exec(rest);
68
+ var css = m ? rest.slice(0, m.index) : rest;
69
+ if (css.trim()) {
70
+ if (current === null) current = toArray(root.querySelectorAll(css));
71
+ else {
72
+ var next = [];
73
+ var scoped = /^\s*[>+~]/.test(css) ? ':scope' + css : ':scope ' + css.replace(/^\s+/, '');
74
+ current.forEach(function (el) {
75
+ toArray(el.querySelectorAll(scoped)).forEach(function (x) { if (next.indexOf(x) === -1) next.push(x); });
76
+ });
77
+ current = next;
78
+ }
79
+ } else if (current === null) current = toArray(root.querySelectorAll('*'));
80
+ if (!m) break;
81
+ current = _applyPositional(current, m);
82
+ rest = rest.slice(m.index + m[0].length);
83
+ }
84
+ (current || []).forEach(function (x) { if (out.indexOf(x) === -1) out.push(x); });
85
+ });
86
+ return out;
87
+ }
88
+
24
89
  function $(selector, context) {
25
90
  if (!(this instanceof $)) return new $(selector, context);
91
+ if (typeof selector === 'function') return $(document).ready(selector);
26
92
 
27
93
  var els = [];
28
94
  var sel = undefined;
@@ -66,7 +132,7 @@
66
132
  return names.some(function (n) { return el.getAttribute(n) != null; });
67
133
  });
68
134
  } else {
69
- els = root ? toArray(root.querySelectorAll(selector)) : [];
135
+ els = root ? _jqSelect(root, selector) : [];
70
136
  }
71
137
  }
72
138
  } else {
@@ -163,17 +229,39 @@
163
229
  // loading-indicator pattern (`$(document).ajaxStart(...)`) — used at
164
230
  // _re.js's top level.
165
231
  var _ajaxActive = 0;
166
- $.ajax = function (opts) {
232
+ // jQuery's default encoding for object data: application/x-www-form-urlencoded
233
+ // (nested objects/arrays as a[b]=c / a[]=1), appended to the URL for GET.
234
+ $.param = function (obj) {
235
+ var parts = [];
236
+ function add(k, v) {
237
+ if (v && typeof v === 'object') {
238
+ for (var kk in v) if (Object.prototype.hasOwnProperty.call(v, kk)) add(k + '[' + (Array.isArray(v) ? '' : kk) + ']', v[kk]);
239
+ } else parts.push(encodeURIComponent(k) + '=' + encodeURIComponent(v == null ? '' : v));
240
+ }
241
+ for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) add(k, obj[k]);
242
+ return parts.join('&');
243
+ };
244
+ $.ajax = function (url, opts) {
245
+ if (typeof url === 'object') { opts = url; url = opts.url; }
167
246
  opts = opts || {};
168
247
  var method = (opts.method || opts.type || 'GET').toUpperCase();
169
- var init = { method: method, headers: opts.headers || {} };
170
- if (opts.data != null && method !== 'GET') {
171
- init.body = typeof opts.data === 'string' ? opts.data : JSON.stringify(opts.data);
248
+ var headers = Object.assign({}, opts.headers || {});
249
+ var init = { method: method, headers: headers };
250
+ var data = opts.data;
251
+ var isJson = /json/i.test(opts.contentType || '');
252
+ if (data != null && method === 'GET') {
253
+ var qs = typeof data === 'string' ? data : $.param(data);
254
+ if (qs) url += (url.indexOf('?') === -1 ? '?' : '&') + qs;
255
+ } else if (data != null) {
256
+ if (typeof data === 'string' || (typeof FormData !== 'undefined' && data instanceof FormData)) init.body = data;
257
+ else if (isJson) init.body = JSON.stringify(data);
258
+ else { init.body = $.param(data); if (!headers['Content-Type']) headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'; }
259
+ if (isJson && !headers['Content-Type']) headers['Content-Type'] = opts.contentType;
172
260
  }
173
261
  if (_ajaxActive === 0) $(document).trigger('ajaxStart');
174
262
  _ajaxActive++;
175
263
  $(document).trigger('ajaxSend');
176
- return fetch(opts.url, init)
264
+ var p = fetch(url, init)
177
265
  .then(function (res) {
178
266
  var ct = res.headers.get('content-type') || '';
179
267
  return ct.indexOf('json') > -1 ? res.json() : res.text();
@@ -193,7 +281,25 @@
193
281
  $(document).trigger('ajaxComplete');
194
282
  if (_ajaxActive === 0) $(document).trigger('ajaxStop');
195
283
  });
284
+ // jqXHR-style chaining; the rejection is consumed only via these.
285
+ p.done = function (fn) { p.then(fn, function () { }); return p; };
286
+ p.fail = function (fn) { p.catch(fn); return p; };
287
+ p.always = function (fn) { p.then(fn, fn); return p; };
288
+ return p;
196
289
  };
290
+ function _shorthand(method) {
291
+ return function (url, data, success, dataType) {
292
+ if (typeof data === 'function') { dataType = success; success = data; data = undefined; }
293
+ return $.ajax({ url: url, method: method, data: data, success: success, dataType: dataType });
294
+ };
295
+ }
296
+ $.get = _shorthand('GET');
297
+ $.post = _shorthand('POST');
298
+ $.getJSON = function (url, data, success) { return $.get(url, data, success, 'json'); };
299
+ $.parseJSON = function (s) { return JSON.parse(s); };
300
+ $.isArray = Array.isArray;
301
+ $.isFunction = function (f) { return typeof f === 'function'; };
302
+ $.noop = function () { };
197
303
 
198
304
  $.fn.each = function (fn) {
199
305
  for (var i = 0; i < this.length; i++) if (fn.call(this[i], i, this[i]) === false) break;
@@ -249,14 +355,64 @@
249
355
  $.fn.hasAttr = function (name) {
250
356
  return !!(this[0] && this[0].getAttribute(name) != null);
251
357
  };
358
+ // jQuery keeps .data() values in an internal cache (objects keep their
359
+ // identity; plugin instances, engines and cyclic structures are fine) and
360
+ // falls back to data-* attributes on read. Primitives are also mirrored to
361
+ // the attribute, which existing code reads back.
362
+ var _dataCache = typeof WeakMap !== 'undefined' ? new WeakMap() : null;
363
+ function _dataStore(el, create) {
364
+ if (!_dataCache || !el || typeof el !== 'object') return null;
365
+ var s = _dataCache.get(el);
366
+ if (!s && create) { s = {}; _dataCache.set(el, s); }
367
+ return s;
368
+ }
369
+ function _camel(k) { return String(k).replace(/-([a-z])/g, function (_, c) { return c.toUpperCase(); }); }
370
+ function _parseDataAttr(v) {
371
+ if (v === undefined) return undefined;
372
+ if (v === 'true') return true;
373
+ if (v === 'false') return false;
374
+ if (v === 'null') return null;
375
+ if (v !== '' && !isNaN(v) && String(+v) === v) return +v;
376
+ if (/^[\[{]/.test(v)) { try { return JSON.parse(v); } catch (e) { } }
377
+ return v;
378
+ }
252
379
  $.fn.data = function (key, value) {
380
+ if (key && typeof key === 'object') {
381
+ var obj = key;
382
+ return this.each(function () { for (var k in obj) $(this).data(k, obj[k]); });
383
+ }
253
384
  if (value === undefined) {
254
- if (!this[0]) return undefined;
255
- if (key === undefined) return Object.assign({}, this[0].dataset);
256
- var v = this[0].dataset[key];
257
- try { return JSON.parse(v); } catch (e) { return v; }
385
+ var el = this[0];
386
+ if (!el) return undefined;
387
+ var store = _dataStore(el, false);
388
+ var ds = el.dataset || {};
389
+ if (key === undefined) {
390
+ var all = {};
391
+ for (var dk in ds) all[dk] = _parseDataAttr(ds[dk]);
392
+ return Object.assign(all, store || {});
393
+ }
394
+ if (store && Object.prototype.hasOwnProperty.call(store, key)) return store[key];
395
+ var ck = _camel(key);
396
+ if (store && Object.prototype.hasOwnProperty.call(store, ck)) return store[ck];
397
+ return _parseDataAttr(ds[ck]);
258
398
  }
259
- return this.each(function () { this.dataset[key] = typeof value === 'string' ? value : JSON.stringify(value); });
399
+ return this.each(function () {
400
+ var s = _dataStore(this, true);
401
+ if (s) s[key] = value;
402
+ if (this.dataset && (value === null || typeof value !== 'object') && typeof value !== 'function') {
403
+ try { this.dataset[_camel(key)] = String(value); } catch (e) { }
404
+ }
405
+ });
406
+ };
407
+ $.fn.removeData = function (key) {
408
+ return this.each(function () {
409
+ var s = _dataStore(this, false);
410
+ var keys = key === undefined ? (s ? Object.keys(s) : []) : String(key).split(/\s+/);
411
+ for (var i = 0; i < keys.length; i++) {
412
+ if (s) { delete s[keys[i]]; delete s[_camel(keys[i])]; }
413
+ if (this.dataset) { try { delete this.dataset[_camel(keys[i])]; } catch (e) { } }
414
+ }
415
+ });
260
416
  };
261
417
  $.fn.val = function (value) {
262
418
  if (value === undefined) return this[0] ? this[0].value : undefined;
@@ -454,8 +610,13 @@
454
610
  // set, exactly what's needed here).
455
611
  $.fn.find = function (sel) {
456
612
  var out = [];
613
+ if (sel && typeof sel === 'object') {
614
+ var cands = toArray(sel instanceof $ ? sel : [sel]);
615
+ var self = toArray(this);
616
+ return $(cands.filter(function (c) { return self.some(function (p) { return p !== c && p.contains(c); }); }));
617
+ }
457
618
  this.each(function () {
458
- var found = this.querySelectorAll(sel);
619
+ var found = _jqSelect(this, sel);
459
620
  for (var i = 0; i < found.length; i++) if (out.indexOf(found[i]) === -1) out.push(found[i]);
460
621
  });
461
622
  return $(out);
@@ -474,16 +635,169 @@
474
635
  ':radio': function (el) { return el.tagName === 'INPUT' && el.type === 'radio'; },
475
636
  ':checked': function (el) { return !!el.checked; },
476
637
  };
638
+ JQUERY_PSEUDOS[':selected'] = function (el) { return !!el.selected; };
639
+ JQUERY_PSEUDOS[':visible'] = function (el) { return !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length); };
640
+ JQUERY_PSEUDOS[':hidden'] = function (el) { return !JQUERY_PSEUDOS[':visible'](el); };
477
641
  $.fn.is = function (sel) {
478
642
  if (!this[0]) return false;
643
+ if (typeof sel === 'function') { var s = this; return toArray(this).some(function (el, i) { return sel.call(el, i, el); }); }
644
+ if (sel && typeof sel === 'object') { var set = toArray(sel instanceof $ ? sel : [sel]); return toArray(this).some(function (el) { return set.indexOf(el) !== -1; }); }
479
645
  if (JQUERY_PSEUDOS[sel]) return JQUERY_PSEUDOS[sel](this[0]);
480
- try { return this[0].matches(sel); } catch (e) { return false; }
646
+ var rewritten = sel;
647
+ for (var r = 0; r < JQ_REWRITES.length; r++) rewritten = rewritten.replace(JQ_REWRITES[r][0], JQ_REWRITES[r][1]);
648
+ try { return this[0].matches(rewritten); } catch (e) { return false; }
481
649
  };
482
650
  $.fn.ready = function (fn) {
483
651
  if (document.readyState !== 'loading') fn($);
484
652
  else document.addEventListener('DOMContentLoaded', function () { fn($); });
485
653
  return this;
486
654
  };
655
+
656
+ // ---- Traversal ----
657
+ function _filterBySel(els, sel) {
658
+ if (!sel) return els;
659
+ return els.filter(function (el) { return $(el).is(sel); });
660
+ }
661
+ $.fn.eq = function (i) { i = +i; if (i < 0) i += this.length; return $(this[i] ? [this[i]] : []); };
662
+ $.fn.first = function () { return this.eq(0); };
663
+ $.fn.last = function () { return this.eq(-1); };
664
+ $.fn.index = function (target) {
665
+ if (target === undefined) {
666
+ var el = this[0];
667
+ if (!el || !el.parentElement) return -1;
668
+ return toArray(el.parentElement.children).indexOf(el);
669
+ }
670
+ var node = target instanceof $ ? target[0] : (typeof target === 'string' ? null : target);
671
+ if (typeof target === 'string') return toArray($(target)).indexOf(this[0]);
672
+ return toArray(this).indexOf(node);
673
+ };
674
+ $.fn.add = function (sel, ctx) {
675
+ var out = toArray(this);
676
+ toArray(typeof sel === 'string' && sel.trim()[0] !== '<' ? $(sel, ctx) : $(sel)).forEach(function (x) { if (out.indexOf(x) === -1) out.push(x); });
677
+ return $(out);
678
+ };
679
+ $.fn.children = function (sel) {
680
+ var out = [];
681
+ this.each(function () { out.push.apply(out, toArray(this.children || [])); });
682
+ return $(_filterBySel(out, sel));
683
+ };
684
+ $.fn.contents = function () {
685
+ var out = [];
686
+ this.each(function () { out.push.apply(out, toArray(this.childNodes || [])); });
687
+ return $(out);
688
+ };
689
+ $.fn.siblings = function (sel) {
690
+ var out = [];
691
+ this.each(function () {
692
+ var me = this;
693
+ if (!me.parentElement) return;
694
+ toArray(me.parentElement.children).forEach(function (c) { if (c !== me && out.indexOf(c) === -1) out.push(c); });
695
+ });
696
+ return $(_filterBySel(out, sel));
697
+ };
698
+ $.fn.prev = function (sel) {
699
+ var out = [];
700
+ this.each(function () { var p = this.previousElementSibling; if (p) out.push(p); });
701
+ return $(_filterBySel(out, sel));
702
+ };
703
+ $.fn.prevAll = function (sel) {
704
+ var out = [];
705
+ this.each(function () { var p = this.previousElementSibling; while (p) { if (out.indexOf(p) === -1) out.push(p); p = p.previousElementSibling; } });
706
+ return $(_filterBySel(out, sel));
707
+ };
708
+ $.fn.nextAll = function (sel) {
709
+ var out = [];
710
+ this.each(function () { var n = this.nextElementSibling; while (n) { if (out.indexOf(n) === -1) out.push(n); n = n.nextElementSibling; } });
711
+ return $(_filterBySel(out, sel));
712
+ };
713
+ $.fn.parents = function (sel) {
714
+ var out = [];
715
+ this.each(function () { var p = this.parentElement; while (p) { if (out.indexOf(p) === -1) out.push(p); p = p.parentElement; } });
716
+ return $(_filterBySel(out, sel));
717
+ };
718
+ $.fn.filter = function (sel) {
719
+ var els = toArray(this);
720
+ if (typeof sel === 'function') return $(els.filter(function (el, i) { return sel.call(el, i, el); }));
721
+ return $(_filterBySel(els, sel));
722
+ };
723
+ $.fn.has = function (sel) {
724
+ return $(toArray(this).filter(function (el) { return $(el).find(sel).length > 0; }));
725
+ };
726
+ $.fn.map = function (fn) {
727
+ var out = [];
728
+ this.each(function (i, el) { var r = fn.call(el, i, el); if (r != null) Array.isArray(r) ? out.push.apply(out, r) : out.push(r); });
729
+ return $(out);
730
+ };
731
+ $.fn.toArray = function () { return toArray(this); };
732
+
733
+ // ---- Visibility (display toggles; timed variants call back after) ----
734
+ function _isHidden(el) {
735
+ return el.style.display === 'none' || (window.getComputedStyle && getComputedStyle(el).display === 'none');
736
+ }
737
+ function _show(el) {
738
+ if (el.style.display === 'none') el.style.display = el._lmOldDisplay || '';
739
+ if (window.getComputedStyle && getComputedStyle(el).display === 'none') el.style.display = el._lmOldDisplay || 'block';
740
+ }
741
+ function _hide(el) {
742
+ if (el.style.display && el.style.display !== 'none') el._lmOldDisplay = el.style.display;
743
+ el.style.display = 'none';
744
+ }
745
+ function _timedArgs(a, b, c) {
746
+ var cb = [a, b, c].filter(function (x) { return typeof x === 'function'; })[0];
747
+ var ms = typeof a === 'number' ? a : (a === 'slow' ? 600 : a === 'fast' ? 200 : (a && typeof a === 'object' && a.duration) || 0);
748
+ return { ms: ms, cb: cb };
749
+ }
750
+ function _visibilityMethod(apply) {
751
+ return function (a, b, c) {
752
+ var t = _timedArgs(a, b, c), self = this;
753
+ this.each(function () { apply(this); });
754
+ if (t.cb) setTimeout(function () { self.each(function () { t.cb.call(this); }); }, t.ms);
755
+ return this;
756
+ };
757
+ }
758
+ $.fn.show = _visibilityMethod(_show);
759
+ $.fn.hide = _visibilityMethod(_hide);
760
+ $.fn.fadeIn = $.fn.show;
761
+ $.fn.fadeOut = $.fn.hide;
762
+ $.fn.slideDown = $.fn.show;
763
+ $.fn.slideUp = $.fn.hide;
764
+ $.fn.toggle = function (state) {
765
+ if (typeof state === 'boolean') return state ? this.show() : this.hide();
766
+ var t = _timedArgs.apply(null, arguments), self = this;
767
+ this.each(function () { _isHidden(this) ? _show(this) : _hide(this); });
768
+ if (t.cb) setTimeout(function () { self.each(function () { t.cb.call(this); }); }, t.ms);
769
+ return this;
770
+ };
771
+ $.fn.fadeToggle = $.fn.toggle;
772
+ $.fn.slideToggle = $.fn.toggle;
773
+
774
+ // ---- Manipulation ----
775
+ $.fn.empty = function () { return this.each(function () { while (this.firstChild) this.removeChild(this.firstChild); }); };
776
+ $.fn.before = function (content) {
777
+ return this.each(function () { var t = this; _normalizeAppendable([content]).forEach(function (n) { t.parentNode && t.parentNode.insertBefore(n, t); }); });
778
+ };
779
+ $.fn.wrap = function (wrapper) {
780
+ return this.each(function () {
781
+ var w = _normalizeAppendable([wrapper]).filter(function (n) { return n.nodeType === 1; })[0];
782
+ if (!w || !this.parentNode) return;
783
+ w = w.cloneNode(true);
784
+ this.parentNode.insertBefore(w, this);
785
+ var inner = w; while (inner.firstElementChild) inner = inner.firstElementChild;
786
+ inner.appendChild(this);
787
+ });
788
+ };
789
+ $.fn.unwrap = function () {
790
+ var parents = [];
791
+ this.each(function () { var p = this.parentElement; if (p && p !== document.body && parents.indexOf(p) === -1) parents.push(p); });
792
+ parents.forEach(function (p) { while (p.firstChild) p.parentNode.insertBefore(p.firstChild, p); p.parentNode.removeChild(p); });
793
+ return this;
794
+ };
795
+ $.fn.clone = function () { return $(toArray(this).map(function (el) { return el.cloneNode(true); })); };
796
+ $.fn.position = function () {
797
+ var el = this[0];
798
+ if (!el) return undefined;
799
+ return { top: el.offsetTop, left: el.offsetLeft };
800
+ };
487
801
  // jQuery's full family of global ajax events — all just named events on
488
802
  // document under the hood, registered/fired the same way.
489
803
  ['ajaxStart', 'ajaxStop', 'ajaxSend', 'ajaxSuccess', 'ajaxError', 'ajaxComplete'].forEach(function (name) {
@@ -545,15 +859,48 @@
545
859
  // native closest(); every other selector (e.g. lstnrs.js's own
546
860
  // "[up] [browse]") is untouched, still native.
547
861
  var AT_ATTR_SELECTOR = /^\[\\@([\w-]+)\]$/;
548
- $.fn.on = function (events, selector, handler) {
862
+ // jQuery passes .trigger(name, extraParams) on to handlers as extra
863
+ // arguments (an array is spread). Carried on a private property, not
864
+ // ev.detail — a native click's detail is its click count.
865
+ function _callHandler(handler, ctx, e) {
866
+ var extra = e.__lmArgs;
867
+ if (extra === undefined) return handler.call(ctx, e);
868
+ return handler.apply(ctx, [e].concat(Array.isArray(extra) ? extra : [extra]));
869
+ }
870
+
871
+ $.fn.on = function (events, selector, data, handler) {
549
872
  if (typeof selector === 'function') { handler = selector; selector = null; }
550
- var evts = events.split(/\s+/).filter(Boolean);
551
- var atMatch = selector && AT_ATTR_SELECTOR.exec(selector);
552
- var atAttr = atMatch ? '@' + atMatch[1] : null;
873
+ else if (typeof data === 'function' && handler === undefined) { handler = data; }
874
+ else if (typeof handler !== 'function' && typeof data === 'function') { handler = data; }
875
+ if (typeof selector !== 'string') selector = null;
876
+ if (typeof handler !== 'function') return this;
877
+ var evts = String(events).split(/\s+/).filter(Boolean);
878
+ // A comma list of [\\@name] parts ("[\\@input],[\\@change],...",
879
+ // "[\\@swipe],[\\@swipe-up],...") is the same case — native
880
+ // closest() can't match any part of it either.
881
+ var atParts = selector ? selector.split(',').map(function (p) { return p.trim(); }) : [];
882
+ var atAttrs = atParts.length && atParts.every(function (p) { return AT_ATTR_SELECTOR.test(p); })
883
+ ? atParts.map(function (p) { return '@' + AT_ATTR_SELECTOR.exec(p)[1]; })
884
+ : null;
885
+ var atAttr = !!atAttrs;
886
+ function _hasAnyAt(el) {
887
+ for (var i = 0; i < atAttrs.length; i++) if (el.getAttribute(atAttrs[i]) != null) return true;
888
+ return false;
889
+ }
553
890
  return this.each(function () {
554
891
  var node = this;
555
892
  var bus = _eventTargetFor(node);
556
- evts.forEach(function (evt) {
893
+ evts.forEach(function (evtFull) {
894
+ // "click.myns": jQuery namespaces only scope .off(); the
895
+ // real event is the part before the first dot.
896
+ var dot = evtFull.indexOf('.');
897
+ var evt = dot === -1 ? evtFull : evtFull.slice(0, dot);
898
+ var ns = dot === -1 ? '' : evtFull.slice(dot + 1);
899
+ if (!evt) return;
900
+ function listen(realName, wrapper) {
901
+ bus.addEventListener(realName, wrapper);
902
+ _recordListener(bus, { type: evt, ns: ns, selector: selector, handler: handler, real: realName, wrapper: wrapper });
903
+ }
557
904
  // 2026-09-22, real bug found and fixed: mouseenter/
558
905
  // mouseleave are real DOM events, but — unlike click,
559
906
  // change, etc. — they never bubble at all (only their
@@ -570,54 +917,57 @@
570
917
  // 1:1 rename).
571
918
  if (evt === 'mouseenter' || evt === 'mouseleave') {
572
919
  var realType = evt === 'mouseenter' ? 'mouseover' : 'mouseout';
573
- bus.addEventListener(realType, function (e) {
920
+ listen(realType, function (e) {
574
921
  var related = e.relatedTarget;
575
922
  if (atAttr) {
576
923
  var el = e.target;
577
924
  var match = null;
578
925
  while (el && el.nodeType === 1) {
579
- if (el.getAttribute(atAttr) != null) { match = el; break; }
926
+ if (_hasAnyAt(el)) { match = el; break; }
580
927
  el = el.parentElement;
581
928
  }
582
929
  if (match && node.contains(match) && !(related && match.contains(related))) {
583
- handler.call(match, e);
930
+ _callHandler(handler, match, e);
584
931
  }
585
932
  } else if (selector && _isNode(node)) {
586
933
  var match2 = e.target.closest(selector);
587
934
  if (match2 && node.contains(match2) && !(related && match2.contains(related))) {
588
- handler.call(match2, e);
935
+ _callHandler(handler, match2, e);
589
936
  }
590
937
  } else if (!(related && node.contains(related))) {
591
- handler.call(node, e);
938
+ _callHandler(handler, node, e);
592
939
  }
593
940
  });
594
941
  return;
595
942
  }
596
943
  var real = EVENT_NAME_MAP[evt] || evt;
597
- bus.addEventListener(real, function (e) {
944
+ listen(real, function (e) {
598
945
  if (atAttr) {
599
946
  var el = e.target;
600
947
  var match = null;
601
948
  while (el && el.nodeType === 1) {
602
- if (el.getAttribute(atAttr) != null) { match = el; break; }
949
+ if (_hasAnyAt(el)) { match = el; break; }
603
950
  el = el.parentElement;
604
951
  }
605
- if (match && node.contains(match)) handler.call(match, e);
952
+ if (match && node.contains(match)) _callHandler(handler, match, e);
606
953
  } else if (selector && _isNode(node)) {
607
954
  var match2 = e.target.closest(selector);
608
- if (match2 && node.contains(match2)) handler.call(match2, e);
955
+ if (match2 && node.contains(match2)) _callHandler(handler, match2, e);
609
956
  } else {
610
- handler.call(node, e);
957
+ _callHandler(handler, node, e);
611
958
  }
612
959
  });
613
960
  });
614
961
  });
615
962
  };
616
- // No .live() — 2026-09-13: confirmed every call site in lstnrs.js was
617
- // internal (never part of the app-facing API), and the file already
618
- // uses `$("body").on(event, selector, handler)` everywhere else for the
619
- // exact same pattern. Migrated all 11 sites to that instead of shimming
620
- // a deprecated jQuery API just to keep two spellings of one thing.
963
+ // Real V1 project code (view/tpl scripts) still uses the pre-1.9
964
+ // jQuery .live(): a document-level delegated binding on this set's
965
+ // own selector.
966
+ $.fn.live = function (events, data, handler) {
967
+ if (this.selector && typeof this.selector === 'string') $(document).on(events, this.selector, data, handler);
968
+ else this.on(events, data, handler);
969
+ return this;
970
+ };
621
971
  $.fn.click = function (handler) { return handler ? this.on('click', handler) : this.trigger('click'); };
622
972
  $.fn.keydown = function (handler) { return handler ? this.on('keydown', handler) : this.trigger('keydown'); };
623
973
  $.fn.trigger = function (type, data) {
@@ -651,15 +1001,58 @@
651
1001
  } else {
652
1002
  ev = new Event(type, { bubbles: _isNode(this) });
653
1003
  }
654
- if (data !== undefined) ev.detail = data;
1004
+ if (data !== undefined) {
1005
+ ev.__lmArgs = data;
1006
+ try { if (ev.detail === undefined || ev.detail === null) ev.detail = data; } catch (e) { }
1007
+ }
655
1008
  bus.dispatchEvent(ev);
656
1009
  });
657
1010
  };
658
- // Real removal needs the original listener reference, which this shim
659
- // doesn't track (LumenJS's own model is delegation-first — see
660
- // lumenjs-spec.md §5.6 — so long-lived per-node listeners needing unbind
661
- // are already the exception, not the pattern). Kept for API completeness.
662
- $.fn.unbind = function () { return this; };
1011
+ var _listenerRegistry = typeof WeakMap !== 'undefined' ? new WeakMap() : null;
1012
+ function _recordListener(bus, rec) {
1013
+ if (!_listenerRegistry) return;
1014
+ var list = _listenerRegistry.get(bus);
1015
+ if (!list) { list = []; _listenerRegistry.set(bus, list); }
1016
+ list.push(rec);
1017
+ }
1018
+ $.fn.off = function (events, selector, handler) {
1019
+ if (typeof selector === 'function') { handler = selector; selector = undefined; }
1020
+ var specs = events === undefined ? [{ type: '', ns: '' }] : String(events).split(/\s+/).filter(Boolean).map(function (e) {
1021
+ var d = e.indexOf('.');
1022
+ return { type: d === -1 ? e : e.slice(0, d), ns: d === -1 ? '' : e.slice(d + 1) };
1023
+ });
1024
+ return this.each(function () {
1025
+ if (!_listenerRegistry) return;
1026
+ var bus = _eventTargetFor(this);
1027
+ var list = _listenerRegistry.get(bus);
1028
+ if (!list) return;
1029
+ for (var i = list.length - 1; i >= 0; i--) {
1030
+ var r = list[i];
1031
+ var hit = specs.some(function (sp) {
1032
+ return (!sp.type || sp.type === r.type) && (!sp.ns || sp.ns === r.ns);
1033
+ });
1034
+ if (!hit) continue;
1035
+ if (selector !== undefined && selector !== '**' && r.selector !== selector) continue;
1036
+ if (handler && r.handler !== handler) continue;
1037
+ bus.removeEventListener(r.real, r.wrapper);
1038
+ list.splice(i, 1);
1039
+ }
1040
+ });
1041
+ };
1042
+ $.fn.unbind = function (events, handler) { return this.off(events, handler); };
1043
+ $.fn.bind = function (events, data, handler) { return this.on(events, null, data, handler); };
1044
+ $.fn.one = function (events, selector, data, handler) {
1045
+ var args = [].slice.call(arguments), fn = null, idx = -1;
1046
+ for (var i = args.length - 1; i >= 0; i--) if (typeof args[i] === 'function') { fn = args[i]; idx = i; break; }
1047
+ if (!fn) return this;
1048
+ var self = this;
1049
+ args[idx] = function once(e) { self.off(events, once); return fn.apply(this, arguments); };
1050
+ return this.on.apply(this, args);
1051
+ };
1052
+ $.fn.die = function (events, handler) {
1053
+ if (this.selector && typeof this.selector === 'string') $(document).off(events, this.selector, handler);
1054
+ return this;
1055
+ };
663
1056
 
664
1057
  // jQuery's shorthand event methods (2026-09-14, real gap found testing
665
1058
  // a real project's vendor code end-to-end — `$(el).keyup(...)` threw
package/src/lstnrs.js CHANGED
@@ -6,11 +6,23 @@ var _navT = 0;
6
6
  var _nav = false;
7
7
  var _pbc;
8
8
  var _vuid = {};
9
+ // Mobile autoplay policy: a suspended AudioContext can only be resumed from a
10
+ // real user gesture, so V1 unlocked one on the first click/touch/tap.
11
+ // 2026-09-26: V1 did `new AudioContext()` bare. This handler runs on EVERY
12
+ // click, so in any environment without the unprefixed constructor (older
13
+ // Safari exposes only webkitAudioContext) that threw on every single click of
14
+ // the page's life. Same unguarded-optional-API class as the renderPlugins()
15
+ // fixes; guarded here, with the real webkit fallback V1 never had.
9
16
  $("body").on("click touch tap", function (e) {
10
- if (!_pbc) _pbc = new AudioContext();
11
- if (_pbc.state == "suspended") {
12
- _pbc.resume().then(() => { });
13
- }
17
+ try {
18
+ var _AC = typeof AudioContext !== "undefined" ? AudioContext
19
+ : (typeof webkitAudioContext !== "undefined" ? webkitAudioContext : null);
20
+ if (!_AC) return;
21
+ if (!_pbc) _pbc = new _AC();
22
+ if (_pbc.state == "suspended") {
23
+ _pbc.resume().then(() => { });
24
+ }
25
+ } catch (err) { }
14
26
  });
15
27
  $("body").on("click touch", ".navTgl", function (e) {
16
28
  _nav = false;
@@ -752,7 +764,11 @@ $("body").on(
752
764
  "change blur focus keyup keydown input",
753
765
  "[\\@input],[\\@change],[\\@blur],[\\@focus],[\\@keyup],[\\@keydown]",
754
766
  function (ev) {
755
- processEv(ev, $(this), ev.type);
767
+ // focus/blur don't bubble, so delegation listens for focusin/focusout;
768
+ // real jQuery reports the original type back — do the same, or
769
+ // processEv looks for a nonexistent @focusin/@focusout attribute.
770
+ var t = ev.type === "focusin" ? "focus" : ev.type === "focusout" ? "blur" : ev.type;
771
+ processEv(ev, $(this), t);
756
772
  }
757
773
  );
758
774