vrembem 1.40.1 → 1.41.0
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/LICENSE +1 -1
- package/dev/scripts.esm.js +633 -510
- package/dev/scripts.esm.js.map +1 -1
- package/dev/scripts.js +633 -510
- package/dev/scripts.js.map +1 -1
- package/dev/scripts.modern.js +529 -438
- package/dev/scripts.modern.js.map +1 -1
- package/dev/scripts.umd.js +633 -510
- package/dev/scripts.umd.js.map +1 -1
- package/dev/styles.css.map +1 -1
- package/dist/scripts.esm.js +1 -1
- package/dist/scripts.esm.js.map +1 -1
- package/dist/scripts.js +1 -1
- package/dist/scripts.js.map +1 -1
- package/dist/scripts.modern.js +1 -1
- package/dist/scripts.modern.js.map +1 -1
- package/dist/scripts.umd.js +1 -1
- package/dist/scripts.umd.js.map +1 -1
- package/dist/styles.css.map +1 -1
- package/package.json +26 -26
package/dev/scripts.modern.js
CHANGED
|
@@ -34,10 +34,9 @@ const setTabindex = selector => {
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
* Adds a class or classes to
|
|
38
|
-
*
|
|
39
|
-
* @param
|
|
40
|
-
* @param {String || Array} cl - Class(es) to add
|
|
37
|
+
* Adds a class or classes to a Node or NodeList.
|
|
38
|
+
* @param {Node || NodeList} el - Element(s) to add class(es) to.
|
|
39
|
+
* @param {String || Array} cl - Class(es) to add.
|
|
41
40
|
*/
|
|
42
41
|
const addClass = (el, ...cl) => {
|
|
43
42
|
el = el.forEach ? el : [el];
|
|
@@ -47,10 +46,9 @@ const addClass = (el, ...cl) => {
|
|
|
47
46
|
};
|
|
48
47
|
|
|
49
48
|
/**
|
|
50
|
-
* Takes a hyphen cased string and converts it to camel case
|
|
51
|
-
*
|
|
52
|
-
* @
|
|
53
|
-
* @returns {Boolean} - returns a camel cased string
|
|
49
|
+
* Takes a hyphen cased string and converts it to camel case.
|
|
50
|
+
* @param {String } str - the string to convert to camel case.
|
|
51
|
+
* @returns {Boolean} - returns a camel cased string.
|
|
54
52
|
*/
|
|
55
53
|
const camelCase = str => {
|
|
56
54
|
return str.replace(/-([a-z])/g, function (g) {
|
|
@@ -169,23 +167,21 @@ class FocusTrap {
|
|
|
169
167
|
}
|
|
170
168
|
|
|
171
169
|
/**
|
|
172
|
-
* Get an element(s) from a selector or return value if not a string
|
|
173
|
-
*
|
|
174
|
-
* @param {
|
|
175
|
-
* @param {Boolean} single - Whether to return a single or all matches
|
|
170
|
+
* Get an element(s) from a selector or return value if not a string.
|
|
171
|
+
* @param {String} selector - Selector to query.
|
|
172
|
+
* @param {Boolean} single - Whether to return a single or all matches.
|
|
176
173
|
*/
|
|
177
174
|
const getElement = function getElement(selector, single = 0) {
|
|
178
|
-
if (typeof selector
|
|
175
|
+
if (typeof selector !== 'string') return selector;
|
|
179
176
|
return single ? document.querySelector(selector) : document.querySelectorAll(selector);
|
|
180
177
|
};
|
|
181
178
|
|
|
182
179
|
/**
|
|
183
|
-
* Checks an element or NodeList whether they contain a class or classes
|
|
180
|
+
* Checks an element or NodeList whether they contain a class or classes.
|
|
184
181
|
* Ref: https://davidwalsh.name/nodelist-array
|
|
185
|
-
*
|
|
186
|
-
* @param {
|
|
187
|
-
* @
|
|
188
|
-
* @returns {Boolean} - Returns true if class exists, otherwise false
|
|
182
|
+
* @param {Node} el - Element(s) to check class(es) on.
|
|
183
|
+
* @param {String || Array} c - Class(es) to check.
|
|
184
|
+
* @returns {Boolean} - Returns true if class exists, otherwise false.
|
|
189
185
|
*/
|
|
190
186
|
const hasClass = (el, ...cl) => {
|
|
191
187
|
el = el.forEach ? el : [el];
|
|
@@ -198,10 +194,9 @@ const hasClass = (el, ...cl) => {
|
|
|
198
194
|
};
|
|
199
195
|
|
|
200
196
|
/**
|
|
201
|
-
* Takes a camel cased string and converts it to hyphen case
|
|
202
|
-
*
|
|
203
|
-
* @
|
|
204
|
-
* @returns {Boolean} - returns a hyphen cased string
|
|
197
|
+
* Takes a camel cased string and converts it to hyphen case.
|
|
198
|
+
* @param {String } str - the string to convert to hyphen case.
|
|
199
|
+
* @returns {Boolean} - returns a hyphen cased string.
|
|
205
200
|
*/
|
|
206
201
|
const hyphenCase = str => {
|
|
207
202
|
return str.replace(/([a-z][A-Z])/g, function (g) {
|
|
@@ -210,11 +205,10 @@ const hyphenCase = str => {
|
|
|
210
205
|
};
|
|
211
206
|
|
|
212
207
|
/**
|
|
213
|
-
* Moves element(s) in the DOM based on a reference and move type
|
|
214
|
-
*
|
|
215
|
-
* @param {String}
|
|
216
|
-
* @param {String}
|
|
217
|
-
* @param {String} reference - The reference element the move is relative to
|
|
208
|
+
* Moves element(s) in the DOM based on a reference and move type.
|
|
209
|
+
* @param {String} target - The element(s) to move.
|
|
210
|
+
* @param {String} type - Move type can be 'after', 'before', 'append' or 'prepend'.
|
|
211
|
+
* @param {String} reference - The reference element the move is relative to.
|
|
218
212
|
*/
|
|
219
213
|
|
|
220
214
|
function moveElement(target, type, reference = false) {
|
|
@@ -265,10 +259,9 @@ function moveElement(target, type, reference = false) {
|
|
|
265
259
|
}
|
|
266
260
|
|
|
267
261
|
/**
|
|
268
|
-
* Remove a class or classes from an element or NodeList
|
|
269
|
-
*
|
|
270
|
-
* @param {
|
|
271
|
-
* @param {String || Array} cl - Class(es) to remove
|
|
262
|
+
* Remove a class or classes from an element or NodeList.
|
|
263
|
+
* @param {Node || NodeList} el - Element(s) to remove class(es) from.
|
|
264
|
+
* @param {String || Array} cl - Class(es) to remove.
|
|
272
265
|
*/
|
|
273
266
|
const removeClass = (el, ...cl) => {
|
|
274
267
|
el = el.forEach ? el : [el];
|
|
@@ -278,10 +271,9 @@ const removeClass = (el, ...cl) => {
|
|
|
278
271
|
};
|
|
279
272
|
|
|
280
273
|
/**
|
|
281
|
-
* Toggle a class or classes on an element or NodeList
|
|
282
|
-
*
|
|
283
|
-
* @param {
|
|
284
|
-
* @param {String || Array} cl - Class(es) to toggle
|
|
274
|
+
* Toggle a class or classes on an element or NodeList.
|
|
275
|
+
* @param {Node || NodeList} el - Element(s) to toggle class(es) on.
|
|
276
|
+
* @param {String || Array} cl - Class(es) to toggle.
|
|
285
277
|
*/
|
|
286
278
|
const toggleClass = (el, ...cl) => {
|
|
287
279
|
el = el.forEach ? el : [el];
|
|
@@ -367,13 +359,15 @@ function _extends() {
|
|
|
367
359
|
return _extends.apply(this, arguments);
|
|
368
360
|
}
|
|
369
361
|
|
|
362
|
+
var defaults$3 = {
|
|
363
|
+
autoInit: false,
|
|
364
|
+
stateAttr: 'aria-checked',
|
|
365
|
+
stateValue: 'mixed'
|
|
366
|
+
};
|
|
367
|
+
|
|
370
368
|
class Checkbox {
|
|
371
369
|
constructor(options) {
|
|
372
|
-
this.defaults =
|
|
373
|
-
autoInit: false,
|
|
374
|
-
stateAttr: 'aria-checked',
|
|
375
|
-
stateValue: 'mixed'
|
|
376
|
-
};
|
|
370
|
+
this.defaults = defaults$3;
|
|
377
371
|
this.settings = _extends({}, this.defaults, options);
|
|
378
372
|
this.__handlerClick = this.handlerClick.bind(this);
|
|
379
373
|
if (this.settings.autoInit) this.init();
|
|
@@ -456,47 +450,6 @@ var defaults$2 = {
|
|
|
456
450
|
transition: true
|
|
457
451
|
};
|
|
458
452
|
|
|
459
|
-
async function switchToModal(drawerKey, obj) {
|
|
460
|
-
// Initial guards
|
|
461
|
-
const drawer = obj.getDrawer(drawerKey);
|
|
462
|
-
if (!drawer) return obj.drawerNotFound(drawerKey);
|
|
463
|
-
if (hasClass(drawer, obj.settings.classModal)) return; // Enable modal state
|
|
464
|
-
|
|
465
|
-
addClass(drawer, obj.settings.classModal);
|
|
466
|
-
addClass(drawer, obj.settings.stateClosed);
|
|
467
|
-
removeClass(drawer, obj.settings.stateOpened); // Dispatch custom event
|
|
468
|
-
|
|
469
|
-
drawer.dispatchEvent(new CustomEvent(obj.settings.customEventPrefix + 'toModal', {
|
|
470
|
-
bubbles: true
|
|
471
|
-
}));
|
|
472
|
-
return drawer;
|
|
473
|
-
}
|
|
474
|
-
async function switchToDefault(drawerKey, obj) {
|
|
475
|
-
// Initial guards
|
|
476
|
-
const drawer = obj.getDrawer(drawerKey);
|
|
477
|
-
if (!drawer) return obj.drawerNotFound(drawerKey);
|
|
478
|
-
if (!hasClass(drawer, obj.settings.classModal)) return; // Tear down modal state
|
|
479
|
-
|
|
480
|
-
setInert(false, obj.settings.selectorInert);
|
|
481
|
-
setOverflowHidden(false, obj.settings.selectorOverflow);
|
|
482
|
-
removeClass(drawer, obj.settings.classModal);
|
|
483
|
-
obj.focusTrap.destroy(); // Restore drawers saved state
|
|
484
|
-
|
|
485
|
-
drawerKey = drawer.getAttribute(`data-${obj.settings.dataDrawer}`);
|
|
486
|
-
const drawerState = obj.state[drawerKey];
|
|
487
|
-
|
|
488
|
-
if (drawerState == obj.settings.stateOpened) {
|
|
489
|
-
addClass(drawer, obj.settings.stateOpened);
|
|
490
|
-
removeClass(drawer, obj.settings.stateClosed);
|
|
491
|
-
} // Dispatch custom event
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
drawer.dispatchEvent(new CustomEvent(obj.settings.customEventPrefix + 'toDefault', {
|
|
495
|
-
bubbles: true
|
|
496
|
-
}));
|
|
497
|
-
return drawer;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
453
|
class Breakpoint {
|
|
501
454
|
constructor(parent) {
|
|
502
455
|
this.mediaQueryLists = [];
|
|
@@ -508,12 +461,21 @@ class Breakpoint {
|
|
|
508
461
|
init() {
|
|
509
462
|
const drawers = document.querySelectorAll(`[data-${this.parent.settings.dataBreakpoint}]`);
|
|
510
463
|
drawers.forEach(drawer => {
|
|
464
|
+
// Setup mediaQueryList object
|
|
511
465
|
const id = drawer.getAttribute(`data-${this.parent.settings.dataDrawer}`);
|
|
512
466
|
const key = drawer.getAttribute(`data-${this.parent.settings.dataBreakpoint}`);
|
|
513
467
|
const bp = this.getBreakpoint(key);
|
|
514
|
-
const mql = window.matchMedia('(min-width:' + bp + ')');
|
|
515
|
-
|
|
516
|
-
|
|
468
|
+
const mql = window.matchMedia('(min-width:' + bp + ')'); // Run match check
|
|
469
|
+
|
|
470
|
+
this.match(mql, drawer); // Conditionally use addListner() for IE11 support
|
|
471
|
+
|
|
472
|
+
if (typeof mql.addEventListener === 'function') {
|
|
473
|
+
mql.addEventListener('change', this.__check);
|
|
474
|
+
} else {
|
|
475
|
+
mql.addListener(this.__check);
|
|
476
|
+
} // Push to mediaQueryLists array along with drawer ID
|
|
477
|
+
|
|
478
|
+
|
|
517
479
|
this.mediaQueryLists.push({
|
|
518
480
|
'mql': mql,
|
|
519
481
|
'drawer': id
|
|
@@ -549,9 +511,9 @@ class Breakpoint {
|
|
|
549
511
|
|
|
550
512
|
match(mql, drawer) {
|
|
551
513
|
if (mql.matches) {
|
|
552
|
-
switchToDefault(drawer
|
|
514
|
+
this.parent.switchToDefault(drawer);
|
|
553
515
|
} else {
|
|
554
|
-
switchToModal(drawer
|
|
516
|
+
this.parent.switchToModal(drawer);
|
|
555
517
|
}
|
|
556
518
|
}
|
|
557
519
|
|
|
@@ -576,6 +538,41 @@ class Breakpoint {
|
|
|
576
538
|
|
|
577
539
|
}
|
|
578
540
|
|
|
541
|
+
function getDrawer(drawerKey) {
|
|
542
|
+
if (typeof drawerKey !== 'string') return drawerKey;
|
|
543
|
+
return document.querySelector(`[data-${this.settings.dataDrawer}="${drawerKey}"]`);
|
|
544
|
+
}
|
|
545
|
+
function drawerNotFound(key) {
|
|
546
|
+
return Promise.reject(new Error(`Did not find drawer with key: "${key}"`));
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
async function close$2(drawerKey) {
|
|
550
|
+
const drawer = this.getDrawer(drawerKey);
|
|
551
|
+
if (!drawer) return drawerNotFound(drawerKey);
|
|
552
|
+
|
|
553
|
+
if (hasClass(drawer, this.settings.stateOpened)) {
|
|
554
|
+
this.working = true;
|
|
555
|
+
|
|
556
|
+
if (hasClass(drawer, this.settings.classModal)) {
|
|
557
|
+
setInert(false, this.settings.selectorInert);
|
|
558
|
+
setOverflowHidden(false, this.settings.selectorOverflow);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
await closeTransition(drawer, this.settings);
|
|
562
|
+
this.stateSave(drawer);
|
|
563
|
+
focusTrigger(this);
|
|
564
|
+
this.focusTrap.destroy();
|
|
565
|
+
drawer.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'closed', {
|
|
566
|
+
detail: this,
|
|
567
|
+
bubbles: true
|
|
568
|
+
}));
|
|
569
|
+
this.working = false;
|
|
570
|
+
return drawer;
|
|
571
|
+
} else {
|
|
572
|
+
return drawer;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
579
576
|
function handlerClick$2(event) {
|
|
580
577
|
// Working catch
|
|
581
578
|
if (this.working) return; // Toggle data trigger
|
|
@@ -638,6 +635,39 @@ function handlerKeydown$2(event) {
|
|
|
638
635
|
}
|
|
639
636
|
}
|
|
640
637
|
|
|
638
|
+
async function open$2(drawerKey) {
|
|
639
|
+
const drawer = this.getDrawer(drawerKey);
|
|
640
|
+
if (!drawer) return drawerNotFound(drawerKey);
|
|
641
|
+
|
|
642
|
+
if (!hasClass(drawer, this.settings.stateOpened)) {
|
|
643
|
+
this.working = true;
|
|
644
|
+
const isModal = hasClass(drawer, this.settings.classModal);
|
|
645
|
+
|
|
646
|
+
if (isModal) {
|
|
647
|
+
setOverflowHidden(true, this.settings.selectorOverflow);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
await openTransition(drawer, this.settings);
|
|
651
|
+
this.stateSave(drawer);
|
|
652
|
+
|
|
653
|
+
if (isModal) {
|
|
654
|
+
this.focusTrap.init(drawer);
|
|
655
|
+
setInert(true, this.settings.selectorInert);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
focusTarget(drawer, this.settings);
|
|
659
|
+
drawer.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'opened', {
|
|
660
|
+
detail: this,
|
|
661
|
+
bubbles: true
|
|
662
|
+
}));
|
|
663
|
+
this.working = false;
|
|
664
|
+
return drawer;
|
|
665
|
+
} else {
|
|
666
|
+
focusTarget(drawer, this.settings);
|
|
667
|
+
return drawer;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
|
|
641
671
|
function stateSet(settings) {
|
|
642
672
|
// If save state is disabled
|
|
643
673
|
if (!settings.stateSave) return stateClear(settings); // If there isn't an existing state to set
|
|
@@ -682,6 +712,59 @@ function stateClear(settings) {
|
|
|
682
712
|
return {};
|
|
683
713
|
}
|
|
684
714
|
|
|
715
|
+
async function switchToModal(drawerKey) {
|
|
716
|
+
// Initial guards
|
|
717
|
+
const drawer = this.getDrawer(drawerKey);
|
|
718
|
+
if (!drawer) return drawerNotFound(drawerKey);
|
|
719
|
+
if (hasClass(drawer, this.settings.classModal)) return; // Enable modal state
|
|
720
|
+
|
|
721
|
+
addClass(drawer, this.settings.classModal);
|
|
722
|
+
addClass(drawer, this.settings.stateClosed);
|
|
723
|
+
removeClass(drawer, this.settings.stateOpened); // Dispatch custom event
|
|
724
|
+
|
|
725
|
+
drawer.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'toModal', {
|
|
726
|
+
bubbles: true
|
|
727
|
+
}));
|
|
728
|
+
return drawer;
|
|
729
|
+
}
|
|
730
|
+
async function switchToDefault(drawerKey) {
|
|
731
|
+
// Initial guards
|
|
732
|
+
const drawer = this.getDrawer(drawerKey);
|
|
733
|
+
if (!drawer) return drawerNotFound(drawerKey);
|
|
734
|
+
if (!hasClass(drawer, this.settings.classModal)) return; // Tear down modal state
|
|
735
|
+
|
|
736
|
+
setInert(false, this.settings.selectorInert);
|
|
737
|
+
setOverflowHidden(false, this.settings.selectorOverflow);
|
|
738
|
+
removeClass(drawer, this.settings.classModal);
|
|
739
|
+
this.focusTrap.destroy(); // Restore drawers saved state
|
|
740
|
+
|
|
741
|
+
drawerKey = drawer.getAttribute(`data-${this.settings.dataDrawer}`);
|
|
742
|
+
const drawerState = this.state[drawerKey];
|
|
743
|
+
|
|
744
|
+
if (drawerState == this.settings.stateOpened) {
|
|
745
|
+
addClass(drawer, this.settings.stateOpened);
|
|
746
|
+
removeClass(drawer, this.settings.stateClosed);
|
|
747
|
+
} // Dispatch custom event
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
drawer.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'toDefault', {
|
|
751
|
+
bubbles: true
|
|
752
|
+
}));
|
|
753
|
+
return drawer;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
async function toggle(drawerKey) {
|
|
757
|
+
const drawer = this.getDrawer(drawerKey);
|
|
758
|
+
if (!drawer) return drawerNotFound(drawerKey);
|
|
759
|
+
const isClosed = !hasClass(drawer, this.settings.stateOpened);
|
|
760
|
+
|
|
761
|
+
if (isClosed) {
|
|
762
|
+
return this.open(drawer);
|
|
763
|
+
} else {
|
|
764
|
+
return this.close(drawer);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
685
768
|
class Drawer {
|
|
686
769
|
constructor(options) {
|
|
687
770
|
this.defaults = defaults$2;
|
|
@@ -743,20 +826,14 @@ class Drawer {
|
|
|
743
826
|
|
|
744
827
|
|
|
745
828
|
getDrawer(drawerKey) {
|
|
746
|
-
|
|
747
|
-
return document.querySelector(`[data-${this.settings.dataDrawer}="${drawerKey}"]`);
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
drawerNotFound(key) {
|
|
751
|
-
return Promise.reject(new Error(`Did not find drawer with key: "${key}"`));
|
|
829
|
+
return getDrawer.call(this, drawerKey);
|
|
752
830
|
}
|
|
753
831
|
|
|
754
832
|
setTabindex() {
|
|
755
|
-
|
|
833
|
+
return setTabindex(`
|
|
756
834
|
[data-${this.settings.dataDrawer}]
|
|
757
835
|
[data-${this.settings.dataDialog}]
|
|
758
|
-
|
|
759
|
-
setTabindex(selectorTabindex);
|
|
836
|
+
`);
|
|
760
837
|
}
|
|
761
838
|
/**
|
|
762
839
|
* Save state functionality
|
|
@@ -780,87 +857,27 @@ class Drawer {
|
|
|
780
857
|
|
|
781
858
|
|
|
782
859
|
switchToDefault(drawerKey) {
|
|
783
|
-
return switchToDefault(
|
|
860
|
+
return switchToDefault.call(this, drawerKey);
|
|
784
861
|
}
|
|
785
862
|
|
|
786
863
|
switchToModal(drawerKey) {
|
|
787
|
-
return switchToModal(
|
|
864
|
+
return switchToModal.call(this, drawerKey);
|
|
788
865
|
}
|
|
789
866
|
/**
|
|
790
867
|
* Change state functionality
|
|
791
868
|
*/
|
|
792
869
|
|
|
793
870
|
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
if (!drawer) return this.drawerNotFound(drawerKey);
|
|
797
|
-
const isClosed = !hasClass(drawer, this.settings.stateOpened);
|
|
798
|
-
|
|
799
|
-
if (isClosed) {
|
|
800
|
-
return this.open(drawer);
|
|
801
|
-
} else {
|
|
802
|
-
return this.close(drawer);
|
|
803
|
-
}
|
|
871
|
+
toggle(drawerKey) {
|
|
872
|
+
return toggle.call(this, drawerKey);
|
|
804
873
|
}
|
|
805
874
|
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
if (!drawer) return this.drawerNotFound(drawerKey);
|
|
809
|
-
|
|
810
|
-
if (!hasClass(drawer, this.settings.stateOpened)) {
|
|
811
|
-
this.working = true;
|
|
812
|
-
const isModal = hasClass(drawer, this.settings.classModal);
|
|
813
|
-
|
|
814
|
-
if (isModal) {
|
|
815
|
-
setOverflowHidden(true, this.settings.selectorOverflow);
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
await openTransition(drawer, this.settings);
|
|
819
|
-
this.stateSave(drawer);
|
|
820
|
-
|
|
821
|
-
if (isModal) {
|
|
822
|
-
this.focusTrap.init(drawer);
|
|
823
|
-
setInert(true, this.settings.selectorInert);
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
focusTarget(drawer, this.settings);
|
|
827
|
-
drawer.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'opened', {
|
|
828
|
-
detail: this,
|
|
829
|
-
bubbles: true
|
|
830
|
-
}));
|
|
831
|
-
this.working = false;
|
|
832
|
-
return drawer;
|
|
833
|
-
} else {
|
|
834
|
-
focusTarget(drawer, this.settings);
|
|
835
|
-
return drawer;
|
|
836
|
-
}
|
|
875
|
+
open(drawerKey) {
|
|
876
|
+
return open$2.call(this, drawerKey);
|
|
837
877
|
}
|
|
838
878
|
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
if (!drawer) return this.drawerNotFound(drawerKey);
|
|
842
|
-
|
|
843
|
-
if (hasClass(drawer, this.settings.stateOpened)) {
|
|
844
|
-
this.working = true;
|
|
845
|
-
|
|
846
|
-
if (hasClass(drawer, this.settings.classModal)) {
|
|
847
|
-
setInert(false, this.settings.selectorInert);
|
|
848
|
-
setOverflowHidden(false, this.settings.selectorOverflow);
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
await closeTransition(drawer, this.settings);
|
|
852
|
-
this.stateSave(drawer);
|
|
853
|
-
focusTrigger(this);
|
|
854
|
-
this.focusTrap.destroy();
|
|
855
|
-
drawer.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'closed', {
|
|
856
|
-
detail: this,
|
|
857
|
-
bubbles: true
|
|
858
|
-
}));
|
|
859
|
-
this.working = false;
|
|
860
|
-
return drawer;
|
|
861
|
-
} else {
|
|
862
|
-
return drawer;
|
|
863
|
-
}
|
|
879
|
+
close(drawerKey) {
|
|
880
|
+
return close$2.call(this, drawerKey);
|
|
864
881
|
}
|
|
865
882
|
|
|
866
883
|
}
|
|
@@ -893,6 +910,27 @@ var defaults$1 = {
|
|
|
893
910
|
transition: true
|
|
894
911
|
};
|
|
895
912
|
|
|
913
|
+
async function close$1(returnFocus = true) {
|
|
914
|
+
const modal = document.querySelector(`[data-${this.settings.dataModal}].${this.settings.stateOpened}`);
|
|
915
|
+
|
|
916
|
+
if (modal) {
|
|
917
|
+
this.working = true;
|
|
918
|
+
setInert(false, this.settings.selectorInert);
|
|
919
|
+
setOverflowHidden(false, this.settings.selectorOverflow);
|
|
920
|
+
await closeTransition(modal, this.settings);
|
|
921
|
+
if (returnFocus) focusTrigger(this);
|
|
922
|
+
this.focusTrap.destroy();
|
|
923
|
+
modal.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'closed', {
|
|
924
|
+
detail: this,
|
|
925
|
+
bubbles: true
|
|
926
|
+
}));
|
|
927
|
+
this.working = false;
|
|
928
|
+
return modal;
|
|
929
|
+
} else {
|
|
930
|
+
return modal;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
|
|
896
934
|
async function handlerClick$1(event) {
|
|
897
935
|
// Working catch
|
|
898
936
|
if (this.working) return; // Trigger click
|
|
@@ -935,21 +973,57 @@ function handlerKeydown$1(event) {
|
|
|
935
973
|
}
|
|
936
974
|
}
|
|
937
975
|
|
|
938
|
-
function
|
|
939
|
-
|
|
976
|
+
function getModal(modalKey) {
|
|
977
|
+
if (typeof modalKey !== 'string') return modalKey;
|
|
978
|
+
return document.querySelector(`[data-${this.settings.dataModal}="${modalKey}"]`);
|
|
979
|
+
}
|
|
980
|
+
function modalNotFound(key) {
|
|
981
|
+
return Promise.reject(new Error(`Did not find modal with key: "${key}"`));
|
|
982
|
+
}
|
|
983
|
+
function moveModals(type = this.settings.moveModals.type, ref = this.settings.moveModals.ref) {
|
|
984
|
+
const modals = document.querySelectorAll(`[data-${this.settings.dataModal}]`);
|
|
985
|
+
if (modals.length) moveElement(modals, type, ref);
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
function setInitialState() {
|
|
989
|
+
const modals = document.querySelectorAll(`[data-${this.settings.dataModal}]`);
|
|
940
990
|
modals.forEach(el => {
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
991
|
+
// Remove opened state setup
|
|
992
|
+
if (el.classList.contains(this.settings.stateOpened)) {
|
|
993
|
+
setInert(false, this.settings.selectorInert);
|
|
994
|
+
setOverflowHidden(false, this.settings.selectorOverflow);
|
|
995
|
+
focusTrigger(this);
|
|
996
|
+
this.focusTrap.destroy();
|
|
997
|
+
} // Remove all state classes and add the default state (closed)
|
|
947
998
|
|
|
948
|
-
|
|
949
|
-
|
|
999
|
+
|
|
1000
|
+
removeClass(el, this.settings.stateOpened, this.settings.stateOpening, this.settings.stateClosing);
|
|
1001
|
+
addClass(el, this.settings.stateClosed);
|
|
950
1002
|
});
|
|
951
1003
|
}
|
|
952
1004
|
|
|
1005
|
+
async function open$1(modalKey) {
|
|
1006
|
+
const modal = getModal.call(this, modalKey);
|
|
1007
|
+
if (!modal) return modalNotFound(modalKey);
|
|
1008
|
+
|
|
1009
|
+
if (hasClass(modal, this.settings.stateClosed)) {
|
|
1010
|
+
this.working = true;
|
|
1011
|
+
setOverflowHidden(true, this.settings.selectorOverflow);
|
|
1012
|
+
await openTransition(modal, this.settings);
|
|
1013
|
+
this.focusTrap.init(modal);
|
|
1014
|
+
focusTarget(modal, this.settings);
|
|
1015
|
+
setInert(true, this.settings.selectorInert);
|
|
1016
|
+
modal.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'opened', {
|
|
1017
|
+
detail: this,
|
|
1018
|
+
bubbles: true
|
|
1019
|
+
}));
|
|
1020
|
+
this.working = false;
|
|
1021
|
+
return modal;
|
|
1022
|
+
} else {
|
|
1023
|
+
return modal;
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
|
|
953
1027
|
class Modal {
|
|
954
1028
|
constructor(options) {
|
|
955
1029
|
this.defaults = defaults$1;
|
|
@@ -965,13 +1039,12 @@ class Modal {
|
|
|
965
1039
|
init(options = null) {
|
|
966
1040
|
if (options) this.settings = _extends({}, this.settings, options);
|
|
967
1041
|
this.moveModals();
|
|
1042
|
+
this.setInitialState();
|
|
968
1043
|
|
|
969
1044
|
if (this.settings.setTabindex) {
|
|
970
1045
|
this.setTabindex();
|
|
971
1046
|
}
|
|
972
1047
|
|
|
973
|
-
this.setInitialState();
|
|
974
|
-
|
|
975
1048
|
if (this.settings.eventListeners) {
|
|
976
1049
|
this.initEventListeners();
|
|
977
1050
|
}
|
|
@@ -1006,99 +1079,105 @@ class Modal {
|
|
|
1006
1079
|
|
|
1007
1080
|
|
|
1008
1081
|
getModal(modalKey) {
|
|
1009
|
-
|
|
1010
|
-
return document.querySelector(`[data-${this.settings.dataModal}="${modalKey}"]`);
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
modalNotFound(key) {
|
|
1014
|
-
return Promise.reject(new Error(`Did not find modal with key: "${key}"`));
|
|
1082
|
+
return getModal.call(this, modalKey);
|
|
1015
1083
|
}
|
|
1016
1084
|
|
|
1017
1085
|
setTabindex() {
|
|
1018
|
-
|
|
1086
|
+
return setTabindex(`
|
|
1019
1087
|
[data-${this.settings.dataModal}]
|
|
1020
1088
|
[data-${this.settings.dataDialog}]
|
|
1021
|
-
|
|
1022
|
-
setTabindex(selectorTabindex);
|
|
1089
|
+
`);
|
|
1023
1090
|
}
|
|
1024
1091
|
|
|
1025
1092
|
setInitialState() {
|
|
1026
|
-
setInitialState(this);
|
|
1093
|
+
return setInitialState.call(this);
|
|
1027
1094
|
}
|
|
1028
1095
|
|
|
1029
|
-
moveModals(type
|
|
1030
|
-
|
|
1031
|
-
if (modals.length) moveElement(modals, type, ref);
|
|
1096
|
+
moveModals(type, ref) {
|
|
1097
|
+
return moveModals.call(this, type, ref);
|
|
1032
1098
|
}
|
|
1033
1099
|
/**
|
|
1034
1100
|
* Change state functionality
|
|
1035
1101
|
*/
|
|
1036
1102
|
|
|
1037
1103
|
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1104
|
+
open(modalKey) {
|
|
1105
|
+
return open$1.call(this, modalKey);
|
|
1106
|
+
}
|
|
1041
1107
|
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1108
|
+
close(returnFocus) {
|
|
1109
|
+
return close$1.call(this, returnFocus);
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
class Collection {
|
|
1115
|
+
constructor() {
|
|
1116
|
+
this.collection = [];
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
register(item) {
|
|
1120
|
+
this.deregister(item);
|
|
1121
|
+
this.collection.push(item);
|
|
1122
|
+
return this.collection;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
deregister(ref) {
|
|
1126
|
+
const index = this.collection.findIndex(entry => {
|
|
1127
|
+
return entry === ref;
|
|
1128
|
+
});
|
|
1129
|
+
|
|
1130
|
+
if (index >= 0) {
|
|
1131
|
+
const entry = this.collection[index];
|
|
1132
|
+
Object.getOwnPropertyNames(entry).forEach(prop => {
|
|
1133
|
+
delete entry[prop];
|
|
1134
|
+
});
|
|
1135
|
+
this.collection.splice(index, 1);
|
|
1057
1136
|
}
|
|
1137
|
+
|
|
1138
|
+
return this.collection;
|
|
1058
1139
|
}
|
|
1059
1140
|
|
|
1060
|
-
|
|
1061
|
-
|
|
1141
|
+
registerCollection(items) {
|
|
1142
|
+
items.forEach(item => {
|
|
1143
|
+
this.register(item);
|
|
1144
|
+
});
|
|
1145
|
+
return this.collection;
|
|
1146
|
+
}
|
|
1062
1147
|
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
setOverflowHidden(false, this.settings.selectorOverflow);
|
|
1067
|
-
await closeTransition(modal, this.settings);
|
|
1068
|
-
if (returnFocus) focusTrigger(this);
|
|
1069
|
-
this.focusTrap.destroy();
|
|
1070
|
-
modal.dispatchEvent(new CustomEvent(this.settings.customEventPrefix + 'closed', {
|
|
1071
|
-
detail: this,
|
|
1072
|
-
bubbles: true
|
|
1073
|
-
}));
|
|
1074
|
-
this.working = false;
|
|
1075
|
-
return modal;
|
|
1076
|
-
} else {
|
|
1077
|
-
return modal;
|
|
1148
|
+
deregisterCollection() {
|
|
1149
|
+
while (this.collection.length > 0) {
|
|
1150
|
+
this.deregister(this.collection[0]);
|
|
1078
1151
|
}
|
|
1152
|
+
|
|
1153
|
+
return this.collection;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
get(query, key = 'id') {
|
|
1157
|
+
const result = this.collection.find(item => {
|
|
1158
|
+
return item[key] === query;
|
|
1159
|
+
});
|
|
1160
|
+
return result || null;
|
|
1079
1161
|
}
|
|
1080
1162
|
|
|
1081
1163
|
}
|
|
1082
1164
|
|
|
1083
1165
|
var defaults = {
|
|
1084
1166
|
autoInit: false,
|
|
1085
|
-
//
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
dataArrow: 'popover-arrow',
|
|
1089
|
-
dataEventType: 'popover-event',
|
|
1090
|
-
dataPlacement: 'popover-placement',
|
|
1167
|
+
// Selectors
|
|
1168
|
+
selectorPopover: '.popover',
|
|
1169
|
+
selectorArrow: '.popover__arrow',
|
|
1091
1170
|
// State classes
|
|
1092
1171
|
stateActive: 'is-active',
|
|
1093
1172
|
// Feature toggles
|
|
1094
|
-
eventType: 'click',
|
|
1095
1173
|
eventListeners: true,
|
|
1096
|
-
|
|
1174
|
+
eventType: 'click',
|
|
1175
|
+
placement: 'bottom'
|
|
1097
1176
|
};
|
|
1098
1177
|
|
|
1099
|
-
function
|
|
1178
|
+
function close(popover) {
|
|
1100
1179
|
// Update state class
|
|
1101
|
-
popover.target.classList.remove(
|
|
1180
|
+
popover.target.classList.remove(this.settings.stateActive); // Update a11y attributes
|
|
1102
1181
|
|
|
1103
1182
|
popover.trigger.setAttribute('aria-expanded', 'false'); // Disable popper event listeners
|
|
1104
1183
|
|
|
@@ -1107,41 +1186,38 @@ function hide$2(popover, obj) {
|
|
|
1107
1186
|
name: 'eventListeners',
|
|
1108
1187
|
enabled: false
|
|
1109
1188
|
}]
|
|
1110
|
-
}); // Update
|
|
1189
|
+
}); // Update popover state
|
|
1111
1190
|
|
|
1112
|
-
|
|
1113
|
-
return item.target === popover.target;
|
|
1114
|
-
});
|
|
1115
|
-
obj.collection[index].state = 'hide'; // Clear the memory if popover trigger matches the ones saved in memory
|
|
1191
|
+
popover.state = 'closed'; // Clear memory if popover trigger matches the one saved in memory
|
|
1116
1192
|
|
|
1117
|
-
if (popover.trigger ===
|
|
1118
|
-
|
|
1193
|
+
if (popover.trigger === this.memory.trigger) {
|
|
1194
|
+
this.memory.trigger = null;
|
|
1119
1195
|
} // Return the popover
|
|
1120
1196
|
|
|
1121
1197
|
|
|
1122
1198
|
return popover;
|
|
1123
1199
|
}
|
|
1124
|
-
function
|
|
1125
|
-
|
|
1126
|
-
if (popover.state === '
|
|
1127
|
-
|
|
1200
|
+
function closeAll() {
|
|
1201
|
+
this.collection.forEach(popover => {
|
|
1202
|
+
if (popover.state === 'opened') {
|
|
1203
|
+
popover.close();
|
|
1128
1204
|
}
|
|
1129
1205
|
}); // Return the collection
|
|
1130
1206
|
|
|
1131
|
-
return
|
|
1207
|
+
return this.collection;
|
|
1132
1208
|
}
|
|
1133
|
-
function
|
|
1134
|
-
// Only run
|
|
1135
|
-
if (popover.state != '
|
|
1209
|
+
function closeCheck(popover) {
|
|
1210
|
+
// Only run closeCheck if provided popover is currently open
|
|
1211
|
+
if (popover.state != 'opened') return; // Needed to correctly check which element is currently being focused
|
|
1136
1212
|
|
|
1137
1213
|
setTimeout(() => {
|
|
1138
1214
|
// Check if trigger or target are being hovered
|
|
1139
1215
|
const isHovered = popover.target.closest(':hover') === popover.target || popover.trigger.closest(':hover') === popover.trigger; // Check if trigger or target are being focused
|
|
1140
1216
|
|
|
1141
|
-
const isFocused = document.activeElement.closest(
|
|
1217
|
+
const isFocused = document.activeElement.closest(`#${popover.id}, [aria-controls="${popover.id}"]`); // Close if the trigger and target are not currently hovered or focused
|
|
1142
1218
|
|
|
1143
1219
|
if (!isHovered && !isFocused) {
|
|
1144
|
-
|
|
1220
|
+
popover.close();
|
|
1145
1221
|
} // Return the popover
|
|
1146
1222
|
|
|
1147
1223
|
|
|
@@ -1149,6 +1225,57 @@ function hideCheck(popover, obj) {
|
|
|
1149
1225
|
}, 1);
|
|
1150
1226
|
}
|
|
1151
1227
|
|
|
1228
|
+
function handlerClick(popover) {
|
|
1229
|
+
if (popover.target.classList.contains(this.settings.stateActive)) {
|
|
1230
|
+
popover.close();
|
|
1231
|
+
} else {
|
|
1232
|
+
this.memory.trigger = popover.trigger;
|
|
1233
|
+
popover.open();
|
|
1234
|
+
documentClick.call(this, popover);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
function handlerKeydown(event) {
|
|
1238
|
+
switch (event.key) {
|
|
1239
|
+
case 'Escape':
|
|
1240
|
+
if (this.memory.trigger) {
|
|
1241
|
+
this.memory.trigger.focus();
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
closeAll.call(this);
|
|
1245
|
+
return;
|
|
1246
|
+
|
|
1247
|
+
case 'Tab':
|
|
1248
|
+
this.collection.forEach(popover => {
|
|
1249
|
+
closeCheck.call(this, popover);
|
|
1250
|
+
});
|
|
1251
|
+
return;
|
|
1252
|
+
|
|
1253
|
+
default:
|
|
1254
|
+
return;
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
function documentClick(popover) {
|
|
1258
|
+
const root = this;
|
|
1259
|
+
document.addEventListener('click', function _f(event) {
|
|
1260
|
+
// Check if a popover was clicked
|
|
1261
|
+
const result = event.target.closest(`#${popover.id}, [aria-controls="${popover.id}"]`);
|
|
1262
|
+
|
|
1263
|
+
if (!result) {
|
|
1264
|
+
// If it doesn't match and popover is open, close it and remove event listener
|
|
1265
|
+
if (popover.target && popover.target.classList.contains(root.settings.stateActive)) {
|
|
1266
|
+
popover.close();
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
this.removeEventListener('click', _f);
|
|
1270
|
+
} else {
|
|
1271
|
+
// If it does match and popover isn't currently active, remove event listener
|
|
1272
|
+
if (popover.target && !popover.target.classList.contains(root.settings.stateActive)) {
|
|
1273
|
+
this.removeEventListener('click', _f);
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
});
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1152
1279
|
function getConfig(el, settings) {
|
|
1153
1280
|
// Get the computed styles of the popover
|
|
1154
1281
|
const styles = getComputedStyle(el); // Setup the config obj with default values
|
|
@@ -1159,26 +1286,23 @@ function getConfig(el, settings) {
|
|
|
1159
1286
|
'offset': 0,
|
|
1160
1287
|
'overflow-padding': 0,
|
|
1161
1288
|
'flip-padding': 0,
|
|
1162
|
-
'arrow-element':
|
|
1289
|
+
'arrow-element': settings.selectorArrow,
|
|
1163
1290
|
'arrow-padding': 0
|
|
1164
1291
|
}; // Loop through config obj
|
|
1165
1292
|
|
|
1166
1293
|
for (const prop in config) {
|
|
1167
1294
|
// Get the CSS variable property values
|
|
1168
1295
|
const prefix = getComputedStyle(document.body).getPropertyValue('--vrembem-variable-prefix');
|
|
1169
|
-
const
|
|
1296
|
+
const value = styles.getPropertyValue(`--${prefix}popover-${prop}`).trim(); // If a value was found, replace the default in config obj
|
|
1170
1297
|
|
|
1171
|
-
if (
|
|
1172
|
-
config[prop] =
|
|
1298
|
+
if (value) {
|
|
1299
|
+
config[prop] = value;
|
|
1173
1300
|
}
|
|
1174
1301
|
} // Return the config obj
|
|
1175
1302
|
|
|
1176
1303
|
|
|
1177
1304
|
return config;
|
|
1178
1305
|
}
|
|
1179
|
-
function getData(el, attr, fallback = false) {
|
|
1180
|
-
return el.hasAttribute(`data-${attr}`) ? el.getAttribute(`data-${attr}`) : fallback;
|
|
1181
|
-
}
|
|
1182
1306
|
function getPadding(value) {
|
|
1183
1307
|
let padding; // Split the value by spaces if it's a string
|
|
1184
1308
|
|
|
@@ -1252,95 +1376,53 @@ function getModifiers(options) {
|
|
|
1252
1376
|
}
|
|
1253
1377
|
}];
|
|
1254
1378
|
}
|
|
1255
|
-
function
|
|
1256
|
-
//
|
|
1257
|
-
|
|
1379
|
+
function getPopoverID(obj) {
|
|
1380
|
+
// If it's a string
|
|
1381
|
+
if (typeof obj === 'string') {
|
|
1382
|
+
return obj;
|
|
1383
|
+
} // If it's an HTML element
|
|
1384
|
+
else if (typeof obj.hasAttribute === 'function') {
|
|
1385
|
+
// If it's a popover trigger
|
|
1386
|
+
if (obj.hasAttribute('aria-controls')) {
|
|
1387
|
+
return obj.getAttribute('aria-controls');
|
|
1388
|
+
} // If it's a popover target
|
|
1389
|
+
else if (obj.closest(this.settings.selectorPopover)) {
|
|
1390
|
+
return obj.id;
|
|
1391
|
+
} // Return false if no id was found
|
|
1392
|
+
else return false;
|
|
1393
|
+
} // If it has an ID property
|
|
1394
|
+
else if (obj.id) {
|
|
1395
|
+
return obj.id;
|
|
1396
|
+
} // Return false if no id was found
|
|
1397
|
+
else return false;
|
|
1398
|
+
}
|
|
1399
|
+
function getPopoverElements(query) {
|
|
1400
|
+
const id = getPopoverID.call(this, query);
|
|
1258
1401
|
|
|
1259
1402
|
if (id) {
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1272
|
-
function show(popover, obj) {
|
|
1273
|
-
// Update state class
|
|
1274
|
-
popover.target.classList.add(obj.settings.stateActive); // Update a11y attributes
|
|
1275
|
-
|
|
1276
|
-
popover.trigger.setAttribute('aria-expanded', 'true'); // Update popover config
|
|
1277
|
-
|
|
1278
|
-
popover.config = getConfig(popover.target, obj.settings); // Enable popper event listeners and set placement/modifiers
|
|
1279
|
-
|
|
1280
|
-
popover.popper.setOptions({
|
|
1281
|
-
placement: getData(popover.target, obj.settings.dataPlacement, popover.config['placement']),
|
|
1282
|
-
modifiers: [{
|
|
1283
|
-
name: 'eventListeners',
|
|
1284
|
-
enabled: true
|
|
1285
|
-
}, ...getModifiers(popover.config)]
|
|
1286
|
-
}); // Update popover's position
|
|
1287
|
-
|
|
1288
|
-
popover.popper.update(); // Update collection status with new state
|
|
1289
|
-
|
|
1290
|
-
const index = obj.collection.findIndex(item => {
|
|
1291
|
-
return item.target === popover.target;
|
|
1292
|
-
});
|
|
1293
|
-
obj.collection[index].state = 'show'; // Return the popover
|
|
1294
|
-
|
|
1295
|
-
return popover;
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
function handlerClick(popover) {
|
|
1299
|
-
if (popover.target.classList.contains(this.settings.stateActive)) {
|
|
1300
|
-
hide$2(popover, this);
|
|
1301
|
-
} else {
|
|
1302
|
-
this.memory.trigger = popover.trigger;
|
|
1303
|
-
show(popover, this);
|
|
1304
|
-
documentClick(popover, this);
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
function handlerKeydown(event) {
|
|
1308
|
-
switch (event.key) {
|
|
1309
|
-
case 'Escape':
|
|
1310
|
-
if (this.memory.trigger) {
|
|
1311
|
-
this.memory.trigger.focus();
|
|
1312
|
-
}
|
|
1313
|
-
|
|
1314
|
-
hideAll(this);
|
|
1315
|
-
return;
|
|
1316
|
-
|
|
1317
|
-
case 'Tab':
|
|
1318
|
-
this.collection.forEach(popover => {
|
|
1319
|
-
hideCheck(popover, this);
|
|
1320
|
-
});
|
|
1321
|
-
return;
|
|
1322
|
-
|
|
1323
|
-
default:
|
|
1324
|
-
return;
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
function documentClick(popover, obj) {
|
|
1328
|
-
document.addEventListener('click', function _f(event) {
|
|
1329
|
-
const result = event.target.closest(`[data-${obj.settings.dataPopover}], [data-${obj.settings.dataTrigger}]`);
|
|
1330
|
-
const match = result === popover.target || result === popover.trigger;
|
|
1331
|
-
|
|
1332
|
-
if (!match) {
|
|
1333
|
-
if (popover.target.classList.contains(obj.settings.stateActive)) {
|
|
1334
|
-
hide$2(popover, obj);
|
|
1335
|
-
}
|
|
1403
|
+
const trigger = document.querySelector(`[aria-controls="${id}"]`);
|
|
1404
|
+
const target = document.querySelector(`#${id}`);
|
|
1405
|
+
|
|
1406
|
+
if (!trigger && !target) {
|
|
1407
|
+
console.error('No popover elements found using the provided ID:', id);
|
|
1408
|
+
} else if (!trigger) {
|
|
1409
|
+
console.error('No popover trigger associated with the provided popover:', target);
|
|
1410
|
+
} else if (!target) {
|
|
1411
|
+
console.error('No popover associated with the provided popover trigger:', trigger);
|
|
1412
|
+
}
|
|
1336
1413
|
|
|
1337
|
-
|
|
1414
|
+
if (!trigger || !target) {
|
|
1415
|
+
return false;
|
|
1338
1416
|
} else {
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1417
|
+
return {
|
|
1418
|
+
trigger,
|
|
1419
|
+
target
|
|
1420
|
+
};
|
|
1342
1421
|
}
|
|
1343
|
-
}
|
|
1422
|
+
} else {
|
|
1423
|
+
console.error('Could not resolve the popover ID:', query);
|
|
1424
|
+
return false;
|
|
1425
|
+
}
|
|
1344
1426
|
}
|
|
1345
1427
|
|
|
1346
1428
|
var top = 'top';
|
|
@@ -3126,95 +3208,120 @@ var createPopper = /*#__PURE__*/popperGenerator({
|
|
|
3126
3208
|
defaultModifiers: defaultModifiers
|
|
3127
3209
|
}); // eslint-disable-next-line import/no-unused-modules
|
|
3128
3210
|
|
|
3129
|
-
function
|
|
3130
|
-
//
|
|
3131
|
-
|
|
3132
|
-
// Try and get the target
|
|
3133
|
-
target = getPopover(trigger, obj.settings); // If still no target is returned, log an error and return false
|
|
3211
|
+
function open(popover) {
|
|
3212
|
+
// Update state class
|
|
3213
|
+
popover.target.classList.add(this.settings.stateActive); // Update a11y attribute
|
|
3134
3214
|
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3215
|
+
popover.trigger.setAttribute('aria-expanded', 'true'); // Update popover config
|
|
3216
|
+
|
|
3217
|
+
popover.config = getConfig(popover.target, this.settings); // Enable popper event listeners and set placement/modifiers
|
|
3218
|
+
|
|
3219
|
+
popover.popper.setOptions({
|
|
3220
|
+
placement: popover.config['placement'],
|
|
3221
|
+
modifiers: [{
|
|
3222
|
+
name: 'eventListeners',
|
|
3223
|
+
enabled: true
|
|
3224
|
+
}, ...getModifiers(popover.config)]
|
|
3225
|
+
}); // Update popover position
|
|
3140
3226
|
|
|
3227
|
+
popover.popper.update(); // Update popover state
|
|
3141
3228
|
|
|
3142
|
-
|
|
3143
|
-
return item.trigger === trigger && item.target === target;
|
|
3144
|
-
}); // Initiate popover variable
|
|
3229
|
+
popover.state = 'opened'; // Return the popover
|
|
3145
3230
|
|
|
3146
|
-
|
|
3231
|
+
return popover;
|
|
3232
|
+
}
|
|
3147
3233
|
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
const popperInstance = createPopper(trigger, target); // Build popover object and push to collection array
|
|
3234
|
+
function register(trigger, target) {
|
|
3235
|
+
// Deregister popover if it already exists in the collection
|
|
3236
|
+
this.deregister(target.id); // Create popper instance
|
|
3237
|
+
|
|
3238
|
+
const popperInstance = createPopper(trigger, target); // Save root this for use inside object & create methods API
|
|
3154
3239
|
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3240
|
+
const root = this;
|
|
3241
|
+
const methods = {
|
|
3242
|
+
open() {
|
|
3243
|
+
open.call(root, this);
|
|
3244
|
+
},
|
|
3245
|
+
|
|
3246
|
+
close() {
|
|
3247
|
+
close.call(root, this);
|
|
3248
|
+
},
|
|
3249
|
+
|
|
3250
|
+
deregister() {
|
|
3251
|
+
deregister.call(root, this);
|
|
3252
|
+
}
|
|
3162
3253
|
|
|
3163
|
-
|
|
3164
|
-
} // Setup event listeners
|
|
3254
|
+
}; // Build popover object and push to collection array
|
|
3165
3255
|
|
|
3256
|
+
const popover = _extends({
|
|
3257
|
+
id: target.id,
|
|
3258
|
+
state: 'closed',
|
|
3259
|
+
trigger: trigger,
|
|
3260
|
+
target: target,
|
|
3261
|
+
popper: popperInstance,
|
|
3262
|
+
config: getConfig(target, this.settings)
|
|
3263
|
+
}, methods); // Setup event listeners
|
|
3166
3264
|
|
|
3167
|
-
registerEventListeners(popover, obj); // Set initial state of popover
|
|
3168
3265
|
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3266
|
+
registerEventListeners.call(this, popover); // Set initial state of popover
|
|
3267
|
+
|
|
3268
|
+
if (popover.target.classList.contains(this.settings.stateActive)) {
|
|
3269
|
+
popover.open();
|
|
3270
|
+
documentClick.call(this, popover);
|
|
3172
3271
|
} else {
|
|
3173
|
-
|
|
3174
|
-
} //
|
|
3272
|
+
popover.close();
|
|
3273
|
+
} // Add item to collection
|
|
3175
3274
|
|
|
3176
3275
|
|
|
3276
|
+
this.collection.push(popover); // Return the popover object
|
|
3277
|
+
|
|
3177
3278
|
return popover;
|
|
3178
3279
|
}
|
|
3179
|
-
function deregister(popover
|
|
3280
|
+
function deregister(popover) {
|
|
3180
3281
|
// Check if this item has been registered in the collection
|
|
3181
|
-
const index =
|
|
3182
|
-
return
|
|
3183
|
-
}); // If the
|
|
3282
|
+
const index = this.collection.findIndex(entry => {
|
|
3283
|
+
return entry.id === popover.id;
|
|
3284
|
+
}); // If the entry exists in the collection
|
|
3184
3285
|
|
|
3185
3286
|
if (index >= 0) {
|
|
3186
|
-
//
|
|
3187
|
-
|
|
3188
|
-
|
|
3287
|
+
// Get the collection entry
|
|
3288
|
+
const entry = this.collection[index]; // Close the collection entry if it's open
|
|
3289
|
+
|
|
3290
|
+
if (entry.state === 'opened') {
|
|
3291
|
+
entry.close();
|
|
3189
3292
|
} // Clean up the popper instance
|
|
3190
3293
|
|
|
3191
3294
|
|
|
3192
|
-
|
|
3295
|
+
entry.popper.destroy(); // Remove event listeners
|
|
3193
3296
|
|
|
3194
|
-
deregisterEventListeners(
|
|
3297
|
+
deregisterEventListeners(entry); // Delete properties from collection entry
|
|
3195
3298
|
|
|
3196
|
-
|
|
3299
|
+
Object.getOwnPropertyNames(entry).forEach(prop => {
|
|
3300
|
+
delete entry[prop];
|
|
3301
|
+
}); // Remove entry from collection
|
|
3302
|
+
|
|
3303
|
+
this.collection.splice(index, 1);
|
|
3197
3304
|
} // Return the new collection
|
|
3198
3305
|
|
|
3199
3306
|
|
|
3200
|
-
return
|
|
3307
|
+
return this.collection;
|
|
3201
3308
|
}
|
|
3202
|
-
function registerEventListeners(popover
|
|
3309
|
+
function registerEventListeners(popover) {
|
|
3203
3310
|
// If event listeners aren't already setup
|
|
3204
3311
|
if (!popover.__eventListeners) {
|
|
3205
3312
|
// Add event listeners based on event type
|
|
3206
|
-
const eventType =
|
|
3313
|
+
const eventType = popover.config['event'];
|
|
3207
3314
|
|
|
3208
3315
|
if (eventType === 'hover') {
|
|
3209
3316
|
// Setup event listeners object for hover
|
|
3210
3317
|
popover.__eventListeners = [{
|
|
3211
3318
|
el: ['trigger'],
|
|
3212
3319
|
type: ['mouseenter', 'focus'],
|
|
3213
|
-
listener:
|
|
3320
|
+
listener: open.bind(this, popover)
|
|
3214
3321
|
}, {
|
|
3215
3322
|
el: ['trigger', 'target'],
|
|
3216
3323
|
type: ['mouseleave', 'focusout'],
|
|
3217
|
-
listener:
|
|
3324
|
+
listener: closeCheck.bind(this, popover)
|
|
3218
3325
|
}]; // Loop through listeners and apply to appropriate elements
|
|
3219
3326
|
|
|
3220
3327
|
popover.__eventListeners.forEach(evObj => {
|
|
@@ -3229,7 +3336,7 @@ function registerEventListeners(popover, obj) {
|
|
|
3229
3336
|
popover.__eventListeners = [{
|
|
3230
3337
|
el: ['trigger'],
|
|
3231
3338
|
type: ['click'],
|
|
3232
|
-
listener: handlerClick.bind(
|
|
3339
|
+
listener: handlerClick.bind(this, popover)
|
|
3233
3340
|
}]; // Loop through listeners and apply to appropriate elements
|
|
3234
3341
|
|
|
3235
3342
|
popover.__eventListeners.forEach(evObj => {
|
|
@@ -3264,31 +3371,13 @@ function deregisterEventListeners(popover) {
|
|
|
3264
3371
|
|
|
3265
3372
|
return popover;
|
|
3266
3373
|
}
|
|
3267
|
-
function registerCollection(obj) {
|
|
3268
|
-
// Get all the triggers
|
|
3269
|
-
const triggers = document.querySelectorAll(`[data-${obj.settings.dataTrigger}]`);
|
|
3270
|
-
triggers.forEach(trigger => {
|
|
3271
|
-
// Register the popover and save to collection array
|
|
3272
|
-
register(trigger, false, obj);
|
|
3273
|
-
}); // Return the popover collection
|
|
3274
|
-
|
|
3275
|
-
return obj.collection;
|
|
3276
|
-
}
|
|
3277
|
-
function deregisterCollection(obj) {
|
|
3278
|
-
// Loop through all items within the collection and pass them to deregister()
|
|
3279
|
-
while (obj.collection.length > 0) {
|
|
3280
|
-
deregister(obj.collection[0], obj);
|
|
3281
|
-
} // Return the popover collection
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
return obj.collection;
|
|
3285
|
-
}
|
|
3286
3374
|
|
|
3287
|
-
class Popover {
|
|
3375
|
+
class Popover extends Collection {
|
|
3288
3376
|
constructor(options) {
|
|
3377
|
+
super();
|
|
3289
3378
|
this.defaults = defaults;
|
|
3290
|
-
this.settings = _extends({}, this.defaults, options);
|
|
3291
|
-
|
|
3379
|
+
this.settings = _extends({}, this.defaults, options); // this.collection = [];
|
|
3380
|
+
|
|
3292
3381
|
this.memory = {
|
|
3293
3382
|
trigger: null
|
|
3294
3383
|
};
|
|
@@ -3298,9 +3387,11 @@ class Popover {
|
|
|
3298
3387
|
|
|
3299
3388
|
init(options = null) {
|
|
3300
3389
|
// Update settings with passed options
|
|
3301
|
-
if (options) this.settings = _extends({}, this.settings, options); //
|
|
3390
|
+
if (options) this.settings = _extends({}, this.settings, options); // Get all the popovers
|
|
3391
|
+
|
|
3392
|
+
const popovers = document.querySelectorAll(this.settings.selectorPopover); // Build the collections array with popover instances
|
|
3302
3393
|
|
|
3303
|
-
registerCollection(
|
|
3394
|
+
this.registerCollection(popovers); // If eventListeners is enabled
|
|
3304
3395
|
|
|
3305
3396
|
if (this.settings.eventListeners) {
|
|
3306
3397
|
// Pass false to initEventListeners() since registerCollection()
|
|
@@ -3311,7 +3402,7 @@ class Popover {
|
|
|
3311
3402
|
|
|
3312
3403
|
destroy() {
|
|
3313
3404
|
// Deregister all popovers from collection
|
|
3314
|
-
deregisterCollection(
|
|
3405
|
+
this.deregisterCollection(); // If eventListeners is enabled
|
|
3315
3406
|
|
|
3316
3407
|
if (this.settings.eventListeners) {
|
|
3317
3408
|
// Pass false to destroyEventListeners() since deregisterCollection()
|
|
@@ -3328,7 +3419,7 @@ class Popover {
|
|
|
3328
3419
|
if (processCollection) {
|
|
3329
3420
|
// Loop through collection and setup event listeners
|
|
3330
3421
|
this.collection.forEach(popover => {
|
|
3331
|
-
registerEventListeners(
|
|
3422
|
+
registerEventListeners.call(this, popover);
|
|
3332
3423
|
});
|
|
3333
3424
|
} // Add keydown global event listener
|
|
3334
3425
|
|
|
@@ -3352,36 +3443,36 @@ class Popover {
|
|
|
3352
3443
|
*/
|
|
3353
3444
|
|
|
3354
3445
|
|
|
3355
|
-
register(
|
|
3356
|
-
|
|
3446
|
+
register(query) {
|
|
3447
|
+
const els = getPopoverElements.call(this, query);
|
|
3448
|
+
if (!els) return false;
|
|
3449
|
+
return register.call(this, els.trigger, els.target);
|
|
3357
3450
|
}
|
|
3358
3451
|
|
|
3359
|
-
deregister(
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
registerCollection() {
|
|
3364
|
-
return registerCollection(this);
|
|
3365
|
-
}
|
|
3366
|
-
|
|
3367
|
-
deregisterCollection() {
|
|
3368
|
-
return deregisterCollection(this);
|
|
3452
|
+
deregister(query) {
|
|
3453
|
+
const popover = this.get(getPopoverID(query));
|
|
3454
|
+
if (!popover) return false;
|
|
3455
|
+
return deregister.call(this, popover);
|
|
3369
3456
|
}
|
|
3370
3457
|
/**
|
|
3371
3458
|
* Change state functionality
|
|
3372
3459
|
*/
|
|
3373
3460
|
|
|
3374
3461
|
|
|
3375
|
-
|
|
3376
|
-
|
|
3462
|
+
open(id) {
|
|
3463
|
+
const popover = this.get(id);
|
|
3464
|
+
if (!popover) return false;
|
|
3465
|
+
return popover.open();
|
|
3377
3466
|
}
|
|
3378
3467
|
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3468
|
+
close(id) {
|
|
3469
|
+
if (id) {
|
|
3470
|
+
const popover = this.get(id);
|
|
3471
|
+
if (!popover) return false;
|
|
3472
|
+
return popover.close();
|
|
3473
|
+
} else {
|
|
3474
|
+
return closeAll.call(this);
|
|
3475
|
+
}
|
|
3385
3476
|
}
|
|
3386
3477
|
|
|
3387
3478
|
}
|