vrembem 2.0.0 → 3.0.2
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/dev/scripts.esm.js +1120 -777
- package/dev/scripts.esm.js.map +1 -1
- package/dev/scripts.js +1120 -777
- package/dev/scripts.js.map +1 -1
- package/dev/scripts.modern.js +931 -687
- package/dev/scripts.modern.js.map +1 -1
- package/dev/scripts.umd.js +1120 -777
- package/dev/scripts.umd.js.map +1 -1
- package/dev/styles.css +29 -38
- 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 +1 -1
- package/dist/styles.css.map +1 -1
- package/package.json +26 -26
package/dev/scripts.esm.js
CHANGED
|
@@ -1,63 +1,153 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} else {
|
|
9
|
-
el.inert = null;
|
|
10
|
-
el.removeAttribute('aria-hidden');
|
|
11
|
-
}
|
|
12
|
-
});
|
|
1
|
+
function _defineProperties(target, props) {
|
|
2
|
+
for (var i = 0; i < props.length; i++) {
|
|
3
|
+
var descriptor = props[i];
|
|
4
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
5
|
+
descriptor.configurable = true;
|
|
6
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
7
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
13
8
|
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
12
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
13
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
14
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
15
|
+
writable: false
|
|
16
|
+
});
|
|
17
|
+
return Constructor;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function _extends() {
|
|
21
|
+
_extends = Object.assign || function (target) {
|
|
22
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
23
|
+
var source = arguments[i];
|
|
24
|
+
|
|
25
|
+
for (var key in source) {
|
|
26
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
27
|
+
target[key] = source[key];
|
|
28
|
+
}
|
|
23
29
|
}
|
|
24
|
-
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return target;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return _extends.apply(this, arguments);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function _inheritsLoose(subClass, superClass) {
|
|
39
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
40
|
+
subClass.prototype.constructor = subClass;
|
|
41
|
+
|
|
42
|
+
_setPrototypeOf(subClass, superClass);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function _setPrototypeOf(o, p) {
|
|
46
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
47
|
+
o.__proto__ = p;
|
|
48
|
+
return o;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return _setPrototypeOf(o, p);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function _assertThisInitialized(self) {
|
|
55
|
+
if (self === void 0) {
|
|
56
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
25
57
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
58
|
+
|
|
59
|
+
return self;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
var id = 0;
|
|
63
|
+
|
|
64
|
+
function _classPrivateFieldLooseKey(name) {
|
|
65
|
+
return "__private_" + id++ + "_" + name;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function _classPrivateFieldLooseBase(receiver, privateKey) {
|
|
69
|
+
if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
|
|
70
|
+
throw new TypeError("attempted to use private field on non-instance");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return receiver;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
var _handler = /*#__PURE__*/_classPrivateFieldLooseKey("handler");
|
|
77
|
+
|
|
78
|
+
var Breakpoint = /*#__PURE__*/function () {
|
|
79
|
+
function Breakpoint(value, handler) {
|
|
80
|
+
Object.defineProperty(this, _handler, {
|
|
81
|
+
writable: true,
|
|
82
|
+
value: void 0
|
|
32
83
|
});
|
|
84
|
+
this.value = value;
|
|
85
|
+
_classPrivateFieldLooseBase(this, _handler)[_handler] = handler;
|
|
86
|
+
this.mql = null;
|
|
33
87
|
}
|
|
34
|
-
};
|
|
35
88
|
|
|
36
|
-
|
|
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.
|
|
40
|
-
*/
|
|
41
|
-
var addClass = function addClass(el) {
|
|
42
|
-
var _arguments = arguments;
|
|
43
|
-
el = el.forEach ? el : [el];
|
|
44
|
-
el.forEach(function (el) {
|
|
45
|
-
var _el$classList;
|
|
89
|
+
var _proto = Breakpoint.prototype;
|
|
46
90
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
91
|
+
_proto.mount = function mount(value, handler) {
|
|
92
|
+
// Update passed params.
|
|
93
|
+
if (value) this.value = value;
|
|
94
|
+
if (handler) _classPrivateFieldLooseBase(this, _handler)[_handler] = handler; // Guard if no breakpoint was set.
|
|
50
95
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
96
|
+
if (!this.value) return this; // Setup and store the MediaQueryList instance.
|
|
97
|
+
|
|
98
|
+
this.mql = window.matchMedia("(min-width: " + this.value + ")"); // Conditionally use addListener() for IE11 support.
|
|
99
|
+
|
|
100
|
+
if (typeof this.mql.addEventListener === 'function') {
|
|
101
|
+
this.mql.addEventListener('change', _classPrivateFieldLooseBase(this, _handler)[_handler]);
|
|
102
|
+
} else {
|
|
103
|
+
this.mql.addListener(_classPrivateFieldLooseBase(this, _handler)[_handler]);
|
|
104
|
+
} // Run the handler.
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
_classPrivateFieldLooseBase(this, _handler)[_handler](this.mql);
|
|
108
|
+
|
|
109
|
+
return this;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
_proto.unmount = function unmount() {
|
|
113
|
+
// Guard if no MediaQueryList instance exists.
|
|
114
|
+
if (!this.mql) return this; // Conditionally use removeListener() for IE11 support.
|
|
115
|
+
|
|
116
|
+
if (typeof this.mql.removeEventListener === 'function') {
|
|
117
|
+
this.mql.removeEventListener('change', _classPrivateFieldLooseBase(this, _handler)[_handler]);
|
|
118
|
+
} else {
|
|
119
|
+
this.mql.removeListener(_classPrivateFieldLooseBase(this, _handler)[_handler]);
|
|
120
|
+
} // Set value, handler and MediaQueryList to null.
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
this.value = null;
|
|
124
|
+
_classPrivateFieldLooseBase(this, _handler)[_handler] = null;
|
|
125
|
+
this.mql = null;
|
|
126
|
+
return this;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
_createClass(Breakpoint, [{
|
|
130
|
+
key: "handler",
|
|
131
|
+
get: function get() {
|
|
132
|
+
return _classPrivateFieldLooseBase(this, _handler)[_handler];
|
|
133
|
+
} // Unmount existing handler before setting a new one.
|
|
134
|
+
,
|
|
135
|
+
set: function set(func) {
|
|
136
|
+
if (this.mql) {
|
|
137
|
+
// Conditionally use removeListener() for IE11 support.
|
|
138
|
+
if (typeof this.mql.removeEventListener === 'function') {
|
|
139
|
+
this.mql.removeEventListener('change', _classPrivateFieldLooseBase(this, _handler)[_handler]);
|
|
140
|
+
} else {
|
|
141
|
+
this.mql.removeListener(_classPrivateFieldLooseBase(this, _handler)[_handler]);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
_classPrivateFieldLooseBase(this, _handler)[_handler] = func;
|
|
146
|
+
}
|
|
147
|
+
}]);
|
|
148
|
+
|
|
149
|
+
return Breakpoint;
|
|
150
|
+
}();
|
|
61
151
|
|
|
62
152
|
function _settle(pact, state, value) {
|
|
63
153
|
if (!pact.s) {
|
|
@@ -341,160 +431,203 @@ var Collection = /*#__PURE__*/function () {
|
|
|
341
431
|
|
|
342
432
|
var focusableSelectors = ['a[href]:not([tabindex^="-"])', 'area[href]:not([tabindex^="-"])', 'input:not([type="hidden"]):not([type="radio"]):not([disabled]):not([tabindex^="-"])', 'input[type="radio"]:not([disabled]):not([tabindex^="-"])', 'select:not([disabled]):not([tabindex^="-"])', 'textarea:not([disabled]):not([tabindex^="-"])', 'button:not([disabled]):not([tabindex^="-"])', 'iframe:not([tabindex^="-"])', 'audio[controls]:not([tabindex^="-"])', 'video[controls]:not([tabindex^="-"])', '[contenteditable]:not([tabindex^="-"])', '[tabindex]:not([tabindex^="-"])'];
|
|
343
433
|
|
|
344
|
-
var
|
|
345
|
-
|
|
434
|
+
var _focusable = /*#__PURE__*/_classPrivateFieldLooseKey("focusable");
|
|
435
|
+
|
|
436
|
+
var _handleFocusTrap = /*#__PURE__*/_classPrivateFieldLooseKey("handleFocusTrap");
|
|
437
|
+
|
|
438
|
+
var _handleFocusLock = /*#__PURE__*/_classPrivateFieldLooseKey("handleFocusLock");
|
|
346
439
|
|
|
347
|
-
if (innerFocus) {
|
|
348
|
-
innerFocus.focus();
|
|
349
|
-
} else {
|
|
350
|
-
var innerElement = target.querySelector('[tabindex="-1"]');
|
|
351
|
-
if (innerElement) innerElement.focus();
|
|
352
|
-
}
|
|
353
|
-
};
|
|
354
|
-
var focusTrigger = function focusTrigger(obj) {
|
|
355
|
-
if (!obj || !obj.memory || !obj.memory.trigger) return;
|
|
356
|
-
obj.memory.trigger.focus();
|
|
357
|
-
obj.memory.trigger = null;
|
|
358
|
-
};
|
|
359
440
|
var FocusTrap = /*#__PURE__*/function () {
|
|
360
|
-
function FocusTrap() {
|
|
361
|
-
|
|
362
|
-
|
|
441
|
+
function FocusTrap(el, selectorFocus) {
|
|
442
|
+
if (el === void 0) {
|
|
443
|
+
el = null;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (selectorFocus === void 0) {
|
|
447
|
+
selectorFocus = '[data-focus]';
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
Object.defineProperty(this, _focusable, {
|
|
451
|
+
writable: true,
|
|
452
|
+
value: void 0
|
|
453
|
+
});
|
|
454
|
+
Object.defineProperty(this, _handleFocusTrap, {
|
|
455
|
+
writable: true,
|
|
456
|
+
value: void 0
|
|
457
|
+
});
|
|
458
|
+
Object.defineProperty(this, _handleFocusLock, {
|
|
459
|
+
writable: true,
|
|
460
|
+
value: void 0
|
|
461
|
+
});
|
|
462
|
+
this.el = el;
|
|
463
|
+
this.selectorFocus = selectorFocus;
|
|
464
|
+
_classPrivateFieldLooseBase(this, _handleFocusTrap)[_handleFocusTrap] = handleFocusTrap.bind(this);
|
|
465
|
+
_classPrivateFieldLooseBase(this, _handleFocusLock)[_handleFocusLock] = handleFocusLock.bind(this);
|
|
363
466
|
}
|
|
364
467
|
|
|
365
468
|
var _proto = FocusTrap.prototype;
|
|
366
469
|
|
|
367
|
-
_proto.
|
|
368
|
-
|
|
369
|
-
this.
|
|
370
|
-
this.
|
|
371
|
-
this.focusable = this.getFocusable();
|
|
470
|
+
_proto.mount = function mount(el, selectorFocus) {
|
|
471
|
+
// Update passed params.
|
|
472
|
+
if (el) this.el = el;
|
|
473
|
+
if (selectorFocus) this.selectorFocus = selectorFocus; // Get the focusable elements.
|
|
372
474
|
|
|
373
|
-
|
|
374
|
-
this.focusableFirst = this.focusable[0];
|
|
375
|
-
this.focusableLast = this.focusable[this.focusable.length - 1];
|
|
376
|
-
this.target.addEventListener('keydown', this.__handlerFocusTrap);
|
|
377
|
-
} else {
|
|
378
|
-
this.target.addEventListener('keydown', this.handlerFocusLock);
|
|
379
|
-
}
|
|
380
|
-
};
|
|
475
|
+
this.focusable = this.getFocusable(); // Set the focus on the element.
|
|
381
476
|
|
|
382
|
-
|
|
383
|
-
if (!this.target) return;
|
|
384
|
-
this.inner = null;
|
|
385
|
-
this.focusable = null;
|
|
386
|
-
this.focusableFirst = null;
|
|
387
|
-
this.focusableLast = null;
|
|
388
|
-
this.target.removeEventListener('keydown', this.__handlerFocusTrap);
|
|
389
|
-
this.target.removeEventListener('keydown', this.handlerFocusLock);
|
|
390
|
-
this.target = null;
|
|
477
|
+
this.focus();
|
|
391
478
|
};
|
|
392
479
|
|
|
393
|
-
_proto.
|
|
394
|
-
//
|
|
395
|
-
|
|
480
|
+
_proto.unmount = function unmount() {
|
|
481
|
+
// Set element to null.
|
|
482
|
+
this.el = null; // Apply empty array to focusable.
|
|
396
483
|
|
|
397
|
-
this.
|
|
398
|
-
this.target.removeEventListener('keydown', this.handlerFocusLock); // Get the focusable elements
|
|
484
|
+
this.focusable = []; // Remove event listeners
|
|
399
485
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
if (this.focusable.length) {
|
|
403
|
-
// If there are focusable elements, setup focus trap
|
|
404
|
-
this.focusableFirst = this.focusable[0];
|
|
405
|
-
this.focusableLast = this.focusable[this.focusable.length - 1];
|
|
406
|
-
this.target.addEventListener('keydown', this.__handlerFocusTrap);
|
|
407
|
-
} else {
|
|
408
|
-
// If there are no focusable elements, setup focus lock
|
|
409
|
-
this.focusableFirst = null;
|
|
410
|
-
this.focusableLast = null;
|
|
411
|
-
this.target.addEventListener('keydown', this.handlerFocusLock);
|
|
412
|
-
}
|
|
486
|
+
document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleFocusTrap)[_handleFocusTrap]);
|
|
487
|
+
document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleFocusLock)[_handleFocusLock]);
|
|
413
488
|
};
|
|
414
489
|
|
|
415
|
-
_proto.
|
|
416
|
-
|
|
417
|
-
|
|
490
|
+
_proto.focus = function focus(el, selectorFocus) {
|
|
491
|
+
if (el === void 0) {
|
|
492
|
+
el = this.el;
|
|
493
|
+
}
|
|
418
494
|
|
|
419
|
-
if (
|
|
420
|
-
|
|
421
|
-
this.focusableLast.focus();
|
|
422
|
-
event.preventDefault();
|
|
423
|
-
}
|
|
424
|
-
} else {
|
|
425
|
-
if (document.activeElement === this.focusableLast || document.activeElement === this.inner) {
|
|
426
|
-
this.focusableFirst.focus();
|
|
427
|
-
event.preventDefault();
|
|
428
|
-
}
|
|
495
|
+
if (selectorFocus === void 0) {
|
|
496
|
+
selectorFocus = this.selectorFocus;
|
|
429
497
|
}
|
|
430
|
-
};
|
|
431
498
|
|
|
432
|
-
|
|
433
|
-
var
|
|
434
|
-
|
|
499
|
+
// Query for the focus selector, otherwise return this element.
|
|
500
|
+
var result = el.querySelector(selectorFocus) || el; // Give the returned element focus.
|
|
501
|
+
|
|
502
|
+
result.focus();
|
|
435
503
|
};
|
|
436
504
|
|
|
437
|
-
_proto.getFocusable = function getFocusable() {
|
|
438
|
-
|
|
505
|
+
_proto.getFocusable = function getFocusable(el) {
|
|
506
|
+
if (el === void 0) {
|
|
507
|
+
el = this.el;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// Initialize the focusable array.
|
|
511
|
+
var focusable = []; // Store the initial focus and scroll position.
|
|
512
|
+
|
|
439
513
|
var initFocus = document.activeElement;
|
|
440
|
-
var initScrollTop =
|
|
441
|
-
|
|
442
|
-
|
|
514
|
+
var initScrollTop = el.scrollTop; // Query for all the focusable elements.
|
|
515
|
+
|
|
516
|
+
var els = el.querySelectorAll(focusableSelectors.join(',')); // Loop through all focusable elements.
|
|
517
|
+
|
|
518
|
+
els.forEach(function (el) {
|
|
519
|
+
// Set them to focus and check
|
|
520
|
+
el.focus(); // Test that the element took focus.
|
|
443
521
|
|
|
444
|
-
if (
|
|
522
|
+
if (document.activeElement === el) {
|
|
523
|
+
// Add element to the focusable array.
|
|
445
524
|
focusable.push(el);
|
|
446
525
|
}
|
|
447
|
-
});
|
|
448
|
-
|
|
449
|
-
|
|
526
|
+
}); // Restore the initial scroll position and focus.
|
|
527
|
+
|
|
528
|
+
el.scrollTop = initScrollTop;
|
|
529
|
+
initFocus.focus(); // Return the focusable array.
|
|
530
|
+
|
|
450
531
|
return focusable;
|
|
451
532
|
};
|
|
452
533
|
|
|
534
|
+
_createClass(FocusTrap, [{
|
|
535
|
+
key: "focusable",
|
|
536
|
+
get: function get() {
|
|
537
|
+
return _classPrivateFieldLooseBase(this, _focusable)[_focusable];
|
|
538
|
+
},
|
|
539
|
+
set: function set(value) {
|
|
540
|
+
// Update the focusable value.
|
|
541
|
+
_classPrivateFieldLooseBase(this, _focusable)[_focusable] = value; // Apply event listeners based on new focusable array length.
|
|
542
|
+
|
|
543
|
+
if (_classPrivateFieldLooseBase(this, _focusable)[_focusable].length) {
|
|
544
|
+
document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleFocusLock)[_handleFocusLock]);
|
|
545
|
+
document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleFocusTrap)[_handleFocusTrap]);
|
|
546
|
+
} else {
|
|
547
|
+
document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleFocusTrap)[_handleFocusTrap]);
|
|
548
|
+
document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleFocusLock)[_handleFocusLock]);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}, {
|
|
552
|
+
key: "focusableFirst",
|
|
553
|
+
get: function get() {
|
|
554
|
+
return this.focusable[0];
|
|
555
|
+
}
|
|
556
|
+
}, {
|
|
557
|
+
key: "focusableLast",
|
|
558
|
+
get: function get() {
|
|
559
|
+
return this.focusable[this.focusable.length - 1];
|
|
560
|
+
}
|
|
561
|
+
}]);
|
|
562
|
+
|
|
453
563
|
return FocusTrap;
|
|
454
564
|
}();
|
|
455
565
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
566
|
+
function handleFocusTrap(event) {
|
|
567
|
+
// Check if the click was a tab and return if not.
|
|
568
|
+
var isTab = event.key === 'Tab' || event.keyCode === 9;
|
|
569
|
+
if (!isTab) return; // If the shift key is pressed.
|
|
570
|
+
|
|
571
|
+
if (event.shiftKey) {
|
|
572
|
+
// If the active element is either the root el or first focusable.
|
|
573
|
+
if (document.activeElement === this.focusableFirst || document.activeElement === this.el) {
|
|
574
|
+
// Prevent default and focus the last focusable element instead.
|
|
575
|
+
event.preventDefault();
|
|
576
|
+
this.focusableLast.focus();
|
|
577
|
+
}
|
|
578
|
+
} else {
|
|
579
|
+
// If the active element is either the root el or last focusable.
|
|
580
|
+
if (document.activeElement === this.focusableLast || document.activeElement === this.el) {
|
|
581
|
+
// Prevent default and focus the first focusable element instead.
|
|
582
|
+
event.preventDefault();
|
|
583
|
+
this.focusableFirst.focus();
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
472
587
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
var hyphenCase = function hyphenCase(str) {
|
|
479
|
-
return str.replace(/([a-z][A-Z])/g, function (g) {
|
|
480
|
-
return g[0] + '-' + g[1].toLowerCase();
|
|
481
|
-
});
|
|
482
|
-
};
|
|
588
|
+
function handleFocusLock(event) {
|
|
589
|
+
// Ignore the tab key by preventing default.
|
|
590
|
+
var isTab = event.key === 'Tab' || event.keyCode === 9;
|
|
591
|
+
if (isTab) event.preventDefault();
|
|
592
|
+
}
|
|
483
593
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
var removeClass = function removeClass(el) {
|
|
490
|
-
var _arguments = arguments;
|
|
491
|
-
el = el.forEach ? el : [el];
|
|
492
|
-
el.forEach(function (el) {
|
|
493
|
-
var _el$classList;
|
|
594
|
+
function getConfig$1(el, dataConfig) {
|
|
595
|
+
var string = el.getAttribute("data-" + dataConfig) || '';
|
|
596
|
+
var json = string.replace(/'/g, '"');
|
|
597
|
+
return json ? JSON.parse(json) : {};
|
|
598
|
+
}
|
|
494
599
|
|
|
495
|
-
|
|
600
|
+
function getPrefix() {
|
|
601
|
+
return getComputedStyle(document.body).getPropertyValue('--vrembem-variable-prefix').trim();
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function localStore(key, enable) {
|
|
605
|
+
if (enable === void 0) {
|
|
606
|
+
enable = true;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
function getStore() {
|
|
610
|
+
var value = localStorage.getItem(key);
|
|
611
|
+
return value ? JSON.parse(value) : {};
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function setStore(obj) {
|
|
615
|
+
localStorage.setItem(key, JSON.stringify(obj));
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
return new Proxy(getStore(), {
|
|
619
|
+
set: function set(target, property, value) {
|
|
620
|
+
target[property] = value;
|
|
621
|
+
if (enable) setStore(target);
|
|
622
|
+
return true;
|
|
623
|
+
},
|
|
624
|
+
deleteProperty: function deleteProperty(target, property) {
|
|
625
|
+
delete target[property];
|
|
626
|
+
if (enable) setStore(target);
|
|
627
|
+
return true;
|
|
628
|
+
}
|
|
496
629
|
});
|
|
497
|
-
}
|
|
630
|
+
}
|
|
498
631
|
|
|
499
632
|
/**
|
|
500
633
|
* Teleports an element in the DOM based on a reference and teleport method.
|
|
@@ -538,21 +671,6 @@ function teleport(what, where, how) {
|
|
|
538
671
|
return returnRef;
|
|
539
672
|
}
|
|
540
673
|
|
|
541
|
-
/**
|
|
542
|
-
* Toggle a class or classes on an element or NodeList.
|
|
543
|
-
* @param {Node || NodeList} el - Element(s) to toggle class(es) on.
|
|
544
|
-
* @param {String || Array} cl - Class(es) to toggle.
|
|
545
|
-
*/
|
|
546
|
-
var toggleClass = function toggleClass(el) {
|
|
547
|
-
var _arguments = arguments;
|
|
548
|
-
el = el.forEach ? el : [el];
|
|
549
|
-
el.forEach(function (el) {
|
|
550
|
-
[].slice.call(_arguments, 1).forEach(function (cl) {
|
|
551
|
-
el.classList.toggle(cl);
|
|
552
|
-
});
|
|
553
|
-
});
|
|
554
|
-
};
|
|
555
|
-
|
|
556
674
|
var openTransition = function openTransition(el, settings) {
|
|
557
675
|
return new Promise(function (resolve) {
|
|
558
676
|
if (settings.transition) {
|
|
@@ -590,86 +708,54 @@ var closeTransition = function closeTransition(el, settings) {
|
|
|
590
708
|
});
|
|
591
709
|
};
|
|
592
710
|
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
FocusTrap: FocusTrap,
|
|
604
|
-
hasClass: hasClass,
|
|
605
|
-
hyphenCase: hyphenCase,
|
|
606
|
-
removeClass: removeClass,
|
|
607
|
-
teleport: teleport,
|
|
608
|
-
toggleClass: toggleClass,
|
|
609
|
-
openTransition: openTransition,
|
|
610
|
-
closeTransition: closeTransition
|
|
611
|
-
};
|
|
612
|
-
|
|
613
|
-
function _defineProperties(target, props) {
|
|
614
|
-
for (var i = 0; i < props.length; i++) {
|
|
615
|
-
var descriptor = props[i];
|
|
616
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
617
|
-
descriptor.configurable = true;
|
|
618
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
619
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
711
|
+
function setOverflowHidden(state, selector) {
|
|
712
|
+
if (selector) {
|
|
713
|
+
var els = document.querySelectorAll(selector);
|
|
714
|
+
els.forEach(function (el) {
|
|
715
|
+
if (state) {
|
|
716
|
+
el.style.overflow = 'hidden';
|
|
717
|
+
} else {
|
|
718
|
+
el.style.removeProperty('overflow');
|
|
719
|
+
}
|
|
720
|
+
});
|
|
620
721
|
}
|
|
621
722
|
}
|
|
622
723
|
|
|
623
|
-
function
|
|
624
|
-
if (
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
_extends = Object.assign || function (target) {
|
|
634
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
635
|
-
var source = arguments[i];
|
|
636
|
-
|
|
637
|
-
for (var key in source) {
|
|
638
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
639
|
-
target[key] = source[key];
|
|
640
|
-
}
|
|
724
|
+
function setInert(state, selector) {
|
|
725
|
+
if (selector) {
|
|
726
|
+
var els = document.querySelectorAll(selector);
|
|
727
|
+
els.forEach(function (el) {
|
|
728
|
+
if (state) {
|
|
729
|
+
el.inert = true;
|
|
730
|
+
el.setAttribute('aria-hidden', true);
|
|
731
|
+
} else {
|
|
732
|
+
el.inert = null;
|
|
733
|
+
el.removeAttribute('aria-hidden');
|
|
641
734
|
}
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
return target;
|
|
645
|
-
};
|
|
646
|
-
|
|
647
|
-
return _extends.apply(this, arguments);
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
function _inheritsLoose(subClass, superClass) {
|
|
651
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
652
|
-
subClass.prototype.constructor = subClass;
|
|
653
|
-
|
|
654
|
-
_setPrototypeOf(subClass, superClass);
|
|
735
|
+
});
|
|
736
|
+
}
|
|
655
737
|
}
|
|
656
738
|
|
|
657
|
-
function
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
return o;
|
|
661
|
-
};
|
|
739
|
+
function updateGlobalState(param, config) {
|
|
740
|
+
// Set inert state based on if a modal is active.
|
|
741
|
+
setInert(!!param, config.selectorInert); // Set overflow state based on if a modal is active.
|
|
662
742
|
|
|
663
|
-
|
|
743
|
+
setOverflowHidden(!!param, config.selectorOverflow);
|
|
664
744
|
}
|
|
665
745
|
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
746
|
+
var index = {
|
|
747
|
+
__proto__: null,
|
|
748
|
+
Breakpoint: Breakpoint,
|
|
749
|
+
Collection: Collection,
|
|
750
|
+
FocusTrap: FocusTrap,
|
|
751
|
+
getConfig: getConfig$1,
|
|
752
|
+
getPrefix: getPrefix,
|
|
753
|
+
localStore: localStore,
|
|
754
|
+
teleport: teleport,
|
|
755
|
+
openTransition: openTransition,
|
|
756
|
+
closeTransition: closeTransition,
|
|
757
|
+
updateGlobalState: updateGlobalState
|
|
758
|
+
};
|
|
673
759
|
|
|
674
760
|
var defaults$3 = {
|
|
675
761
|
autoInit: false,
|
|
@@ -752,16 +838,17 @@ var Checkbox = /*#__PURE__*/function () {
|
|
|
752
838
|
var defaults$2 = {
|
|
753
839
|
autoInit: false,
|
|
754
840
|
// Data attributes
|
|
755
|
-
dataDrawer: 'drawer',
|
|
756
|
-
dataDialog: 'drawer-dialog',
|
|
757
|
-
dataToggle: 'drawer-toggle',
|
|
758
841
|
dataOpen: 'drawer-open',
|
|
759
842
|
dataClose: 'drawer-close',
|
|
843
|
+
dataToggle: 'drawer-toggle',
|
|
760
844
|
dataBreakpoint: 'drawer-breakpoint',
|
|
845
|
+
dataConfig: 'drawer-config',
|
|
761
846
|
// Selectors
|
|
847
|
+
selectorDrawer: '.drawer',
|
|
848
|
+
selectorDialog: '.drawer__dialog',
|
|
762
849
|
selectorFocus: '[data-focus]',
|
|
763
850
|
selectorInert: null,
|
|
764
|
-
selectorOverflow:
|
|
851
|
+
selectorOverflow: 'body',
|
|
765
852
|
// State classes
|
|
766
853
|
stateOpened: 'is-opened',
|
|
767
854
|
stateOpening: 'is-opening',
|
|
@@ -773,399 +860,624 @@ var defaults$2 = {
|
|
|
773
860
|
breakpoints: null,
|
|
774
861
|
customEventPrefix: 'drawer:',
|
|
775
862
|
eventListeners: true,
|
|
776
|
-
|
|
777
|
-
|
|
863
|
+
store: true,
|
|
864
|
+
storeKey: 'VB:DrawerState',
|
|
778
865
|
setTabindex: true,
|
|
779
866
|
transition: true
|
|
780
867
|
};
|
|
781
868
|
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
this.mediaQueryLists = [];
|
|
785
|
-
this.parent = parent;
|
|
786
|
-
this.prefix = this.getVariablePrefix();
|
|
787
|
-
this.__check = this.check.bind(this);
|
|
788
|
-
}
|
|
869
|
+
function handleClick$2(event) {
|
|
870
|
+
var _this = this;
|
|
789
871
|
|
|
790
|
-
|
|
872
|
+
// If an open, close or toggle button was clicked, handle the click event.
|
|
873
|
+
var trigger = event.target.closest("\n [data-" + this.settings.dataOpen + "],\n [data-" + this.settings.dataToggle + "],\n [data-" + this.settings.dataClose + "]\n ");
|
|
791
874
|
|
|
792
|
-
|
|
793
|
-
|
|
875
|
+
if (trigger) {
|
|
876
|
+
// Prevent the default behavior of the trigger.
|
|
877
|
+
event.preventDefault(); // If it's a toggle trigger...
|
|
794
878
|
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
879
|
+
if (trigger.matches("[data-" + this.settings.dataToggle + "]")) {
|
|
880
|
+
var selectors = trigger.getAttribute("data-" + this.settings.dataToggle).trim().split(' ');
|
|
881
|
+
selectors.forEach(function (selector) {
|
|
882
|
+
// Get the entry from collection using the attribute value.
|
|
883
|
+
var entry = _this.get(selector); // Store the trigger on the entry.
|
|
800
884
|
|
|
801
|
-
var bp = _this.getBreakpoint(key);
|
|
802
885
|
|
|
803
|
-
|
|
886
|
+
entry.trigger = trigger; // Toggle the drawer
|
|
804
887
|
|
|
805
|
-
|
|
888
|
+
entry.toggle();
|
|
889
|
+
});
|
|
890
|
+
} // If it's a open trigger...
|
|
806
891
|
|
|
807
892
|
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
} else {
|
|
811
|
-
mql.addListener(_this.__check);
|
|
812
|
-
} // Push to mediaQueryLists array along with drawer ID
|
|
893
|
+
if (trigger.matches("[data-" + this.settings.dataOpen + "]")) {
|
|
894
|
+
var _selectors = trigger.getAttribute("data-" + this.settings.dataOpen).trim().split(' ');
|
|
813
895
|
|
|
896
|
+
_selectors.forEach(function (selector) {
|
|
897
|
+
// Get the entry from collection using the attribute value.
|
|
898
|
+
var entry = _this.get(selector); // Store the trigger on the entry.
|
|
814
899
|
|
|
815
|
-
_this.mediaQueryLists.push({
|
|
816
|
-
'mql': mql,
|
|
817
|
-
'drawer': id
|
|
818
|
-
});
|
|
819
|
-
});
|
|
820
|
-
};
|
|
821
900
|
|
|
822
|
-
|
|
823
|
-
var _this2 = this;
|
|
901
|
+
entry.trigger = trigger; // Open the drawer.
|
|
824
902
|
|
|
825
|
-
|
|
826
|
-
this.mediaQueryLists.forEach(function (item) {
|
|
827
|
-
item.mql.removeListener(_this2.__check);
|
|
903
|
+
entry.open();
|
|
828
904
|
});
|
|
829
|
-
}
|
|
905
|
+
} // If it's a close trigger...
|
|
830
906
|
|
|
831
|
-
this.mediaQueryLists = null;
|
|
832
|
-
};
|
|
833
907
|
|
|
834
|
-
|
|
835
|
-
|
|
908
|
+
if (trigger.matches("[data-" + this.settings.dataClose + "]")) {
|
|
909
|
+
var _selectors2 = trigger.getAttribute("data-" + this.settings.dataClose).trim().split(' ');
|
|
836
910
|
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
911
|
+
_selectors2.forEach(function (selector) {
|
|
912
|
+
if (selector) {
|
|
913
|
+
// Get the entry from collection using the attribute value.
|
|
914
|
+
var entry = _this.get(selector); // Store the trigger on the entry.
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
entry.trigger = trigger; // Close the drawer.
|
|
840
918
|
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
if (drawer) _this3.match(item.mql, drawer);
|
|
919
|
+
entry.close();
|
|
920
|
+
} else {
|
|
921
|
+
// If no value is set on close trigger, get the parent drawer.
|
|
922
|
+
var parent = event.target.closest(_this.settings.selectorDrawer); // If a parent drawer was found, close it.
|
|
923
|
+
|
|
924
|
+
if (parent) _this.close(parent);
|
|
925
|
+
}
|
|
849
926
|
});
|
|
850
|
-
document.dispatchEvent(new CustomEvent(this.parent.settings.customEventPrefix + 'breakpoint', {
|
|
851
|
-
bubbles: true
|
|
852
|
-
}));
|
|
853
927
|
}
|
|
854
|
-
};
|
|
855
928
|
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
929
|
+
return;
|
|
930
|
+
} // If the modal drawer screen was clicked...
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
if (event.target.matches(this.settings.selectorDrawer)) {
|
|
934
|
+
// Close the modal drawer.
|
|
935
|
+
this.close(event.target.id);
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
function handleKeydown$2(event) {
|
|
939
|
+
if (event.key === 'Escape') {
|
|
940
|
+
var modal = this.activeModal;
|
|
941
|
+
if (modal) this.close(modal);
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
var deregister$2 = function deregister(obj, close) {
|
|
946
|
+
if (close === void 0) {
|
|
947
|
+
close = true;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
try {
|
|
951
|
+
var _temp5 = function _temp5() {
|
|
952
|
+
// Return the modified collection.
|
|
953
|
+
return _this2.collection;
|
|
954
|
+
};
|
|
955
|
+
|
|
956
|
+
var _this2 = this;
|
|
957
|
+
|
|
958
|
+
// Return collection if nothing was passed.
|
|
959
|
+
if (!obj) return Promise.resolve(_this2.collection); // Check if entry has been registered in the collection.
|
|
960
|
+
|
|
961
|
+
var index = _this2.collection.findIndex(function (entry) {
|
|
962
|
+
return entry.id === obj.id;
|
|
963
|
+
});
|
|
964
|
+
|
|
965
|
+
var _temp6 = function () {
|
|
966
|
+
if (index >= 0) {
|
|
967
|
+
var _temp7 = function _temp7() {
|
|
968
|
+
// Remove entry from local store.
|
|
969
|
+
delete _this2.store[_entry.id]; // Unmount the MatchMedia functionality.
|
|
970
|
+
|
|
971
|
+
_entry.unmountBreakpoint(); // Delete properties from collection entry.
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
Object.getOwnPropertyNames(_entry).forEach(function (prop) {
|
|
975
|
+
delete _entry[prop];
|
|
976
|
+
}); // Remove entry from collection.
|
|
977
|
+
|
|
978
|
+
_this2.collection.splice(index, 1);
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
// Get the collection entry.
|
|
982
|
+
var _entry = _this2.collection[index]; // If entry is in the opened state.
|
|
983
|
+
|
|
984
|
+
var _temp8 = function () {
|
|
985
|
+
if (close && _entry.state === 'opened') {
|
|
986
|
+
// Close the drawer.
|
|
987
|
+
return Promise.resolve(_entry.close(false)).then(function () {});
|
|
988
|
+
}
|
|
989
|
+
}();
|
|
990
|
+
|
|
991
|
+
return _temp8 && _temp8.then ? _temp8.then(_temp7) : _temp7(_temp8);
|
|
992
|
+
}
|
|
993
|
+
}();
|
|
994
|
+
|
|
995
|
+
return Promise.resolve(_temp6 && _temp6.then ? _temp6.then(_temp5) : _temp5(_temp6));
|
|
996
|
+
} catch (e) {
|
|
997
|
+
return Promise.reject(e);
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
|
|
1001
|
+
function L() {
|
|
1002
|
+
return getComputedStyle(document.body).getPropertyValue("--vrembem-variable-prefix").trim();
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
function getBreakpoint(drawer) {
|
|
1006
|
+
var prefix = L();
|
|
1007
|
+
var bp = drawer.getAttribute("data-" + this.settings.dataBreakpoint);
|
|
1008
|
+
|
|
1009
|
+
if (this.settings.breakpoints && this.settings.breakpoints[bp]) {
|
|
1010
|
+
return this.settings.breakpoints[bp];
|
|
1011
|
+
} else if (getComputedStyle(document.body).getPropertyValue("--" + prefix + "breakpoint-" + bp).trim()) {
|
|
1012
|
+
return getComputedStyle(document.body).getPropertyValue("--" + prefix + "breakpoint-" + bp).trim();
|
|
1013
|
+
} else {
|
|
1014
|
+
return bp;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
function getDrawer(query) {
|
|
1019
|
+
// Get the entry from collection.
|
|
1020
|
+
var entry = typeof query === 'string' ? this.get(query) : this.get(query.id); // Return entry if it was resolved, otherwise throw error.
|
|
1021
|
+
|
|
1022
|
+
if (entry) {
|
|
1023
|
+
return entry;
|
|
1024
|
+
} else {
|
|
1025
|
+
throw new Error("Drawer not found in collection with id of \"" + (query.id || query) + "\".");
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
function getDrawerID(obj) {
|
|
1030
|
+
// If it's a string, return the string.
|
|
1031
|
+
if (typeof obj === 'string') {
|
|
1032
|
+
return obj;
|
|
1033
|
+
} // If it's an HTML element.
|
|
1034
|
+
else if (typeof obj.hasAttribute === 'function') {
|
|
1035
|
+
// If it's a drawer open trigger, return data value.
|
|
1036
|
+
if (obj.hasAttribute("data-" + this.settings.dataOpen)) {
|
|
1037
|
+
return obj.getAttribute("data-" + this.settings.dataOpen);
|
|
1038
|
+
} // If it's a drawer close trigger, return data value or false.
|
|
1039
|
+
else if (obj.hasAttribute("data-" + this.settings.dataClose)) {
|
|
1040
|
+
return obj.getAttribute("data-" + this.settings.dataClose) || false;
|
|
1041
|
+
} // If it's a drawer toggle trigger, return data value.
|
|
1042
|
+
else if (obj.hasAttribute("data-" + this.settings.dataToggle)) {
|
|
1043
|
+
return obj.getAttribute("data-" + this.settings.dataToggle);
|
|
1044
|
+
} // If it's a drawer element, return the id.
|
|
1045
|
+
else if (obj.closest(this.settings.selectorDrawer)) {
|
|
1046
|
+
obj = obj.closest(this.settings.selectorDrawer);
|
|
1047
|
+
return obj.id || false;
|
|
1048
|
+
} // Return false if no id was found.
|
|
1049
|
+
else return false;
|
|
1050
|
+
} // If it has an id property, return its value.
|
|
1051
|
+
else if (obj.id) {
|
|
1052
|
+
return obj.id;
|
|
1053
|
+
} // Return false if no id was found.
|
|
1054
|
+
else return false;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
function getDrawerElements(query) {
|
|
1058
|
+
var id = getDrawerID.call(this, query);
|
|
1059
|
+
|
|
1060
|
+
if (id) {
|
|
1061
|
+
var drawer = document.querySelector("#" + id);
|
|
1062
|
+
var dialog = drawer ? drawer.querySelector(this.settings.selectorDialog) : null;
|
|
1063
|
+
|
|
1064
|
+
if (!drawer && !dialog) {
|
|
1065
|
+
return {
|
|
1066
|
+
error: new Error("No drawer elements found using the ID: \"" + id + "\".")
|
|
1067
|
+
};
|
|
1068
|
+
} else if (!dialog) {
|
|
1069
|
+
return {
|
|
1070
|
+
error: new Error('Drawer is missing dialog element.')
|
|
1071
|
+
};
|
|
859
1072
|
} else {
|
|
860
|
-
|
|
1073
|
+
return {
|
|
1074
|
+
drawer: drawer,
|
|
1075
|
+
dialog: dialog
|
|
1076
|
+
};
|
|
861
1077
|
}
|
|
862
|
-
}
|
|
1078
|
+
} else {
|
|
1079
|
+
return {
|
|
1080
|
+
error: new Error('Could not resolve the drawer ID.')
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
863
1084
|
|
|
864
|
-
|
|
865
|
-
|
|
1085
|
+
var initialState = function initialState(entry) {
|
|
1086
|
+
try {
|
|
1087
|
+
var _this2 = this;
|
|
866
1088
|
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
1089
|
+
var _temp3 = function () {
|
|
1090
|
+
if (_this2.store[entry.id]) {
|
|
1091
|
+
var _temp4 = function () {
|
|
1092
|
+
if (_this2.store[entry.id] === 'opened') {
|
|
1093
|
+
return Promise.resolve(entry.open(false, false)).then(function () {});
|
|
1094
|
+
} else {
|
|
1095
|
+
return Promise.resolve(entry.close(false, false)).then(function () {});
|
|
1096
|
+
}
|
|
1097
|
+
}();
|
|
872
1098
|
|
|
873
|
-
|
|
874
|
-
|
|
1099
|
+
if (_temp4 && _temp4.then) return _temp4.then(function () {});
|
|
1100
|
+
} else if (entry.el.classList.contains(_this2.settings.stateOpened)) {
|
|
1101
|
+
// Update drawer state.
|
|
1102
|
+
entry.state = 'opened';
|
|
1103
|
+
} else {
|
|
1104
|
+
// Remove transition state classes.
|
|
1105
|
+
entry.el.classList.remove(_this2.settings.stateOpening);
|
|
1106
|
+
entry.el.classList.remove(_this2.settings.stateClosing); // Add closed state class.
|
|
875
1107
|
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
prefix += 'breakpoint-';
|
|
880
|
-
return prefix;
|
|
881
|
-
};
|
|
1108
|
+
entry.el.classList.add(_this2.settings.stateClosed);
|
|
1109
|
+
}
|
|
1110
|
+
}();
|
|
882
1111
|
|
|
883
|
-
|
|
884
|
-
|
|
1112
|
+
// Setup initial state using the following priority:
|
|
1113
|
+
// 1. If a store state is available, restore from local store.
|
|
1114
|
+
// 2. If opened state class is set, set state to opened.
|
|
1115
|
+
// 3. Else, initialize default state.
|
|
1116
|
+
return Promise.resolve(_temp3 && _temp3.then ? _temp3.then(function () {}) : void 0);
|
|
1117
|
+
} catch (e) {
|
|
1118
|
+
return Promise.reject(e);
|
|
1119
|
+
}
|
|
1120
|
+
};
|
|
885
1121
|
|
|
886
|
-
function
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
1122
|
+
function updateFocusState$1(entry) {
|
|
1123
|
+
// Check if there's an active modal
|
|
1124
|
+
if (entry.state === 'opened') {
|
|
1125
|
+
// Mount the focus trap on the opened drawer.
|
|
1126
|
+
if (entry.mode === 'modal') {
|
|
1127
|
+
this.focusTrap.mount(entry.dialog, this.settings.selectorFocus);
|
|
1128
|
+
} else {
|
|
1129
|
+
this.focusTrap.focus(entry.dialog, this.settings.selectorFocus);
|
|
1130
|
+
}
|
|
1131
|
+
} else {
|
|
1132
|
+
// Set focus to root trigger and unmount the focus trap.
|
|
1133
|
+
if (entry.trigger) {
|
|
1134
|
+
entry.trigger.focus();
|
|
1135
|
+
entry.trigger = null;
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
this.focusTrap.unmount();
|
|
1139
|
+
}
|
|
892
1140
|
}
|
|
893
1141
|
|
|
894
|
-
var
|
|
1142
|
+
var open$2 = function open(query, transition, focus) {
|
|
1143
|
+
if (focus === void 0) {
|
|
1144
|
+
focus = true;
|
|
1145
|
+
}
|
|
1146
|
+
|
|
895
1147
|
try {
|
|
1148
|
+
var _temp3 = function _temp3() {
|
|
1149
|
+
// Set focus to the drawer element if the focus param is true.
|
|
1150
|
+
if (focus) {
|
|
1151
|
+
updateFocusState$1.call(_this2, drawer);
|
|
1152
|
+
} // Dispatch custom opened event.
|
|
1153
|
+
|
|
1154
|
+
|
|
1155
|
+
drawer.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'opened', {
|
|
1156
|
+
detail: _this2,
|
|
1157
|
+
bubbles: true
|
|
1158
|
+
})); // Return the drawer.
|
|
1159
|
+
|
|
1160
|
+
return drawer;
|
|
1161
|
+
};
|
|
1162
|
+
|
|
896
1163
|
var _this2 = this;
|
|
897
1164
|
|
|
898
|
-
|
|
1165
|
+
// Get the drawer from collection.
|
|
1166
|
+
var drawer = getDrawer.call(_this2, query); // Get the modal configuration.
|
|
899
1167
|
|
|
900
|
-
|
|
1168
|
+
var config = _extends({}, _this2.settings, drawer.settings); // Add transition parameter to configuration.
|
|
901
1169
|
|
|
902
|
-
if (hasClass(drawer, _this2.settings.stateOpened)) {
|
|
903
|
-
_this2.working = true;
|
|
904
1170
|
|
|
905
|
-
|
|
906
|
-
setInert(false, _this2.settings.selectorInert);
|
|
907
|
-
setOverflowHidden(false, _this2.settings.selectorOverflow);
|
|
908
|
-
}
|
|
1171
|
+
if (transition !== undefined) config.transition = transition; // If drawer is closed.
|
|
909
1172
|
|
|
910
|
-
|
|
911
|
-
|
|
1173
|
+
var _temp4 = function () {
|
|
1174
|
+
if (drawer.state === 'closed') {
|
|
1175
|
+
// Update drawer state.
|
|
1176
|
+
drawer.state = 'opening'; // Run the open transition.
|
|
912
1177
|
|
|
913
|
-
|
|
1178
|
+
return Promise.resolve(openTransition(drawer.el, config)).then(function () {
|
|
1179
|
+
// Update the global state if mode is modal.
|
|
1180
|
+
if (drawer.mode === 'modal') updateGlobalState(true, config); // Update drawer state.
|
|
914
1181
|
|
|
915
|
-
|
|
1182
|
+
drawer.state = 'opened';
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
}();
|
|
916
1186
|
|
|
917
|
-
|
|
918
|
-
detail: _this2,
|
|
919
|
-
bubbles: true
|
|
920
|
-
}));
|
|
921
|
-
_this2.working = false;
|
|
922
|
-
return drawer;
|
|
923
|
-
});
|
|
924
|
-
} else {
|
|
925
|
-
return Promise.resolve(drawer);
|
|
926
|
-
}
|
|
1187
|
+
return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(_temp3) : _temp3(_temp4));
|
|
927
1188
|
} catch (e) {
|
|
928
1189
|
return Promise.reject(e);
|
|
929
1190
|
}
|
|
930
1191
|
};
|
|
931
1192
|
|
|
932
|
-
function
|
|
933
|
-
|
|
934
|
-
|
|
1193
|
+
var close$2 = function close(query, transition, focus) {
|
|
1194
|
+
if (focus === void 0) {
|
|
1195
|
+
focus = true;
|
|
1196
|
+
}
|
|
935
1197
|
|
|
936
|
-
|
|
1198
|
+
try {
|
|
1199
|
+
var _this2 = this;
|
|
937
1200
|
|
|
938
|
-
|
|
939
|
-
var
|
|
940
|
-
this.memory.trigger = trigger;
|
|
941
|
-
this.toggle(selector);
|
|
942
|
-
event.preventDefault();
|
|
943
|
-
return;
|
|
944
|
-
} // Open data trigger
|
|
1201
|
+
// Get the drawer from collection.
|
|
1202
|
+
var drawer = getDrawer.call(_this2, query); // Get the modal configuration.
|
|
945
1203
|
|
|
1204
|
+
var config = _extends({}, _this2.settings, drawer.settings); // Add transition parameter to configuration.
|
|
946
1205
|
|
|
947
|
-
trigger = event.target.closest("[data-" + this.settings.dataOpen + "]");
|
|
948
1206
|
|
|
949
|
-
|
|
950
|
-
var _selector = trigger.getAttribute("data-" + this.settings.dataOpen);
|
|
1207
|
+
if (transition !== undefined) config.transition = transition; // If drawer is opened.
|
|
951
1208
|
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
} // Close data trigger
|
|
1209
|
+
var _temp2 = function () {
|
|
1210
|
+
if (drawer.state === 'opened') {
|
|
1211
|
+
// Update drawer state.
|
|
1212
|
+
drawer.state = 'closing'; // Remove focus from active element.
|
|
957
1213
|
|
|
1214
|
+
document.activeElement.blur(); // Run the close transition.
|
|
958
1215
|
|
|
959
|
-
|
|
1216
|
+
return Promise.resolve(closeTransition(drawer.el, config)).then(function () {
|
|
1217
|
+
// Update the global state if mode is modal.
|
|
1218
|
+
if (drawer.mode === 'modal') updateGlobalState(false, config); // Set focus to the trigger element if the focus param is true.
|
|
960
1219
|
|
|
961
|
-
|
|
962
|
-
|
|
1220
|
+
if (focus) {
|
|
1221
|
+
updateFocusState$1.call(_this2, drawer);
|
|
1222
|
+
} // Update drawer state.
|
|
963
1223
|
|
|
964
|
-
if (_selector2) {
|
|
965
|
-
this.memory.trigger = trigger;
|
|
966
|
-
this.close(_selector2);
|
|
967
|
-
} else {
|
|
968
|
-
var target = event.target.closest("[data-" + this.settings.dataDrawer + "]");
|
|
969
|
-
if (target) this.close(target);
|
|
970
|
-
}
|
|
971
1224
|
|
|
972
|
-
|
|
973
|
-
return;
|
|
974
|
-
} // Screen modal trigger
|
|
1225
|
+
drawer.state = 'closed'; // Dispatch custom closed event.
|
|
975
1226
|
|
|
1227
|
+
drawer.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'closed', {
|
|
1228
|
+
detail: _this2,
|
|
1229
|
+
bubbles: true
|
|
1230
|
+
}));
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
}();
|
|
976
1234
|
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
1235
|
+
return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {
|
|
1236
|
+
// Return the drawer.
|
|
1237
|
+
return drawer;
|
|
1238
|
+
}) : drawer);
|
|
1239
|
+
} catch (e) {
|
|
1240
|
+
return Promise.reject(e);
|
|
980
1241
|
}
|
|
981
|
-
}
|
|
982
|
-
function handlerKeydown$1(event) {
|
|
983
|
-
// Working catch
|
|
984
|
-
if (this.working) return;
|
|
1242
|
+
};
|
|
985
1243
|
|
|
986
|
-
|
|
987
|
-
|
|
1244
|
+
var toggle = function toggle(query, transition, focus) {
|
|
1245
|
+
try {
|
|
1246
|
+
var _this2 = this;
|
|
1247
|
+
|
|
1248
|
+
// Get the drawer from collection.
|
|
1249
|
+
var drawer = getDrawer.call(_this2, query); // Open or close the drawer based on its current state.
|
|
988
1250
|
|
|
989
|
-
if (
|
|
990
|
-
|
|
1251
|
+
if (drawer.state === 'closed') {
|
|
1252
|
+
return Promise.resolve(open$2.call(_this2, drawer, transition, focus));
|
|
1253
|
+
} else {
|
|
1254
|
+
return Promise.resolve(close$2.call(_this2, drawer, transition, focus));
|
|
991
1255
|
}
|
|
1256
|
+
} catch (e) {
|
|
1257
|
+
return Promise.reject(e);
|
|
992
1258
|
}
|
|
993
|
-
}
|
|
1259
|
+
};
|
|
994
1260
|
|
|
995
|
-
var
|
|
1261
|
+
var toModal = function toModal(entry) {
|
|
996
1262
|
try {
|
|
997
|
-
var
|
|
998
|
-
|
|
999
|
-
var drawer = _this2.getDrawer(drawerKey);
|
|
1000
|
-
|
|
1001
|
-
if (!drawer) return Promise.resolve(drawerNotFound(drawerKey));
|
|
1263
|
+
var _this4 = this;
|
|
1002
1264
|
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1265
|
+
// Get the drawer configuration.
|
|
1266
|
+
// Add the modal class.
|
|
1267
|
+
entry.el.classList.add(entry.getSetting('classModal')); // Set aria-modal attribute to true.
|
|
1006
1268
|
|
|
1007
|
-
|
|
1008
|
-
setOverflowHidden(true, _this2.settings.selectorOverflow);
|
|
1009
|
-
}
|
|
1269
|
+
entry.dialog.setAttribute('aria-modal', 'true'); // If there isn't a stored state but also has the opened state class...
|
|
1010
1270
|
|
|
1011
|
-
|
|
1012
|
-
|
|
1271
|
+
if (!_this4.store[entry.id] && entry.el.classList.contains(entry.getSetting('stateOpened'))) {
|
|
1272
|
+
// Save the opened state in local store.
|
|
1273
|
+
_this4.store[entry.id] = 'opened';
|
|
1274
|
+
} // Modal drawer defaults to closed state.
|
|
1013
1275
|
|
|
1014
|
-
if (isModal) {
|
|
1015
|
-
_this2.focusTrap.init(drawer);
|
|
1016
1276
|
|
|
1017
|
-
|
|
1018
|
-
|
|
1277
|
+
return Promise.resolve(close$2.call(_this4, entry, false, false)).then(function () {
|
|
1278
|
+
// Dispatch custom switch event.
|
|
1279
|
+
entry.el.dispatchEvent(new CustomEvent(entry.getSetting('customEventPrefix') + 'switchMode', {
|
|
1280
|
+
detail: _this4,
|
|
1281
|
+
bubbles: true
|
|
1282
|
+
})); // Return the entry.
|
|
1019
1283
|
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
detail: _this2,
|
|
1023
|
-
bubbles: true
|
|
1024
|
-
}));
|
|
1025
|
-
_this2.working = false;
|
|
1026
|
-
return drawer;
|
|
1027
|
-
});
|
|
1028
|
-
} else {
|
|
1029
|
-
focusTarget(drawer, _this2.settings);
|
|
1030
|
-
return Promise.resolve(drawer);
|
|
1031
|
-
}
|
|
1284
|
+
return entry;
|
|
1285
|
+
});
|
|
1032
1286
|
} catch (e) {
|
|
1033
1287
|
return Promise.reject(e);
|
|
1034
1288
|
}
|
|
1035
1289
|
};
|
|
1036
1290
|
|
|
1037
|
-
function
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
var storageCheck = localStorage.getItem(settings.stateKey);
|
|
1291
|
+
var toInline = function toInline(entry) {
|
|
1292
|
+
try {
|
|
1293
|
+
var _this2 = this;
|
|
1042
1294
|
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
} // Set the existing state
|
|
1295
|
+
// Remove the modal class.
|
|
1296
|
+
entry.el.classList.remove(entry.getSetting('classModal')); // Remove the aria-modal attribute.
|
|
1046
1297
|
|
|
1298
|
+
entry.dialog.removeAttribute('aria-modal'); // Update the global state.
|
|
1047
1299
|
|
|
1048
|
-
|
|
1049
|
-
Object.keys(state).forEach(function (key) {
|
|
1050
|
-
var item = document.querySelector("[data-" + settings.dataDrawer + "=\"" + key + "\"]");
|
|
1051
|
-
if (!item) return;
|
|
1052
|
-
state[key] == settings.stateOpened ? addClass(item, settings.stateOpened) : removeClass(item, settings.stateOpened);
|
|
1053
|
-
});
|
|
1054
|
-
return state;
|
|
1055
|
-
}
|
|
1056
|
-
function stateSave(target, settings) {
|
|
1057
|
-
// If save state is disabled
|
|
1058
|
-
if (!settings.stateSave) return stateClear(settings); // Get the currently saved object if it exists
|
|
1300
|
+
updateGlobalState(false, _extends({}, _this2.settings, entry.settings)); // Remove any focus traps.
|
|
1059
1301
|
|
|
1060
|
-
|
|
1302
|
+
_this2.focusTrap.unmount(); // Setup initial state.
|
|
1061
1303
|
|
|
1062
|
-
var drawers = target ? [target] : document.querySelectorAll("[data-" + settings.dataDrawer + "]"); // Loop through drawers and save their states
|
|
1063
1304
|
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1305
|
+
return Promise.resolve(initialState.call(_this2, entry)).then(function () {
|
|
1306
|
+
// Dispatch custom switch event.
|
|
1307
|
+
entry.el.dispatchEvent(new CustomEvent(entry.getSetting('customEventPrefix') + 'switchMode', {
|
|
1308
|
+
detail: _this2,
|
|
1309
|
+
bubbles: true
|
|
1310
|
+
})); // Return the entry.
|
|
1069
1311
|
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
if (localStorage.getItem(settings.stateKey)) {
|
|
1075
|
-
localStorage.removeItem(settings.stateKey);
|
|
1312
|
+
return entry;
|
|
1313
|
+
});
|
|
1314
|
+
} catch (e) {
|
|
1315
|
+
return Promise.reject(e);
|
|
1076
1316
|
}
|
|
1317
|
+
};
|
|
1077
1318
|
|
|
1078
|
-
|
|
1319
|
+
function switchMode(entry) {
|
|
1320
|
+
switch (entry.mode) {
|
|
1321
|
+
case 'inline':
|
|
1322
|
+
return toInline.call(this, entry);
|
|
1323
|
+
|
|
1324
|
+
case 'modal':
|
|
1325
|
+
return toModal.call(this, entry);
|
|
1326
|
+
|
|
1327
|
+
default:
|
|
1328
|
+
throw new Error("\"" + entry.mode + "\" is not a valid drawer mode.");
|
|
1329
|
+
}
|
|
1079
1330
|
}
|
|
1080
1331
|
|
|
1081
|
-
var
|
|
1332
|
+
var register$2 = function register(el, dialog) {
|
|
1082
1333
|
try {
|
|
1083
|
-
var
|
|
1334
|
+
var _this2 = this;
|
|
1084
1335
|
|
|
1085
|
-
//
|
|
1086
|
-
|
|
1336
|
+
// Deregister entry incase it has already been registered.
|
|
1337
|
+
return Promise.resolve(deregister$2.call(_this2, el, false)).then(function () {
|
|
1338
|
+
// Save root this for use inside methods API.
|
|
1339
|
+
var root = _this2; // Create an instance of the Breakpoint class.
|
|
1087
1340
|
|
|
1088
|
-
|
|
1089
|
-
if (!hasClass(drawer, _this4.settings.classModal)) return Promise.resolve(); // Tear down modal state
|
|
1341
|
+
var breakpoint = new Breakpoint(); // Setup methods API.
|
|
1090
1342
|
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1343
|
+
var methods = {
|
|
1344
|
+
open: function open(transition, focus) {
|
|
1345
|
+
return open$2.call(root, this, transition, focus);
|
|
1346
|
+
},
|
|
1347
|
+
close: function close(transition, focus) {
|
|
1348
|
+
return close$2.call(root, this, transition, focus);
|
|
1349
|
+
},
|
|
1350
|
+
toggle: function toggle$1(transition, focus) {
|
|
1351
|
+
return toggle.call(root, this, transition, focus);
|
|
1352
|
+
},
|
|
1353
|
+
deregister: function deregister() {
|
|
1354
|
+
return deregister$2.call(root, this);
|
|
1355
|
+
},
|
|
1356
|
+
mountBreakpoint: function mountBreakpoint() {
|
|
1357
|
+
var value = this.breakpoint;
|
|
1358
|
+
var handler = this.handleBreakpoint.bind(this);
|
|
1359
|
+
breakpoint.mount(value, handler);
|
|
1360
|
+
return this;
|
|
1361
|
+
},
|
|
1362
|
+
unmountBreakpoint: function unmountBreakpoint() {
|
|
1363
|
+
breakpoint.unmount();
|
|
1364
|
+
return this;
|
|
1365
|
+
},
|
|
1366
|
+
handleBreakpoint: function handleBreakpoint(event) {
|
|
1367
|
+
this.mode = event.matches ? 'inline' : 'modal';
|
|
1368
|
+
return this;
|
|
1369
|
+
},
|
|
1370
|
+
getSetting: function getSetting(key) {
|
|
1371
|
+
return key in this.settings ? this.settings[key] : root.settings[key];
|
|
1372
|
+
}
|
|
1373
|
+
}; // Setup the drawer object.
|
|
1094
1374
|
|
|
1095
|
-
|
|
1375
|
+
var entry = _extends({
|
|
1376
|
+
id: el.id,
|
|
1377
|
+
el: el,
|
|
1378
|
+
dialog: dialog,
|
|
1379
|
+
trigger: null,
|
|
1380
|
+
settings: getConfig$1(el, _this2.settings.dataConfig),
|
|
1096
1381
|
|
|
1382
|
+
get breakpoint() {
|
|
1383
|
+
return getBreakpoint.call(root, el);
|
|
1384
|
+
},
|
|
1097
1385
|
|
|
1098
|
-
|
|
1099
|
-
|
|
1386
|
+
get state() {
|
|
1387
|
+
return __state;
|
|
1388
|
+
},
|
|
1100
1389
|
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
removeClass(drawer, _this4.settings.stateClosed);
|
|
1104
|
-
} // Dispatch custom event
|
|
1390
|
+
set state(value) {
|
|
1391
|
+
__state = value; // Save 'opened' and 'closed' states to store if mode is inline.
|
|
1105
1392
|
|
|
1393
|
+
if (value === 'opened' || value === 'closed') {
|
|
1394
|
+
if (this.mode === 'inline') root.store[this.id] = this.state;
|
|
1395
|
+
}
|
|
1396
|
+
},
|
|
1106
1397
|
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
return Promise.resolve(drawer);
|
|
1111
|
-
} catch (e) {
|
|
1112
|
-
return Promise.reject(e);
|
|
1113
|
-
}
|
|
1114
|
-
};
|
|
1115
|
-
var switchToModal = function switchToModal(drawerKey) {
|
|
1116
|
-
try {
|
|
1117
|
-
var _this2 = this;
|
|
1398
|
+
get mode() {
|
|
1399
|
+
return __mode;
|
|
1400
|
+
},
|
|
1118
1401
|
|
|
1119
|
-
|
|
1120
|
-
|
|
1402
|
+
set mode(value) {
|
|
1403
|
+
__mode = value;
|
|
1404
|
+
switchMode.call(root, this);
|
|
1405
|
+
}
|
|
1121
1406
|
|
|
1122
|
-
|
|
1123
|
-
if (hasClass(drawer, _this2.settings.classModal)) return Promise.resolve(); // Enable modal state
|
|
1407
|
+
}, methods); // Create the state var with the initial state.
|
|
1124
1408
|
|
|
1125
|
-
addClass(drawer, _this2.settings.classModal);
|
|
1126
|
-
addClass(drawer, _this2.settings.stateClosed);
|
|
1127
|
-
removeClass(drawer, _this2.settings.stateOpened); // Dispatch custom event
|
|
1128
1409
|
|
|
1129
|
-
|
|
1130
|
-
bubbles: true
|
|
1131
|
-
}));
|
|
1132
|
-
return Promise.resolve(drawer);
|
|
1133
|
-
} catch (e) {
|
|
1134
|
-
return Promise.reject(e);
|
|
1135
|
-
}
|
|
1136
|
-
};
|
|
1410
|
+
var __state = el.classList.contains(entry.getSetting('stateOpened')) ? 'opened' : 'closed'; // Create the mode var with the initial mode.
|
|
1137
1411
|
|
|
1138
|
-
var toggle = function toggle(drawerKey) {
|
|
1139
|
-
try {
|
|
1140
|
-
var _this2 = this;
|
|
1141
1412
|
|
|
1142
|
-
|
|
1413
|
+
var __mode = el.classList.contains(entry.getSetting('classModal')) ? 'modal' : 'inline'; // Setup mode specific attributes.
|
|
1143
1414
|
|
|
1144
|
-
if (!drawer) return Promise.resolve(drawerNotFound(drawerKey));
|
|
1145
|
-
var isClosed = !hasClass(drawer, _this2.settings.stateOpened);
|
|
1146
1415
|
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1416
|
+
if (entry.mode === 'modal') {
|
|
1417
|
+
// Set aria-modal attribute to true.
|
|
1418
|
+
entry.dialog.setAttribute('aria-modal', 'true');
|
|
1419
|
+
} else {
|
|
1420
|
+
// Remove the aria-modal attribute.
|
|
1421
|
+
entry.dialog.removeAttribute('aria-modal');
|
|
1422
|
+
} // Set tabindex="-1" so dialog is focusable via JS or click.
|
|
1423
|
+
|
|
1424
|
+
|
|
1425
|
+
if (entry.getSetting('setTabindex')) {
|
|
1426
|
+
entry.dialog.setAttribute('tabindex', '-1');
|
|
1427
|
+
} // Add entry to collection.
|
|
1428
|
+
|
|
1429
|
+
|
|
1430
|
+
_this2.collection.push(entry); // If the entry has a breakpoint...
|
|
1431
|
+
|
|
1432
|
+
|
|
1433
|
+
var _temp = function () {
|
|
1434
|
+
if (entry.breakpoint) {
|
|
1435
|
+
// Mount media query breakpoint functionality.
|
|
1436
|
+
entry.mountBreakpoint();
|
|
1437
|
+
} else {
|
|
1438
|
+
// Else, Setup initial state.
|
|
1439
|
+
return Promise.resolve(initialState.call(_this2, entry)).then(function () {});
|
|
1440
|
+
}
|
|
1441
|
+
}();
|
|
1442
|
+
|
|
1443
|
+
return _temp && _temp.then ? _temp.then(function () {
|
|
1444
|
+
// Return the registered entry.
|
|
1445
|
+
return entry;
|
|
1446
|
+
}) : entry;
|
|
1447
|
+
});
|
|
1152
1448
|
} catch (e) {
|
|
1153
1449
|
return Promise.reject(e);
|
|
1154
1450
|
}
|
|
1155
1451
|
};
|
|
1156
1452
|
|
|
1157
|
-
var
|
|
1453
|
+
var _handleClick$1 = /*#__PURE__*/_classPrivateFieldLooseKey("handleClick");
|
|
1454
|
+
|
|
1455
|
+
var _handleKeydown$2 = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
|
|
1456
|
+
|
|
1457
|
+
var Drawer = /*#__PURE__*/function (_Collection) {
|
|
1458
|
+
_inheritsLoose(Drawer, _Collection);
|
|
1459
|
+
|
|
1158
1460
|
function Drawer(options) {
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1461
|
+
var _this;
|
|
1462
|
+
|
|
1463
|
+
_this = _Collection.call(this) || this;
|
|
1464
|
+
Object.defineProperty(_assertThisInitialized(_this), _handleClick$1, {
|
|
1465
|
+
writable: true,
|
|
1466
|
+
value: void 0
|
|
1467
|
+
});
|
|
1468
|
+
Object.defineProperty(_assertThisInitialized(_this), _handleKeydown$2, {
|
|
1469
|
+
writable: true,
|
|
1470
|
+
value: void 0
|
|
1471
|
+
});
|
|
1472
|
+
_this.defaults = defaults$2;
|
|
1473
|
+
_this.settings = _extends({}, _this.defaults, options);
|
|
1474
|
+
_this.focusTrap = new FocusTrap(); // Setup local store for inline drawer state management.
|
|
1475
|
+
|
|
1476
|
+
_this.store = localStore(_this.settings.storeKey, _this.settings.store);
|
|
1477
|
+
_classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleClick$1)[_handleClick$1] = handleClick$2.bind(_assertThisInitialized(_this));
|
|
1478
|
+
_classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleKeydown$2)[_handleKeydown$2] = handleKeydown$2.bind(_assertThisInitialized(_this));
|
|
1479
|
+
if (_this.settings.autoInit) _this.init();
|
|
1480
|
+
return _this;
|
|
1169
1481
|
}
|
|
1170
1482
|
|
|
1171
1483
|
var _proto = Drawer.prototype;
|
|
@@ -1175,109 +1487,91 @@ var Drawer = /*#__PURE__*/function () {
|
|
|
1175
1487
|
options = null;
|
|
1176
1488
|
}
|
|
1177
1489
|
|
|
1178
|
-
|
|
1179
|
-
|
|
1490
|
+
try {
|
|
1491
|
+
var _this3 = this;
|
|
1180
1492
|
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1493
|
+
// Update settings with passed options.
|
|
1494
|
+
if (options) _this3.settings = _extends({}, _this3.settings, options); // Get all the modals.
|
|
1495
|
+
|
|
1496
|
+
var drawers = document.querySelectorAll(_this3.settings.selectorDrawer); // Register the collections array with modal instances.
|
|
1184
1497
|
|
|
1185
|
-
|
|
1498
|
+
return Promise.resolve(_this3.registerCollection(drawers)).then(function () {
|
|
1499
|
+
// If eventListeners are enabled, init event listeners.
|
|
1500
|
+
if (_this3.settings.eventListeners) {
|
|
1501
|
+
_this3.initEventListeners();
|
|
1502
|
+
}
|
|
1186
1503
|
|
|
1187
|
-
|
|
1188
|
-
|
|
1504
|
+
return _this3;
|
|
1505
|
+
});
|
|
1506
|
+
} catch (e) {
|
|
1507
|
+
return Promise.reject(e);
|
|
1189
1508
|
}
|
|
1190
1509
|
};
|
|
1191
1510
|
|
|
1192
1511
|
_proto.destroy = function destroy() {
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1512
|
+
try {
|
|
1513
|
+
var _this5 = this;
|
|
1514
|
+
|
|
1515
|
+
// Remove all entries from the collection.
|
|
1516
|
+
return Promise.resolve(_this5.deregisterCollection()).then(function () {
|
|
1517
|
+
// If eventListeners are enabled, init event listeners.
|
|
1518
|
+
if (_this5.settings.eventListeners) {
|
|
1519
|
+
_this5.destroyEventListeners();
|
|
1520
|
+
}
|
|
1197
1521
|
|
|
1198
|
-
|
|
1199
|
-
|
|
1522
|
+
return _this5;
|
|
1523
|
+
});
|
|
1524
|
+
} catch (e) {
|
|
1525
|
+
return Promise.reject(e);
|
|
1200
1526
|
}
|
|
1201
|
-
}
|
|
1202
|
-
/**
|
|
1203
|
-
* Event listeners
|
|
1204
|
-
*/
|
|
1205
|
-
;
|
|
1527
|
+
};
|
|
1206
1528
|
|
|
1207
1529
|
_proto.initEventListeners = function initEventListeners() {
|
|
1208
|
-
document.addEventListener('click', this
|
|
1209
|
-
document.addEventListener('touchend', this
|
|
1210
|
-
document.addEventListener('keydown', this
|
|
1530
|
+
document.addEventListener('click', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
|
|
1531
|
+
document.addEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
|
|
1532
|
+
document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$2)[_handleKeydown$2], false);
|
|
1211
1533
|
};
|
|
1212
1534
|
|
|
1213
1535
|
_proto.destroyEventListeners = function destroyEventListeners() {
|
|
1214
|
-
document.removeEventListener('click', this
|
|
1215
|
-
document.removeEventListener('touchend', this
|
|
1216
|
-
document.removeEventListener('keydown', this
|
|
1217
|
-
}
|
|
1218
|
-
/**
|
|
1219
|
-
* Helpers
|
|
1220
|
-
*/
|
|
1221
|
-
;
|
|
1222
|
-
|
|
1223
|
-
_proto.getDrawer = function getDrawer$1(drawerKey) {
|
|
1224
|
-
return getDrawer.call(this, drawerKey);
|
|
1536
|
+
document.removeEventListener('click', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
|
|
1537
|
+
document.removeEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
|
|
1538
|
+
document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$2)[_handleKeydown$2], false);
|
|
1225
1539
|
};
|
|
1226
1540
|
|
|
1227
|
-
_proto.
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
* Save state functionality
|
|
1232
|
-
*/
|
|
1233
|
-
;
|
|
1234
|
-
|
|
1235
|
-
_proto.stateSet = function stateSet$1() {
|
|
1236
|
-
this.state = stateSet(this.settings);
|
|
1541
|
+
_proto.register = function register(query) {
|
|
1542
|
+
var els = getDrawerElements.call(this, query);
|
|
1543
|
+
if (els.error) return Promise.reject(els.error);
|
|
1544
|
+
return register$2.call(this, els.drawer, els.dialog);
|
|
1237
1545
|
};
|
|
1238
1546
|
|
|
1239
|
-
_proto.
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
}
|
|
1243
|
-
|
|
1244
|
-
this.state = stateSave(target, this.settings);
|
|
1547
|
+
_proto.deregister = function deregister(query) {
|
|
1548
|
+
var entry = this.get(getDrawerID.call(this, query));
|
|
1549
|
+
return deregister$2.call(this, entry);
|
|
1245
1550
|
};
|
|
1246
1551
|
|
|
1247
|
-
_proto.
|
|
1248
|
-
this
|
|
1249
|
-
}
|
|
1250
|
-
/**
|
|
1251
|
-
* SwitchTo functionality
|
|
1252
|
-
*/
|
|
1253
|
-
;
|
|
1254
|
-
|
|
1255
|
-
_proto.switchToDefault = function switchToDefault$1(drawerKey) {
|
|
1256
|
-
return switchToDefault.call(this, drawerKey);
|
|
1552
|
+
_proto.open = function open(id, transition, focus) {
|
|
1553
|
+
return open$2.call(this, id, transition, focus);
|
|
1257
1554
|
};
|
|
1258
1555
|
|
|
1259
|
-
_proto.
|
|
1260
|
-
return
|
|
1261
|
-
}
|
|
1262
|
-
/**
|
|
1263
|
-
* Change state functionality
|
|
1264
|
-
*/
|
|
1265
|
-
;
|
|
1266
|
-
|
|
1267
|
-
_proto.toggle = function toggle$1(drawerKey) {
|
|
1268
|
-
return toggle.call(this, drawerKey);
|
|
1556
|
+
_proto.close = function close(id, transition, focus) {
|
|
1557
|
+
return close$2.call(this, id, transition, focus);
|
|
1269
1558
|
};
|
|
1270
1559
|
|
|
1271
|
-
_proto.
|
|
1272
|
-
return
|
|
1560
|
+
_proto.toggle = function toggle$1(id, transition, focus) {
|
|
1561
|
+
return toggle.call(this, id, transition, focus);
|
|
1273
1562
|
};
|
|
1274
1563
|
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1564
|
+
_createClass(Drawer, [{
|
|
1565
|
+
key: "activeModal",
|
|
1566
|
+
get: function get() {
|
|
1567
|
+
return this.collection.find(function (entry) {
|
|
1568
|
+
return entry.state === 'opened' && entry.mode === 'modal';
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
}]);
|
|
1278
1572
|
|
|
1279
1573
|
return Drawer;
|
|
1280
|
-
}();
|
|
1574
|
+
}(Collection);
|
|
1281
1575
|
|
|
1282
1576
|
var defaults$1 = {
|
|
1283
1577
|
autoInit: false,
|
|
@@ -1307,38 +1601,6 @@ var defaults$1 = {
|
|
|
1307
1601
|
transition: true
|
|
1308
1602
|
};
|
|
1309
1603
|
|
|
1310
|
-
function updateGlobalState() {
|
|
1311
|
-
// Set inert state based on if a modal is active.
|
|
1312
|
-
setInert(!!this.active, this.settings.selectorInert); // Set overflow state based on if a modal is active.
|
|
1313
|
-
|
|
1314
|
-
setOverflowHidden(!!this.active, this.settings.selectorOverflow); // Update the z-index of the stack.
|
|
1315
|
-
|
|
1316
|
-
updateStackIndex(this.stack);
|
|
1317
|
-
}
|
|
1318
|
-
function updateFocusState() {
|
|
1319
|
-
// Check if there's an active modal
|
|
1320
|
-
if (this.active) {
|
|
1321
|
-
// Set focus and init focus trap on active modal.
|
|
1322
|
-
focusTarget(this.active.target, this.settings);
|
|
1323
|
-
this.focusTrap.init(this.active.target);
|
|
1324
|
-
} else {
|
|
1325
|
-
// Set focus to root trigger and destroy focus trap.
|
|
1326
|
-
focusTrigger(this);
|
|
1327
|
-
this.focusTrap.destroy();
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
function updateStackIndex(stack) {
|
|
1331
|
-
stack.forEach(function (entry, index) {
|
|
1332
|
-
entry.target.style.zIndex = null;
|
|
1333
|
-
var value = getComputedStyle(entry.target)['z-index'];
|
|
1334
|
-
entry.target.style.zIndex = parseInt(value) + index + 1;
|
|
1335
|
-
});
|
|
1336
|
-
}
|
|
1337
|
-
function getConfig$1(el) {
|
|
1338
|
-
var string = el.getAttribute("data-" + this.settings.dataConfig) || '';
|
|
1339
|
-
var json = string.replace(/'/g, '"');
|
|
1340
|
-
return json ? JSON.parse(json) : {};
|
|
1341
|
-
}
|
|
1342
1604
|
function getModal(query) {
|
|
1343
1605
|
// Get the entry from collection.
|
|
1344
1606
|
var entry = typeof query === 'string' ? this.get(query) : this.get(query.id); // Return entry if it was resolved, otherwise throw error.
|
|
@@ -1346,9 +1608,10 @@ function getModal(query) {
|
|
|
1346
1608
|
if (entry) {
|
|
1347
1609
|
return entry;
|
|
1348
1610
|
} else {
|
|
1349
|
-
throw new Error("Modal not found in collection with id of \"" + query + "\".");
|
|
1611
|
+
throw new Error("Modal not found in collection with id of \"" + (query.id || query) + "\".");
|
|
1350
1612
|
}
|
|
1351
1613
|
}
|
|
1614
|
+
|
|
1352
1615
|
function getModalID(obj) {
|
|
1353
1616
|
// If it's a string, return the string.
|
|
1354
1617
|
if (typeof obj === 'string') {
|
|
@@ -1364,7 +1627,7 @@ function getModalID(obj) {
|
|
|
1364
1627
|
} // If it's a modal replace trigger, return data value.
|
|
1365
1628
|
else if (obj.hasAttribute("data-" + this.settings.dataReplace)) {
|
|
1366
1629
|
return obj.getAttribute("data-" + this.settings.dataReplace);
|
|
1367
|
-
} // If it's a modal
|
|
1630
|
+
} // If it's a modal element, return the id.
|
|
1368
1631
|
else if (obj.closest(this.settings.selectorModal)) {
|
|
1369
1632
|
obj = obj.closest(this.settings.selectorModal);
|
|
1370
1633
|
return obj.id || false;
|
|
@@ -1376,14 +1639,15 @@ function getModalID(obj) {
|
|
|
1376
1639
|
} // Return false if no id was found.
|
|
1377
1640
|
else return false;
|
|
1378
1641
|
}
|
|
1642
|
+
|
|
1379
1643
|
function getModalElements(query) {
|
|
1380
1644
|
var id = getModalID.call(this, query);
|
|
1381
1645
|
|
|
1382
1646
|
if (id) {
|
|
1383
|
-
var
|
|
1384
|
-
var dialog =
|
|
1647
|
+
var modal = document.querySelector("#" + id);
|
|
1648
|
+
var dialog = modal ? modal.querySelector(this.settings.selectorDialog) : null;
|
|
1385
1649
|
|
|
1386
|
-
if (!
|
|
1650
|
+
if (!modal && !dialog) {
|
|
1387
1651
|
return {
|
|
1388
1652
|
error: new Error("No modal elements found using the ID: \"" + id + "\".")
|
|
1389
1653
|
};
|
|
@@ -1393,7 +1657,7 @@ function getModalElements(query) {
|
|
|
1393
1657
|
};
|
|
1394
1658
|
} else {
|
|
1395
1659
|
return {
|
|
1396
|
-
|
|
1660
|
+
modal: modal,
|
|
1397
1661
|
dialog: dialog
|
|
1398
1662
|
};
|
|
1399
1663
|
}
|
|
@@ -1404,7 +1668,31 @@ function getModalElements(query) {
|
|
|
1404
1668
|
}
|
|
1405
1669
|
}
|
|
1406
1670
|
|
|
1407
|
-
|
|
1671
|
+
function updateFocusState() {
|
|
1672
|
+
// Check if there's an active modal
|
|
1673
|
+
if (this.active) {
|
|
1674
|
+
// Mount the focus trap on the active modal.
|
|
1675
|
+
this.focusTrap.mount(this.active.dialog, this.settings.selectorFocus);
|
|
1676
|
+
} else {
|
|
1677
|
+
// Set focus to root trigger and unmount the focus trap.
|
|
1678
|
+
if (this.trigger) {
|
|
1679
|
+
this.trigger.focus();
|
|
1680
|
+
this.trigger = null;
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
this.focusTrap.unmount();
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
function updateStackIndex(stack) {
|
|
1688
|
+
stack.forEach(function (entry, index) {
|
|
1689
|
+
entry.el.style.zIndex = null;
|
|
1690
|
+
var value = getComputedStyle(entry.el)['z-index'];
|
|
1691
|
+
entry.el.style.zIndex = parseInt(value) + index + 1;
|
|
1692
|
+
});
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
var handleClick$1 = function handleClick(event) {
|
|
1408
1696
|
try {
|
|
1409
1697
|
var _this2 = this;
|
|
1410
1698
|
|
|
@@ -1415,7 +1703,7 @@ var handleClick = function handleClick(event) {
|
|
|
1415
1703
|
event.preventDefault(); // Save the trigger if it's not coming from inside a modal.
|
|
1416
1704
|
|
|
1417
1705
|
var fromModal = event.target.closest(_this2.settings.selectorModal);
|
|
1418
|
-
if (!fromModal) _this2.
|
|
1706
|
+
if (!fromModal) _this2.trigger = trigger; // Get the modal.
|
|
1419
1707
|
|
|
1420
1708
|
var modal = _this2.get(getModalID.call(_this2, trigger)); // Depending on the button type, either open or replace the modal.
|
|
1421
1709
|
|
|
@@ -1444,7 +1732,7 @@ var handleClick = function handleClick(event) {
|
|
|
1444
1732
|
return Promise.reject(e);
|
|
1445
1733
|
}
|
|
1446
1734
|
};
|
|
1447
|
-
function handleKeydown(event) {
|
|
1735
|
+
function handleKeydown$1(event) {
|
|
1448
1736
|
// If escape key was pressed.
|
|
1449
1737
|
if (event.key === 'Escape') {
|
|
1450
1738
|
// If a modal is opened and not required, close the modal.
|
|
@@ -1519,20 +1807,20 @@ var deregister$1 = function deregister(obj, close) {
|
|
|
1519
1807
|
}
|
|
1520
1808
|
};
|
|
1521
1809
|
|
|
1522
|
-
var open$1 = function open(query, transition,
|
|
1523
|
-
if (
|
|
1524
|
-
|
|
1810
|
+
var open$1 = function open(query, transition, focus) {
|
|
1811
|
+
if (focus === void 0) {
|
|
1812
|
+
focus = true;
|
|
1525
1813
|
}
|
|
1526
1814
|
|
|
1527
1815
|
try {
|
|
1528
1816
|
var _temp3 = function _temp3() {
|
|
1529
|
-
// Update
|
|
1530
|
-
if (
|
|
1817
|
+
// Update focus if the focus param is true.
|
|
1818
|
+
if (focus) {
|
|
1531
1819
|
updateFocusState.call(_this2);
|
|
1532
1820
|
} // Dispatch custom opened event.
|
|
1533
1821
|
|
|
1534
1822
|
|
|
1535
|
-
modal.
|
|
1823
|
+
modal.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'opened', {
|
|
1536
1824
|
detail: _this2,
|
|
1537
1825
|
bubbles: true
|
|
1538
1826
|
})); // Return the modal.
|
|
@@ -1569,14 +1857,14 @@ var open$1 = function open(query, transition, bulk) {
|
|
|
1569
1857
|
// Update modal state.
|
|
1570
1858
|
modal.state = 'opening'; // Apply z-index styles based on stack length.
|
|
1571
1859
|
|
|
1572
|
-
modal.
|
|
1573
|
-
var value = getComputedStyle(modal.
|
|
1574
|
-
modal.
|
|
1860
|
+
modal.el.style.zIndex = null;
|
|
1861
|
+
var value = getComputedStyle(modal.el)['z-index'];
|
|
1862
|
+
modal.el.style.zIndex = parseInt(value) + _this2.stack.length + 1; // Store modal in stack array.
|
|
1575
1863
|
|
|
1576
1864
|
_this2.stack.push(modal); // Run the open transition.
|
|
1577
1865
|
|
|
1578
1866
|
|
|
1579
|
-
return Promise.resolve(openTransition(modal.
|
|
1867
|
+
return Promise.resolve(openTransition(modal.el, config)).then(function () {
|
|
1580
1868
|
// Update modal state.
|
|
1581
1869
|
modal.state = 'opened';
|
|
1582
1870
|
});
|
|
@@ -1589,9 +1877,9 @@ var open$1 = function open(query, transition, bulk) {
|
|
|
1589
1877
|
}
|
|
1590
1878
|
};
|
|
1591
1879
|
|
|
1592
|
-
var close$1 = function close(query, transition,
|
|
1593
|
-
if (
|
|
1594
|
-
|
|
1880
|
+
var close$1 = function close(query, transition, focus) {
|
|
1881
|
+
if (focus === void 0) {
|
|
1882
|
+
focus = true;
|
|
1595
1883
|
}
|
|
1596
1884
|
|
|
1597
1885
|
try {
|
|
@@ -1612,26 +1900,26 @@ var close$1 = function close(query, transition, bulk) {
|
|
|
1612
1900
|
|
|
1613
1901
|
document.activeElement.blur(); // Run the close transition.
|
|
1614
1902
|
|
|
1615
|
-
return Promise.resolve(closeTransition(modal.
|
|
1903
|
+
return Promise.resolve(closeTransition(modal.el, config)).then(function () {
|
|
1616
1904
|
// Remove z-index styles.
|
|
1617
|
-
modal.
|
|
1905
|
+
modal.el.style.zIndex = null; // Get index of modal in stack array.
|
|
1618
1906
|
|
|
1619
1907
|
var index = _this2.stack.findIndex(function (entry) {
|
|
1620
1908
|
return entry.id === modal.id;
|
|
1621
1909
|
}); // Remove modal from stack array.
|
|
1622
1910
|
|
|
1623
1911
|
|
|
1624
|
-
_this2.stack.splice(index, 1); // Update
|
|
1912
|
+
_this2.stack.splice(index, 1); // Update focus if the focus param is true.
|
|
1625
1913
|
|
|
1626
1914
|
|
|
1627
|
-
if (
|
|
1915
|
+
if (focus) {
|
|
1628
1916
|
updateFocusState.call(_this2);
|
|
1629
1917
|
} // Update modal state.
|
|
1630
1918
|
|
|
1631
1919
|
|
|
1632
1920
|
modal.state = 'closed'; // Dispatch custom closed event.
|
|
1633
1921
|
|
|
1634
|
-
modal.
|
|
1922
|
+
modal.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'closed', {
|
|
1635
1923
|
detail: _this2,
|
|
1636
1924
|
bubbles: true
|
|
1637
1925
|
}));
|
|
@@ -1664,7 +1952,7 @@ var closeAll$1 = function closeAll(exclude, transition) {
|
|
|
1664
1952
|
Promise.resolve();
|
|
1665
1953
|
} else {
|
|
1666
1954
|
var _push2 = result.push;
|
|
1667
|
-
return Promise.resolve(close$1.call(_this2, modal, transition,
|
|
1955
|
+
return Promise.resolve(close$1.call(_this2, modal, transition, false)).then(function (_close$call) {
|
|
1668
1956
|
_push2.call(result, _close$call);
|
|
1669
1957
|
});
|
|
1670
1958
|
}
|
|
@@ -1682,11 +1970,18 @@ var closeAll$1 = function closeAll(exclude, transition) {
|
|
|
1682
1970
|
}
|
|
1683
1971
|
};
|
|
1684
1972
|
|
|
1685
|
-
var replace = function replace(query, transition) {
|
|
1973
|
+
var replace = function replace(query, transition, focus) {
|
|
1974
|
+
if (focus === void 0) {
|
|
1975
|
+
focus = true;
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1686
1978
|
try {
|
|
1687
1979
|
var _temp3 = function _temp3() {
|
|
1688
|
-
// Update the focus
|
|
1689
|
-
|
|
1980
|
+
// Update focus if the focus param is true.
|
|
1981
|
+
if (focus) {
|
|
1982
|
+
updateFocusState.call(_this2);
|
|
1983
|
+
} // Return the modals there were opened and closed.
|
|
1984
|
+
|
|
1690
1985
|
|
|
1691
1986
|
return {
|
|
1692
1987
|
opened: resultOpened,
|
|
@@ -1710,7 +2005,7 @@ var replace = function replace(query, transition) {
|
|
|
1710
2005
|
});
|
|
1711
2006
|
} else {
|
|
1712
2007
|
// If modal is closed, close all and open replacement at the same time.
|
|
1713
|
-
resultOpened = open$1.call(_this2, modal, transition,
|
|
2008
|
+
resultOpened = open$1.call(_this2, modal, transition, false);
|
|
1714
2009
|
resultClosed = closeAll$1.call(_this2, false, transition);
|
|
1715
2010
|
return Promise.resolve(Promise.all([resultOpened, resultClosed])).then(function () {});
|
|
1716
2011
|
}
|
|
@@ -1722,24 +2017,24 @@ var replace = function replace(query, transition) {
|
|
|
1722
2017
|
}
|
|
1723
2018
|
};
|
|
1724
2019
|
|
|
1725
|
-
var register$1 = function register(
|
|
2020
|
+
var register$1 = function register(el, dialog) {
|
|
1726
2021
|
try {
|
|
1727
2022
|
var _this2 = this;
|
|
1728
2023
|
|
|
1729
2024
|
// Deregister entry incase it has already been registered.
|
|
1730
|
-
return Promise.resolve(deregister$1.call(_this2,
|
|
2025
|
+
return Promise.resolve(deregister$1.call(_this2, el, false)).then(function () {
|
|
1731
2026
|
// Save root this for use inside methods API.
|
|
1732
2027
|
var root = _this2; // Setup methods API.
|
|
1733
2028
|
|
|
1734
2029
|
var methods = {
|
|
1735
|
-
open: function open(transition) {
|
|
1736
|
-
return open$1.call(root, this, transition);
|
|
2030
|
+
open: function open(transition, focus) {
|
|
2031
|
+
return open$1.call(root, this, transition, focus);
|
|
1737
2032
|
},
|
|
1738
|
-
close: function close(transition) {
|
|
1739
|
-
return close$1.call(root, this, transition);
|
|
2033
|
+
close: function close(transition, focus) {
|
|
2034
|
+
return close$1.call(root, this, transition, focus);
|
|
1740
2035
|
},
|
|
1741
|
-
replace: function replace$1(transition) {
|
|
1742
|
-
return replace.call(root, this, transition);
|
|
2036
|
+
replace: function replace$1(transition, focus) {
|
|
2037
|
+
return replace.call(root, this, transition, focus);
|
|
1743
2038
|
},
|
|
1744
2039
|
deregister: function deregister() {
|
|
1745
2040
|
return deregister$1.call(root, this);
|
|
@@ -1754,19 +2049,19 @@ var register$1 = function register(target, dialog) {
|
|
|
1754
2049
|
}
|
|
1755
2050
|
|
|
1756
2051
|
if (!this.returnRef) {
|
|
1757
|
-
this.returnRef = teleport(this.
|
|
1758
|
-
return this.
|
|
2052
|
+
this.returnRef = teleport(this.el, ref, method);
|
|
2053
|
+
return this.el;
|
|
1759
2054
|
} else {
|
|
1760
|
-
console.error('Element has already been teleported:', this.
|
|
2055
|
+
console.error('Element has already been teleported:', this.el);
|
|
1761
2056
|
return false;
|
|
1762
2057
|
}
|
|
1763
2058
|
},
|
|
1764
2059
|
teleportReturn: function teleportReturn() {
|
|
1765
2060
|
if (this.returnRef) {
|
|
1766
|
-
this.returnRef = teleport(this.
|
|
1767
|
-
return this.
|
|
2061
|
+
this.returnRef = teleport(this.el, this.returnRef);
|
|
2062
|
+
return this.el;
|
|
1768
2063
|
} else {
|
|
1769
|
-
console.error('No return reference found:', this.
|
|
2064
|
+
console.error('No return reference found:', this.el);
|
|
1770
2065
|
return false;
|
|
1771
2066
|
}
|
|
1772
2067
|
},
|
|
@@ -1776,12 +2071,12 @@ var register$1 = function register(target, dialog) {
|
|
|
1776
2071
|
}; // Setup the modal object.
|
|
1777
2072
|
|
|
1778
2073
|
var entry = _extends({
|
|
1779
|
-
id:
|
|
2074
|
+
id: el.id,
|
|
1780
2075
|
state: 'closed',
|
|
1781
|
-
|
|
1782
|
-
target: target,
|
|
2076
|
+
el: el,
|
|
1783
2077
|
dialog: dialog,
|
|
1784
|
-
returnRef: null
|
|
2078
|
+
returnRef: null,
|
|
2079
|
+
settings: getConfig$1(el, _this2.settings.dataConfig)
|
|
1785
2080
|
}, methods); // Set aria-modal attribute to true.
|
|
1786
2081
|
|
|
1787
2082
|
|
|
@@ -1805,25 +2100,33 @@ var register$1 = function register(target, dialog) {
|
|
|
1805
2100
|
_this2.collection.push(entry); // Setup initial state.
|
|
1806
2101
|
|
|
1807
2102
|
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
entry.target.classList.add(_this2.settings.stateClosed);
|
|
1817
|
-
} // Return the registered entry.
|
|
2103
|
+
var _temp = function () {
|
|
2104
|
+
if (entry.el.classList.contains(_this2.settings.stateOpened)) {
|
|
2105
|
+
// Open entry with transitions disabled.
|
|
2106
|
+
return Promise.resolve(entry.open(false)).then(function () {});
|
|
2107
|
+
} else {
|
|
2108
|
+
// Remove transition state classes.
|
|
2109
|
+
entry.el.classList.remove(_this2.settings.stateOpening);
|
|
2110
|
+
entry.el.classList.remove(_this2.settings.stateClosing); // Add closed state class.
|
|
1818
2111
|
|
|
2112
|
+
entry.el.classList.add(_this2.settings.stateClosed);
|
|
2113
|
+
}
|
|
2114
|
+
}();
|
|
1819
2115
|
|
|
1820
|
-
return
|
|
2116
|
+
return _temp && _temp.then ? _temp.then(function () {
|
|
2117
|
+
// Return the registered entry.
|
|
2118
|
+
return entry;
|
|
2119
|
+
}) : entry;
|
|
1821
2120
|
});
|
|
1822
2121
|
} catch (e) {
|
|
1823
2122
|
return Promise.reject(e);
|
|
1824
2123
|
}
|
|
1825
2124
|
};
|
|
1826
2125
|
|
|
2126
|
+
var _handleClick = /*#__PURE__*/_classPrivateFieldLooseKey("handleClick");
|
|
2127
|
+
|
|
2128
|
+
var _handleKeydown$1 = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
|
|
2129
|
+
|
|
1827
2130
|
var Modal = /*#__PURE__*/function (_Collection) {
|
|
1828
2131
|
_inheritsLoose(Modal, _Collection);
|
|
1829
2132
|
|
|
@@ -1831,24 +2134,33 @@ var Modal = /*#__PURE__*/function (_Collection) {
|
|
|
1831
2134
|
var _this;
|
|
1832
2135
|
|
|
1833
2136
|
_this = _Collection.call(this) || this;
|
|
2137
|
+
Object.defineProperty(_assertThisInitialized(_this), _handleClick, {
|
|
2138
|
+
writable: true,
|
|
2139
|
+
value: void 0
|
|
2140
|
+
});
|
|
2141
|
+
Object.defineProperty(_assertThisInitialized(_this), _handleKeydown$1, {
|
|
2142
|
+
writable: true,
|
|
2143
|
+
value: void 0
|
|
2144
|
+
});
|
|
1834
2145
|
_this.defaults = defaults$1;
|
|
1835
2146
|
_this.settings = _extends({}, _this.defaults, options);
|
|
1836
|
-
_this.
|
|
2147
|
+
_this.trigger = null;
|
|
1837
2148
|
_this.focusTrap = new FocusTrap(); // Setup a proxy for stack array.
|
|
1838
2149
|
|
|
1839
2150
|
_this.stack = new Proxy([], {
|
|
1840
2151
|
set: function set(target, property, value) {
|
|
1841
|
-
target[property] = value; // Update global state
|
|
2152
|
+
target[property] = value; // Update global state if stack length changed.
|
|
1842
2153
|
|
|
1843
2154
|
if (property === 'length') {
|
|
1844
|
-
updateGlobalState
|
|
2155
|
+
updateGlobalState(_this.active, _this.settings);
|
|
2156
|
+
updateStackIndex(_this.stack);
|
|
1845
2157
|
}
|
|
1846
2158
|
|
|
1847
2159
|
return true;
|
|
1848
2160
|
}
|
|
1849
2161
|
});
|
|
1850
|
-
_this
|
|
1851
|
-
_this
|
|
2162
|
+
_classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleClick)[_handleClick] = handleClick$1.bind(_assertThisInitialized(_this));
|
|
2163
|
+
_classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleKeydown$1)[_handleKeydown$1] = handleKeydown$1.bind(_assertThisInitialized(_this));
|
|
1852
2164
|
if (_this.settings.autoInit) _this.init();
|
|
1853
2165
|
return _this;
|
|
1854
2166
|
}
|
|
@@ -1865,10 +2177,13 @@ var Modal = /*#__PURE__*/function (_Collection) {
|
|
|
1865
2177
|
var modals = document.querySelectorAll(_this3.settings.selectorModal); // Register the collections array with modal instances.
|
|
1866
2178
|
|
|
1867
2179
|
return Promise.resolve(_this3.registerCollection(modals)).then(function () {
|
|
2180
|
+
// If eventListeners are enabled, init event listeners.
|
|
1868
2181
|
if (_this3.settings.eventListeners) {
|
|
1869
2182
|
_this3.initEventListeners();
|
|
1870
2183
|
}
|
|
1871
|
-
|
|
2184
|
+
|
|
2185
|
+
return _this3;
|
|
2186
|
+
});
|
|
1872
2187
|
} catch (e) {
|
|
1873
2188
|
return Promise.reject(e);
|
|
1874
2189
|
}
|
|
@@ -1878,35 +2193,38 @@ var Modal = /*#__PURE__*/function (_Collection) {
|
|
|
1878
2193
|
try {
|
|
1879
2194
|
var _this5 = this;
|
|
1880
2195
|
|
|
1881
|
-
// Clear
|
|
1882
|
-
_this5.
|
|
2196
|
+
// Clear stored trigger.
|
|
2197
|
+
_this5.trigger = null; // Remove all entries from the collection.
|
|
1883
2198
|
|
|
1884
2199
|
return Promise.resolve(_this5.deregisterCollection()).then(function () {
|
|
2200
|
+
// If eventListeners are enabled, destroy event listeners.
|
|
1885
2201
|
if (_this5.settings.eventListeners) {
|
|
1886
2202
|
_this5.destroyEventListeners();
|
|
1887
2203
|
}
|
|
1888
|
-
|
|
2204
|
+
|
|
2205
|
+
return _this5;
|
|
2206
|
+
});
|
|
1889
2207
|
} catch (e) {
|
|
1890
2208
|
return Promise.reject(e);
|
|
1891
2209
|
}
|
|
1892
2210
|
};
|
|
1893
2211
|
|
|
1894
2212
|
_proto.initEventListeners = function initEventListeners() {
|
|
1895
|
-
document.addEventListener('click', this
|
|
1896
|
-
document.addEventListener('touchend', this
|
|
1897
|
-
document.addEventListener('keydown', this
|
|
2213
|
+
document.addEventListener('click', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
|
|
2214
|
+
document.addEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
|
|
2215
|
+
document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$1)[_handleKeydown$1], false);
|
|
1898
2216
|
};
|
|
1899
2217
|
|
|
1900
2218
|
_proto.destroyEventListeners = function destroyEventListeners() {
|
|
1901
|
-
document.removeEventListener('click', this
|
|
1902
|
-
document.removeEventListener('touchend', this
|
|
1903
|
-
document.removeEventListener('keydown', this
|
|
2219
|
+
document.removeEventListener('click', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
|
|
2220
|
+
document.removeEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
|
|
2221
|
+
document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$1)[_handleKeydown$1], false);
|
|
1904
2222
|
};
|
|
1905
2223
|
|
|
1906
2224
|
_proto.register = function register(query) {
|
|
1907
2225
|
var els = getModalElements.call(this, query);
|
|
1908
2226
|
if (els.error) return Promise.reject(els.error);
|
|
1909
|
-
return register$1.call(this, els.
|
|
2227
|
+
return register$1.call(this, els.modal, els.dialog);
|
|
1910
2228
|
};
|
|
1911
2229
|
|
|
1912
2230
|
_proto.deregister = function deregister(query) {
|
|
@@ -1914,28 +2232,36 @@ var Modal = /*#__PURE__*/function (_Collection) {
|
|
|
1914
2232
|
return deregister$1.call(this, modal);
|
|
1915
2233
|
};
|
|
1916
2234
|
|
|
1917
|
-
_proto.open = function open(id, transition) {
|
|
1918
|
-
return open$1.call(this, id, transition);
|
|
2235
|
+
_proto.open = function open(id, transition, focus) {
|
|
2236
|
+
return open$1.call(this, id, transition, focus);
|
|
1919
2237
|
};
|
|
1920
2238
|
|
|
1921
|
-
_proto.close = function close(id, transition) {
|
|
1922
|
-
return close$1.call(this, id, transition);
|
|
2239
|
+
_proto.close = function close(id, transition, focus) {
|
|
2240
|
+
return close$1.call(this, id, transition, focus);
|
|
1923
2241
|
};
|
|
1924
2242
|
|
|
1925
|
-
_proto.replace = function replace$1(id, transition) {
|
|
1926
|
-
return replace.call(this, id, transition);
|
|
2243
|
+
_proto.replace = function replace$1(id, transition, focus) {
|
|
2244
|
+
return replace.call(this, id, transition, focus);
|
|
1927
2245
|
};
|
|
1928
2246
|
|
|
1929
|
-
_proto.closeAll = function closeAll(exclude, transition) {
|
|
2247
|
+
_proto.closeAll = function closeAll(exclude, transition, focus) {
|
|
1930
2248
|
if (exclude === void 0) {
|
|
1931
2249
|
exclude = false;
|
|
1932
2250
|
}
|
|
1933
2251
|
|
|
2252
|
+
if (focus === void 0) {
|
|
2253
|
+
focus = true;
|
|
2254
|
+
}
|
|
2255
|
+
|
|
1934
2256
|
try {
|
|
1935
2257
|
var _this7 = this;
|
|
1936
2258
|
|
|
1937
2259
|
return Promise.resolve(closeAll$1.call(_this7, exclude, transition)).then(function (result) {
|
|
1938
|
-
|
|
2260
|
+
// Update focus if the focus param is true.
|
|
2261
|
+
if (focus) {
|
|
2262
|
+
updateFocusState.call(_this7);
|
|
2263
|
+
}
|
|
2264
|
+
|
|
1939
2265
|
return result;
|
|
1940
2266
|
});
|
|
1941
2267
|
} catch (e) {
|
|
@@ -1982,7 +2308,7 @@ function getConfig(el, settings) {
|
|
|
1982
2308
|
|
|
1983
2309
|
for (var prop in config) {
|
|
1984
2310
|
// Get the CSS variable property values.
|
|
1985
|
-
var prefix =
|
|
2311
|
+
var prefix = L();
|
|
1986
2312
|
var value = styles.getPropertyValue("--" + prefix + "popover-" + prop).trim(); // If a value was found, replace the default in config obj.
|
|
1987
2313
|
|
|
1988
2314
|
if (value) {
|
|
@@ -1993,6 +2319,7 @@ function getConfig(el, settings) {
|
|
|
1993
2319
|
|
|
1994
2320
|
return config;
|
|
1995
2321
|
}
|
|
2322
|
+
|
|
1996
2323
|
function getPadding(value) {
|
|
1997
2324
|
var padding; // Split the value by spaces if it's a string.
|
|
1998
2325
|
|
|
@@ -2042,6 +2369,7 @@ function getPadding(value) {
|
|
|
2042
2369
|
|
|
2043
2370
|
return padding;
|
|
2044
2371
|
}
|
|
2372
|
+
|
|
2045
2373
|
function getModifiers(options) {
|
|
2046
2374
|
return [{
|
|
2047
2375
|
name: 'offset',
|
|
@@ -2066,6 +2394,7 @@ function getModifiers(options) {
|
|
|
2066
2394
|
}
|
|
2067
2395
|
}];
|
|
2068
2396
|
}
|
|
2397
|
+
|
|
2069
2398
|
function getPopover(query) {
|
|
2070
2399
|
// Get the entry from collection.
|
|
2071
2400
|
var entry = typeof query === 'string' ? this.get(query) : this.get(query.id); // Return entry if it was resolved, otherwise throw error.
|
|
@@ -2076,13 +2405,14 @@ function getPopover(query) {
|
|
|
2076
2405
|
throw new Error("Popover not found in collection with id of \"" + query + "\".");
|
|
2077
2406
|
}
|
|
2078
2407
|
}
|
|
2408
|
+
|
|
2079
2409
|
function getPopoverID(obj) {
|
|
2080
2410
|
// If it's a string, return the string.
|
|
2081
2411
|
if (typeof obj === 'string') {
|
|
2082
2412
|
return obj;
|
|
2083
2413
|
} // If it's an HTML element.
|
|
2084
2414
|
else if (typeof obj.hasAttribute === 'function') {
|
|
2085
|
-
// If it's a popover
|
|
2415
|
+
// If it's a popover element, return the id.
|
|
2086
2416
|
if (obj.closest(this.settings.selectorPopover)) {
|
|
2087
2417
|
obj = obj.closest(this.settings.selectorPopover);
|
|
2088
2418
|
return obj.id;
|
|
@@ -2100,14 +2430,15 @@ function getPopoverID(obj) {
|
|
|
2100
2430
|
} // Return false if no id was found.
|
|
2101
2431
|
else return false;
|
|
2102
2432
|
}
|
|
2433
|
+
|
|
2103
2434
|
function getPopoverElements(query) {
|
|
2104
2435
|
var id = getPopoverID.call(this, query);
|
|
2105
2436
|
|
|
2106
2437
|
if (id) {
|
|
2438
|
+
var popover = document.querySelector("#" + id);
|
|
2107
2439
|
var trigger = document.querySelector("[aria-controls=\"" + id + "\"]") || document.querySelector("[aria-describedby=\"" + id + "\"]");
|
|
2108
|
-
var target = document.querySelector("#" + id);
|
|
2109
2440
|
|
|
2110
|
-
if (!trigger && !
|
|
2441
|
+
if (!trigger && !popover) {
|
|
2111
2442
|
return {
|
|
2112
2443
|
error: new Error("No popover elements found using the ID: \"" + id + "\".")
|
|
2113
2444
|
};
|
|
@@ -2115,14 +2446,14 @@ function getPopoverElements(query) {
|
|
|
2115
2446
|
return {
|
|
2116
2447
|
error: new Error('No popover trigger associated with the provided popover.')
|
|
2117
2448
|
};
|
|
2118
|
-
} else if (!
|
|
2449
|
+
} else if (!popover) {
|
|
2119
2450
|
return {
|
|
2120
2451
|
error: new Error('No popover associated with the provided popover trigger.')
|
|
2121
2452
|
};
|
|
2122
2453
|
} else {
|
|
2123
2454
|
return {
|
|
2124
|
-
|
|
2125
|
-
|
|
2455
|
+
popover: popover,
|
|
2456
|
+
trigger: trigger
|
|
2126
2457
|
};
|
|
2127
2458
|
}
|
|
2128
2459
|
} else {
|
|
@@ -2165,7 +2496,7 @@ var close = function close(query) {
|
|
|
2165
2496
|
// If a modal exists and its state is opened.
|
|
2166
2497
|
if (popover && popover.state === 'opened') {
|
|
2167
2498
|
// Update state class.
|
|
2168
|
-
popover.
|
|
2499
|
+
popover.el.classList.remove(_this2.settings.stateActive); // Update accessibility attribute(s).
|
|
2169
2500
|
|
|
2170
2501
|
if (popover.trigger.hasAttribute('aria-controls')) {
|
|
2171
2502
|
popover.trigger.setAttribute('aria-expanded', 'false');
|
|
@@ -2179,10 +2510,10 @@ var close = function close(query) {
|
|
|
2179
2510
|
}]
|
|
2180
2511
|
}); // Update popover state.
|
|
2181
2512
|
|
|
2182
|
-
popover.state = 'closed'; // Clear
|
|
2513
|
+
popover.state = 'closed'; // Clear root trigger if popover trigger matches.
|
|
2183
2514
|
|
|
2184
|
-
if (popover.trigger === _this2.
|
|
2185
|
-
_this2.
|
|
2515
|
+
if (popover.trigger === _this2.trigger) {
|
|
2516
|
+
_this2.trigger = null;
|
|
2186
2517
|
}
|
|
2187
2518
|
} // Return the popover.
|
|
2188
2519
|
|
|
@@ -2203,10 +2534,10 @@ function closeCheck(popover) {
|
|
|
2203
2534
|
if (popover.state != 'opened') return; // Needed to correctly check which element is currently being focused.
|
|
2204
2535
|
|
|
2205
2536
|
setTimeout(function () {
|
|
2206
|
-
// Check if trigger or
|
|
2207
|
-
var isHovered = popover.
|
|
2537
|
+
// Check if trigger or element are being hovered.
|
|
2538
|
+
var isHovered = popover.el.closest(':hover') === popover.el || popover.trigger.closest(':hover') === popover.trigger; // Check if trigger or element are being focused.
|
|
2208
2539
|
|
|
2209
|
-
var isFocused = document.activeElement.closest("#" + popover.id + ", [aria-controls=\"" + popover.id + "\"]"); // Close if the trigger and
|
|
2540
|
+
var isFocused = document.activeElement.closest("#" + popover.id + ", [aria-controls=\"" + popover.id + "\"]"); // Close if the trigger and element are not currently hovered or focused.
|
|
2210
2541
|
|
|
2211
2542
|
if (!isHovered && !isFocused) {
|
|
2212
2543
|
popover.close();
|
|
@@ -2217,22 +2548,22 @@ function closeCheck(popover) {
|
|
|
2217
2548
|
}, 1);
|
|
2218
2549
|
}
|
|
2219
2550
|
|
|
2220
|
-
function
|
|
2551
|
+
function handleClick(popover) {
|
|
2221
2552
|
if (popover.state === 'opened') {
|
|
2222
2553
|
popover.close();
|
|
2223
2554
|
} else {
|
|
2224
|
-
this.
|
|
2555
|
+
this.trigger = popover.trigger;
|
|
2225
2556
|
popover.open();
|
|
2226
|
-
|
|
2557
|
+
handleDocumentClick.call(this, popover);
|
|
2227
2558
|
}
|
|
2228
2559
|
}
|
|
2229
|
-
function
|
|
2560
|
+
function handleKeydown(event) {
|
|
2230
2561
|
var _this = this;
|
|
2231
2562
|
|
|
2232
2563
|
switch (event.key) {
|
|
2233
2564
|
case 'Escape':
|
|
2234
|
-
if (this.
|
|
2235
|
-
this.
|
|
2565
|
+
if (this.trigger) {
|
|
2566
|
+
this.trigger.focus();
|
|
2236
2567
|
}
|
|
2237
2568
|
|
|
2238
2569
|
closeAll.call(this);
|
|
@@ -2248,7 +2579,7 @@ function handlerKeydown(event) {
|
|
|
2248
2579
|
return;
|
|
2249
2580
|
}
|
|
2250
2581
|
}
|
|
2251
|
-
function
|
|
2582
|
+
function handleDocumentClick(popover) {
|
|
2252
2583
|
var root = this;
|
|
2253
2584
|
document.addEventListener('click', function _f(event) {
|
|
2254
2585
|
// Check if a popover was clicked.
|
|
@@ -2256,14 +2587,14 @@ function documentClick(popover) {
|
|
|
2256
2587
|
|
|
2257
2588
|
if (!result) {
|
|
2258
2589
|
// If it doesn't match and popover is open, close it and remove event listener.
|
|
2259
|
-
if (popover.
|
|
2590
|
+
if (popover.el && popover.el.classList.contains(root.settings.stateActive)) {
|
|
2260
2591
|
popover.close();
|
|
2261
2592
|
}
|
|
2262
2593
|
|
|
2263
2594
|
this.removeEventListener('click', _f);
|
|
2264
2595
|
} else {
|
|
2265
2596
|
// If it does match and popover isn't currently active, remove event listener.
|
|
2266
|
-
if (popover.
|
|
2597
|
+
if (popover.el && !popover.el.classList.contains(root.settings.stateActive)) {
|
|
2267
2598
|
this.removeEventListener('click', _f);
|
|
2268
2599
|
}
|
|
2269
2600
|
}
|
|
@@ -4121,14 +4452,14 @@ var open = function open(query) {
|
|
|
4121
4452
|
// Get the popover from collection.
|
|
4122
4453
|
var popover = getPopover.call(_this2, query); // Update state class.
|
|
4123
4454
|
|
|
4124
|
-
popover.
|
|
4455
|
+
popover.el.classList.add(_this2.settings.stateActive); // Update accessibility attribute(s).
|
|
4125
4456
|
|
|
4126
4457
|
if (popover.trigger.hasAttribute('aria-controls')) {
|
|
4127
4458
|
popover.trigger.setAttribute('aria-expanded', 'true');
|
|
4128
4459
|
} // Update popover config.
|
|
4129
4460
|
|
|
4130
4461
|
|
|
4131
|
-
popover.config = getConfig(popover.
|
|
4462
|
+
popover.config = getConfig(popover.el, _this2.settings); // Enable popper event listeners and set placement/modifiers.
|
|
4132
4463
|
|
|
4133
4464
|
popover.popper.setOptions({
|
|
4134
4465
|
placement: popover.config['placement'],
|
|
@@ -4148,12 +4479,12 @@ var open = function open(query) {
|
|
|
4148
4479
|
}
|
|
4149
4480
|
};
|
|
4150
4481
|
|
|
4151
|
-
var register = function register(
|
|
4482
|
+
var register = function register(el, trigger) {
|
|
4152
4483
|
try {
|
|
4153
4484
|
var _this2 = this;
|
|
4154
4485
|
|
|
4155
4486
|
// Deregister entry incase it has already been registered.
|
|
4156
|
-
deregister.call(_this2,
|
|
4487
|
+
deregister.call(_this2, el); // Save root this for use inside methods API.
|
|
4157
4488
|
|
|
4158
4489
|
|
|
4159
4490
|
var root = _this2; // Setup methods API.
|
|
@@ -4171,12 +4502,12 @@ var register = function register(trigger, target) {
|
|
|
4171
4502
|
}; // Setup the popover object.
|
|
4172
4503
|
|
|
4173
4504
|
var entry = _extends({
|
|
4174
|
-
id:
|
|
4505
|
+
id: el.id,
|
|
4175
4506
|
state: 'closed',
|
|
4507
|
+
el: el,
|
|
4176
4508
|
trigger: trigger,
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
config: getConfig(target, _this2.settings)
|
|
4509
|
+
popper: createPopper(trigger, el),
|
|
4510
|
+
config: getConfig(el, _this2.settings)
|
|
4180
4511
|
}, methods); // Set aria-expanded to false if trigger has aria-controls attribute.
|
|
4181
4512
|
|
|
4182
4513
|
|
|
@@ -4191,9 +4522,9 @@ var register = function register(trigger, target) {
|
|
|
4191
4522
|
|
|
4192
4523
|
|
|
4193
4524
|
var _temp2 = function () {
|
|
4194
|
-
if (entry.
|
|
4525
|
+
if (entry.el.classList.contains(_this2.settings.stateActive)) {
|
|
4195
4526
|
return Promise.resolve(entry.open()).then(function () {
|
|
4196
|
-
|
|
4527
|
+
handleDocumentClick.call(_this2, entry);
|
|
4197
4528
|
});
|
|
4198
4529
|
}
|
|
4199
4530
|
}();
|
|
@@ -4219,7 +4550,7 @@ function registerEventListeners(entry) {
|
|
|
4219
4550
|
type: ['mouseenter', 'focus'],
|
|
4220
4551
|
listener: open.bind(this, entry)
|
|
4221
4552
|
}, {
|
|
4222
|
-
el: ['
|
|
4553
|
+
el: ['el', 'trigger'],
|
|
4223
4554
|
type: ['mouseleave', 'focusout'],
|
|
4224
4555
|
listener: closeCheck.bind(this, entry)
|
|
4225
4556
|
}]; // Loop through listeners and apply to the appropriate elements.
|
|
@@ -4237,7 +4568,7 @@ function registerEventListeners(entry) {
|
|
|
4237
4568
|
entry.__eventListeners = [{
|
|
4238
4569
|
el: ['trigger'],
|
|
4239
4570
|
type: ['click'],
|
|
4240
|
-
listener:
|
|
4571
|
+
listener: handleClick.bind(this, entry)
|
|
4241
4572
|
}]; // Loop through listeners and apply to the appropriate elements.
|
|
4242
4573
|
|
|
4243
4574
|
entry.__eventListeners.forEach(function (evObj) {
|
|
@@ -4254,6 +4585,8 @@ function registerEventListeners(entry) {
|
|
|
4254
4585
|
return entry;
|
|
4255
4586
|
}
|
|
4256
4587
|
|
|
4588
|
+
var _handleKeydown = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
|
|
4589
|
+
|
|
4257
4590
|
var Popover = /*#__PURE__*/function (_Collection) {
|
|
4258
4591
|
_inheritsLoose(Popover, _Collection);
|
|
4259
4592
|
|
|
@@ -4261,10 +4594,14 @@ var Popover = /*#__PURE__*/function (_Collection) {
|
|
|
4261
4594
|
var _this;
|
|
4262
4595
|
|
|
4263
4596
|
_this = _Collection.call(this) || this;
|
|
4597
|
+
Object.defineProperty(_assertThisInitialized(_this), _handleKeydown, {
|
|
4598
|
+
writable: true,
|
|
4599
|
+
value: void 0
|
|
4600
|
+
});
|
|
4264
4601
|
_this.defaults = defaults;
|
|
4265
4602
|
_this.settings = _extends({}, _this.defaults, options);
|
|
4266
|
-
_this.
|
|
4267
|
-
_this
|
|
4603
|
+
_this.trigger = null;
|
|
4604
|
+
_classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleKeydown)[_handleKeydown] = handleKeydown.bind(_assertThisInitialized(_this));
|
|
4268
4605
|
if (_this.settings.autoInit) _this.init();
|
|
4269
4606
|
return _this;
|
|
4270
4607
|
}
|
|
@@ -4281,12 +4618,15 @@ var Popover = /*#__PURE__*/function (_Collection) {
|
|
|
4281
4618
|
var popovers = document.querySelectorAll(_this3.settings.selectorPopover); // Register the collections array with popover instances.
|
|
4282
4619
|
|
|
4283
4620
|
return Promise.resolve(_this3.registerCollection(popovers)).then(function () {
|
|
4621
|
+
// If eventListeners are enabled, init event listeners.
|
|
4284
4622
|
if (_this3.settings.eventListeners) {
|
|
4285
4623
|
// Pass false to initEventListeners() since registerCollection()
|
|
4286
4624
|
// already adds event listeners to popovers.
|
|
4287
4625
|
_this3.initEventListeners(false);
|
|
4288
4626
|
}
|
|
4289
|
-
|
|
4627
|
+
|
|
4628
|
+
return _this3;
|
|
4629
|
+
});
|
|
4290
4630
|
} catch (e) {
|
|
4291
4631
|
return Promise.reject(e);
|
|
4292
4632
|
}
|
|
@@ -4296,16 +4636,19 @@ var Popover = /*#__PURE__*/function (_Collection) {
|
|
|
4296
4636
|
try {
|
|
4297
4637
|
var _this5 = this;
|
|
4298
4638
|
|
|
4299
|
-
// Clear
|
|
4300
|
-
_this5.
|
|
4639
|
+
// Clear stored trigger.
|
|
4640
|
+
_this5.trigger = null; // Remove all entries from the collection.
|
|
4301
4641
|
|
|
4302
4642
|
return Promise.resolve(_this5.deregisterCollection()).then(function () {
|
|
4643
|
+
// If eventListeners are enabled, destroy event listeners.
|
|
4303
4644
|
if (_this5.settings.eventListeners) {
|
|
4304
4645
|
// Pass false to destroyEventListeners() since deregisterCollection()
|
|
4305
4646
|
// already removes event listeners from popovers.
|
|
4306
4647
|
_this5.destroyEventListeners(false);
|
|
4307
4648
|
}
|
|
4308
|
-
|
|
4649
|
+
|
|
4650
|
+
return _this5;
|
|
4651
|
+
});
|
|
4309
4652
|
} catch (e) {
|
|
4310
4653
|
return Promise.reject(e);
|
|
4311
4654
|
}
|
|
@@ -4326,7 +4669,7 @@ var Popover = /*#__PURE__*/function (_Collection) {
|
|
|
4326
4669
|
} // Add keydown global event listener.
|
|
4327
4670
|
|
|
4328
4671
|
|
|
4329
|
-
document.addEventListener('keydown', this
|
|
4672
|
+
document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown)[_handleKeydown], false);
|
|
4330
4673
|
};
|
|
4331
4674
|
|
|
4332
4675
|
_proto.destroyEventListeners = function destroyEventListeners(processCollection) {
|
|
@@ -4342,13 +4685,13 @@ var Popover = /*#__PURE__*/function (_Collection) {
|
|
|
4342
4685
|
} // Remove keydown global event listener.
|
|
4343
4686
|
|
|
4344
4687
|
|
|
4345
|
-
document.removeEventListener('keydown', this
|
|
4688
|
+
document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown)[_handleKeydown], false);
|
|
4346
4689
|
};
|
|
4347
4690
|
|
|
4348
4691
|
_proto.register = function register$1(query) {
|
|
4349
4692
|
var els = getPopoverElements.call(this, query);
|
|
4350
4693
|
if (els.error) return Promise.reject(els.error);
|
|
4351
|
-
return register.call(this, els.
|
|
4694
|
+
return register.call(this, els.popover, els.trigger);
|
|
4352
4695
|
};
|
|
4353
4696
|
|
|
4354
4697
|
_proto.deregister = function deregister$1(query) {
|