vrembem 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dev/scripts.esm.js +1117 -776
- package/dev/scripts.esm.js.map +1 -1
- package/dev/scripts.js +1117 -776
- package/dev/scripts.js.map +1 -1
- package/dev/scripts.modern.js +928 -686
- package/dev/scripts.modern.js.map +1 -1
- package/dev/scripts.umd.js +1117 -776
- 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,199 @@ 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
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
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
|
+
}
|
|
599
|
+
|
|
600
|
+
function localStore(key, enable) {
|
|
601
|
+
if (enable === void 0) {
|
|
602
|
+
enable = true;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
function getStore() {
|
|
606
|
+
var value = localStorage.getItem(key);
|
|
607
|
+
return value ? JSON.parse(value) : {};
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
function setStore(obj) {
|
|
611
|
+
localStorage.setItem(key, JSON.stringify(obj));
|
|
612
|
+
}
|
|
494
613
|
|
|
495
|
-
|
|
614
|
+
return new Proxy(getStore(), {
|
|
615
|
+
set: function set(target, property, value) {
|
|
616
|
+
target[property] = value;
|
|
617
|
+
if (enable) setStore(target);
|
|
618
|
+
return true;
|
|
619
|
+
},
|
|
620
|
+
deleteProperty: function deleteProperty(target, property) {
|
|
621
|
+
delete target[property];
|
|
622
|
+
if (enable) setStore(target);
|
|
623
|
+
return true;
|
|
624
|
+
}
|
|
496
625
|
});
|
|
497
|
-
}
|
|
626
|
+
}
|
|
498
627
|
|
|
499
628
|
/**
|
|
500
629
|
* Teleports an element in the DOM based on a reference and teleport method.
|
|
@@ -538,21 +667,6 @@ function teleport(what, where, how) {
|
|
|
538
667
|
return returnRef;
|
|
539
668
|
}
|
|
540
669
|
|
|
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
670
|
var openTransition = function openTransition(el, settings) {
|
|
557
671
|
return new Promise(function (resolve) {
|
|
558
672
|
if (settings.transition) {
|
|
@@ -590,86 +704,53 @@ var closeTransition = function closeTransition(el, settings) {
|
|
|
590
704
|
});
|
|
591
705
|
};
|
|
592
706
|
|
|
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);
|
|
707
|
+
function setOverflowHidden(state, selector) {
|
|
708
|
+
if (selector) {
|
|
709
|
+
var els = document.querySelectorAll(selector);
|
|
710
|
+
els.forEach(function (el) {
|
|
711
|
+
if (state) {
|
|
712
|
+
el.style.overflow = 'hidden';
|
|
713
|
+
} else {
|
|
714
|
+
el.style.removeProperty('overflow');
|
|
715
|
+
}
|
|
716
|
+
});
|
|
620
717
|
}
|
|
621
718
|
}
|
|
622
719
|
|
|
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
|
-
}
|
|
720
|
+
function setInert(state, selector) {
|
|
721
|
+
if (selector) {
|
|
722
|
+
var els = document.querySelectorAll(selector);
|
|
723
|
+
els.forEach(function (el) {
|
|
724
|
+
if (state) {
|
|
725
|
+
el.inert = true;
|
|
726
|
+
el.setAttribute('aria-hidden', true);
|
|
727
|
+
} else {
|
|
728
|
+
el.inert = null;
|
|
729
|
+
el.removeAttribute('aria-hidden');
|
|
641
730
|
}
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
return target;
|
|
645
|
-
};
|
|
646
|
-
|
|
647
|
-
return _extends.apply(this, arguments);
|
|
731
|
+
});
|
|
732
|
+
}
|
|
648
733
|
}
|
|
649
734
|
|
|
650
|
-
function
|
|
651
|
-
|
|
652
|
-
|
|
735
|
+
function updateGlobalState(param, config) {
|
|
736
|
+
// Set inert state based on if a modal is active.
|
|
737
|
+
setInert(!!param, config.selectorInert); // Set overflow state based on if a modal is active.
|
|
653
738
|
|
|
654
|
-
|
|
739
|
+
setOverflowHidden(!!param, config.selectorOverflow);
|
|
655
740
|
}
|
|
656
741
|
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
return self;
|
|
672
|
-
}
|
|
742
|
+
var index = {
|
|
743
|
+
__proto__: null,
|
|
744
|
+
Breakpoint: Breakpoint,
|
|
745
|
+
Collection: Collection,
|
|
746
|
+
FocusTrap: FocusTrap,
|
|
747
|
+
getConfig: getConfig$1,
|
|
748
|
+
localStore: localStore,
|
|
749
|
+
teleport: teleport,
|
|
750
|
+
openTransition: openTransition,
|
|
751
|
+
closeTransition: closeTransition,
|
|
752
|
+
updateGlobalState: updateGlobalState
|
|
753
|
+
};
|
|
673
754
|
|
|
674
755
|
var defaults$3 = {
|
|
675
756
|
autoInit: false,
|
|
@@ -752,16 +833,17 @@ var Checkbox = /*#__PURE__*/function () {
|
|
|
752
833
|
var defaults$2 = {
|
|
753
834
|
autoInit: false,
|
|
754
835
|
// Data attributes
|
|
755
|
-
dataDrawer: 'drawer',
|
|
756
|
-
dataDialog: 'drawer-dialog',
|
|
757
|
-
dataToggle: 'drawer-toggle',
|
|
758
836
|
dataOpen: 'drawer-open',
|
|
759
837
|
dataClose: 'drawer-close',
|
|
838
|
+
dataToggle: 'drawer-toggle',
|
|
760
839
|
dataBreakpoint: 'drawer-breakpoint',
|
|
840
|
+
dataConfig: 'drawer-config',
|
|
761
841
|
// Selectors
|
|
842
|
+
selectorDrawer: '.drawer',
|
|
843
|
+
selectorDialog: '.drawer__dialog',
|
|
762
844
|
selectorFocus: '[data-focus]',
|
|
763
845
|
selectorInert: null,
|
|
764
|
-
selectorOverflow:
|
|
846
|
+
selectorOverflow: 'body',
|
|
765
847
|
// State classes
|
|
766
848
|
stateOpened: 'is-opened',
|
|
767
849
|
stateOpening: 'is-opening',
|
|
@@ -773,399 +855,627 @@ var defaults$2 = {
|
|
|
773
855
|
breakpoints: null,
|
|
774
856
|
customEventPrefix: 'drawer:',
|
|
775
857
|
eventListeners: true,
|
|
776
|
-
|
|
777
|
-
|
|
858
|
+
store: true,
|
|
859
|
+
storeKey: 'VB:DrawerState',
|
|
778
860
|
setTabindex: true,
|
|
779
861
|
transition: true
|
|
780
862
|
};
|
|
781
863
|
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
this.mediaQueryLists = [];
|
|
785
|
-
this.parent = parent;
|
|
786
|
-
this.prefix = this.getVariablePrefix();
|
|
787
|
-
this.__check = this.check.bind(this);
|
|
788
|
-
}
|
|
864
|
+
function handleClick$2(event) {
|
|
865
|
+
var _this = this;
|
|
789
866
|
|
|
790
|
-
|
|
867
|
+
// If an open, close or toggle button was clicked, handle the click event.
|
|
868
|
+
var trigger = event.target.closest("\n [data-" + this.settings.dataOpen + "],\n [data-" + this.settings.dataToggle + "],\n [data-" + this.settings.dataClose + "]\n ");
|
|
791
869
|
|
|
792
|
-
|
|
793
|
-
|
|
870
|
+
if (trigger) {
|
|
871
|
+
// Prevent the default behavior of the trigger.
|
|
872
|
+
event.preventDefault(); // If it's a toggle trigger...
|
|
794
873
|
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
874
|
+
if (trigger.matches("[data-" + this.settings.dataToggle + "]")) {
|
|
875
|
+
var selectors = trigger.getAttribute("data-" + this.settings.dataToggle).trim().split(' ');
|
|
876
|
+
selectors.forEach(function (selector) {
|
|
877
|
+
// Get the entry from collection using the attribute value.
|
|
878
|
+
var entry = _this.get(selector); // Store the trigger on the entry.
|
|
800
879
|
|
|
801
|
-
var bp = _this.getBreakpoint(key);
|
|
802
880
|
|
|
803
|
-
|
|
881
|
+
entry.trigger = trigger; // Toggle the drawer
|
|
804
882
|
|
|
805
|
-
|
|
883
|
+
entry.toggle();
|
|
884
|
+
});
|
|
885
|
+
} // If it's a open trigger...
|
|
806
886
|
|
|
807
887
|
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
} else {
|
|
811
|
-
mql.addListener(_this.__check);
|
|
812
|
-
} // Push to mediaQueryLists array along with drawer ID
|
|
888
|
+
if (trigger.matches("[data-" + this.settings.dataOpen + "]")) {
|
|
889
|
+
var _selectors = trigger.getAttribute("data-" + this.settings.dataOpen).trim().split(' ');
|
|
813
890
|
|
|
891
|
+
_selectors.forEach(function (selector) {
|
|
892
|
+
// Get the entry from collection using the attribute value.
|
|
893
|
+
var entry = _this.get(selector); // Store the trigger on the entry.
|
|
814
894
|
|
|
815
|
-
_this.mediaQueryLists.push({
|
|
816
|
-
'mql': mql,
|
|
817
|
-
'drawer': id
|
|
818
|
-
});
|
|
819
|
-
});
|
|
820
|
-
};
|
|
821
895
|
|
|
822
|
-
|
|
823
|
-
var _this2 = this;
|
|
896
|
+
entry.trigger = trigger; // Open the drawer.
|
|
824
897
|
|
|
825
|
-
|
|
826
|
-
this.mediaQueryLists.forEach(function (item) {
|
|
827
|
-
item.mql.removeListener(_this2.__check);
|
|
898
|
+
entry.open();
|
|
828
899
|
});
|
|
829
|
-
}
|
|
900
|
+
} // If it's a close trigger...
|
|
830
901
|
|
|
831
|
-
this.mediaQueryLists = null;
|
|
832
|
-
};
|
|
833
902
|
|
|
834
|
-
|
|
835
|
-
|
|
903
|
+
if (trigger.matches("[data-" + this.settings.dataClose + "]")) {
|
|
904
|
+
var _selectors2 = trigger.getAttribute("data-" + this.settings.dataClose).trim().split(' ');
|
|
836
905
|
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
906
|
+
_selectors2.forEach(function (selector) {
|
|
907
|
+
if (selector) {
|
|
908
|
+
// Get the entry from collection using the attribute value.
|
|
909
|
+
var entry = _this.get(selector); // Store the trigger on the entry.
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
entry.trigger = trigger; // Close the drawer.
|
|
840
913
|
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
if (drawer) _this3.match(item.mql, drawer);
|
|
914
|
+
entry.close();
|
|
915
|
+
} else {
|
|
916
|
+
// If no value is set on close trigger, get the parent drawer.
|
|
917
|
+
var parent = event.target.closest(_this.settings.selectorDrawer); // If a parent drawer was found, close it.
|
|
918
|
+
|
|
919
|
+
if (parent) _this.close(parent);
|
|
920
|
+
}
|
|
849
921
|
});
|
|
850
|
-
document.dispatchEvent(new CustomEvent(this.parent.settings.customEventPrefix + 'breakpoint', {
|
|
851
|
-
bubbles: true
|
|
852
|
-
}));
|
|
853
922
|
}
|
|
854
|
-
};
|
|
855
923
|
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
924
|
+
return;
|
|
925
|
+
} // If the modal drawer screen was clicked...
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
if (event.target.matches(this.settings.selectorDrawer)) {
|
|
929
|
+
// Close the modal drawer.
|
|
930
|
+
this.close(event.target.id);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
function handleKeydown$2(event) {
|
|
934
|
+
if (event.key === 'Escape') {
|
|
935
|
+
var modal = this.activeModal;
|
|
936
|
+
if (modal) this.close(modal);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
var deregister$2 = function deregister(obj, close) {
|
|
941
|
+
if (close === void 0) {
|
|
942
|
+
close = true;
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
try {
|
|
946
|
+
var _temp5 = function _temp5() {
|
|
947
|
+
// Return the modified collection.
|
|
948
|
+
return _this2.collection;
|
|
949
|
+
};
|
|
950
|
+
|
|
951
|
+
var _this2 = this;
|
|
952
|
+
|
|
953
|
+
// Return collection if nothing was passed.
|
|
954
|
+
if (!obj) return Promise.resolve(_this2.collection); // Check if entry has been registered in the collection.
|
|
955
|
+
|
|
956
|
+
var index = _this2.collection.findIndex(function (entry) {
|
|
957
|
+
return entry.id === obj.id;
|
|
958
|
+
});
|
|
959
|
+
|
|
960
|
+
var _temp6 = function () {
|
|
961
|
+
if (index >= 0) {
|
|
962
|
+
var _temp7 = function _temp7() {
|
|
963
|
+
// Remove entry from local store.
|
|
964
|
+
delete _this2.store[_entry.id]; // Unmount the MatchMedia functionality.
|
|
965
|
+
|
|
966
|
+
_entry.unmountBreakpoint(); // Delete properties from collection entry.
|
|
967
|
+
|
|
968
|
+
|
|
969
|
+
Object.getOwnPropertyNames(_entry).forEach(function (prop) {
|
|
970
|
+
delete _entry[prop];
|
|
971
|
+
}); // Remove entry from collection.
|
|
972
|
+
|
|
973
|
+
_this2.collection.splice(index, 1);
|
|
974
|
+
};
|
|
975
|
+
|
|
976
|
+
// Get the collection entry.
|
|
977
|
+
var _entry = _this2.collection[index]; // If entry is in the opened state.
|
|
978
|
+
|
|
979
|
+
var _temp8 = function () {
|
|
980
|
+
if (close && _entry.state === 'opened') {
|
|
981
|
+
// Close the drawer.
|
|
982
|
+
return Promise.resolve(_entry.close(false)).then(function () {});
|
|
983
|
+
}
|
|
984
|
+
}();
|
|
985
|
+
|
|
986
|
+
return _temp8 && _temp8.then ? _temp8.then(_temp7) : _temp7(_temp8);
|
|
987
|
+
}
|
|
988
|
+
}();
|
|
989
|
+
|
|
990
|
+
return Promise.resolve(_temp6 && _temp6.then ? _temp6.then(_temp5) : _temp5(_temp6));
|
|
991
|
+
} catch (e) {
|
|
992
|
+
return Promise.reject(e);
|
|
993
|
+
}
|
|
994
|
+
};
|
|
995
|
+
|
|
996
|
+
function getBreakpoint(drawer) {
|
|
997
|
+
var prefix = getVariablePrefix();
|
|
998
|
+
var bp = drawer.getAttribute("data-" + this.settings.dataBreakpoint);
|
|
999
|
+
|
|
1000
|
+
if (this.settings.breakpoints && this.settings.breakpoints[bp]) {
|
|
1001
|
+
return this.settings.breakpoints[bp];
|
|
1002
|
+
} else if (getComputedStyle(document.body).getPropertyValue(prefix + bp)) {
|
|
1003
|
+
return getComputedStyle(document.body).getPropertyValue(prefix + bp);
|
|
1004
|
+
} else {
|
|
1005
|
+
return bp;
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
function getVariablePrefix() {
|
|
1010
|
+
var prefix = '--';
|
|
1011
|
+
prefix += getComputedStyle(document.body).getPropertyValue('--vrembem-variable-prefix');
|
|
1012
|
+
prefix += 'breakpoint-';
|
|
1013
|
+
return prefix;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
function getDrawer(query) {
|
|
1017
|
+
// Get the entry from collection.
|
|
1018
|
+
var entry = typeof query === 'string' ? this.get(query) : this.get(query.id); // Return entry if it was resolved, otherwise throw error.
|
|
1019
|
+
|
|
1020
|
+
if (entry) {
|
|
1021
|
+
return entry;
|
|
1022
|
+
} else {
|
|
1023
|
+
throw new Error("Drawer not found in collection with id of \"" + (query.id || query) + "\".");
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
function getDrawerID(obj) {
|
|
1028
|
+
// If it's a string, return the string.
|
|
1029
|
+
if (typeof obj === 'string') {
|
|
1030
|
+
return obj;
|
|
1031
|
+
} // If it's an HTML element.
|
|
1032
|
+
else if (typeof obj.hasAttribute === 'function') {
|
|
1033
|
+
// If it's a drawer open trigger, return data value.
|
|
1034
|
+
if (obj.hasAttribute("data-" + this.settings.dataOpen)) {
|
|
1035
|
+
return obj.getAttribute("data-" + this.settings.dataOpen);
|
|
1036
|
+
} // If it's a drawer close trigger, return data value or false.
|
|
1037
|
+
else if (obj.hasAttribute("data-" + this.settings.dataClose)) {
|
|
1038
|
+
return obj.getAttribute("data-" + this.settings.dataClose) || false;
|
|
1039
|
+
} // If it's a drawer toggle trigger, return data value.
|
|
1040
|
+
else if (obj.hasAttribute("data-" + this.settings.dataToggle)) {
|
|
1041
|
+
return obj.getAttribute("data-" + this.settings.dataToggle);
|
|
1042
|
+
} // If it's a drawer element, return the id.
|
|
1043
|
+
else if (obj.closest(this.settings.selectorDrawer)) {
|
|
1044
|
+
obj = obj.closest(this.settings.selectorDrawer);
|
|
1045
|
+
return obj.id || false;
|
|
1046
|
+
} // Return false if no id was found.
|
|
1047
|
+
else return false;
|
|
1048
|
+
} // If it has an id property, return its value.
|
|
1049
|
+
else if (obj.id) {
|
|
1050
|
+
return obj.id;
|
|
1051
|
+
} // Return false if no id was found.
|
|
1052
|
+
else return false;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
function getDrawerElements(query) {
|
|
1056
|
+
var id = getDrawerID.call(this, query);
|
|
1057
|
+
|
|
1058
|
+
if (id) {
|
|
1059
|
+
var drawer = document.querySelector("#" + id);
|
|
1060
|
+
var dialog = drawer ? drawer.querySelector(this.settings.selectorDialog) : null;
|
|
1061
|
+
|
|
1062
|
+
if (!drawer && !dialog) {
|
|
1063
|
+
return {
|
|
1064
|
+
error: new Error("No drawer elements found using the ID: \"" + id + "\".")
|
|
1065
|
+
};
|
|
1066
|
+
} else if (!dialog) {
|
|
1067
|
+
return {
|
|
1068
|
+
error: new Error('Drawer is missing dialog element.')
|
|
1069
|
+
};
|
|
859
1070
|
} else {
|
|
860
|
-
|
|
1071
|
+
return {
|
|
1072
|
+
drawer: drawer,
|
|
1073
|
+
dialog: dialog
|
|
1074
|
+
};
|
|
861
1075
|
}
|
|
862
|
-
}
|
|
1076
|
+
} else {
|
|
1077
|
+
return {
|
|
1078
|
+
error: new Error('Could not resolve the drawer ID.')
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
863
1082
|
|
|
864
|
-
|
|
865
|
-
|
|
1083
|
+
var initialState = function initialState(entry) {
|
|
1084
|
+
try {
|
|
1085
|
+
var _this2 = this;
|
|
866
1086
|
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
1087
|
+
var _temp3 = function () {
|
|
1088
|
+
if (_this2.store[entry.id]) {
|
|
1089
|
+
var _temp4 = function () {
|
|
1090
|
+
if (_this2.store[entry.id] === 'opened') {
|
|
1091
|
+
return Promise.resolve(entry.open(false, false)).then(function () {});
|
|
1092
|
+
} else {
|
|
1093
|
+
return Promise.resolve(entry.close(false, false)).then(function () {});
|
|
1094
|
+
}
|
|
1095
|
+
}();
|
|
872
1096
|
|
|
873
|
-
|
|
874
|
-
|
|
1097
|
+
if (_temp4 && _temp4.then) return _temp4.then(function () {});
|
|
1098
|
+
} else if (entry.el.classList.contains(_this2.settings.stateOpened)) {
|
|
1099
|
+
// Update drawer state.
|
|
1100
|
+
entry.state = 'opened';
|
|
1101
|
+
} else {
|
|
1102
|
+
// Remove transition state classes.
|
|
1103
|
+
entry.el.classList.remove(_this2.settings.stateOpening);
|
|
1104
|
+
entry.el.classList.remove(_this2.settings.stateClosing); // Add closed state class.
|
|
875
1105
|
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
prefix += 'breakpoint-';
|
|
880
|
-
return prefix;
|
|
881
|
-
};
|
|
1106
|
+
entry.el.classList.add(_this2.settings.stateClosed);
|
|
1107
|
+
}
|
|
1108
|
+
}();
|
|
882
1109
|
|
|
883
|
-
|
|
884
|
-
|
|
1110
|
+
// Setup initial state using the following priority:
|
|
1111
|
+
// 1. If a store state is available, restore from local store.
|
|
1112
|
+
// 2. If opened state class is set, set state to opened.
|
|
1113
|
+
// 3. Else, initialize default state.
|
|
1114
|
+
return Promise.resolve(_temp3 && _temp3.then ? _temp3.then(function () {}) : void 0);
|
|
1115
|
+
} catch (e) {
|
|
1116
|
+
return Promise.reject(e);
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
885
1119
|
|
|
886
|
-
function
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
1120
|
+
function updateFocusState$1(entry) {
|
|
1121
|
+
// Check if there's an active modal
|
|
1122
|
+
if (entry.state === 'opened') {
|
|
1123
|
+
// Mount the focus trap on the opened drawer.
|
|
1124
|
+
if (entry.mode === 'modal') {
|
|
1125
|
+
this.focusTrap.mount(entry.dialog, this.settings.selectorFocus);
|
|
1126
|
+
} else {
|
|
1127
|
+
this.focusTrap.focus(entry.dialog, this.settings.selectorFocus);
|
|
1128
|
+
}
|
|
1129
|
+
} else {
|
|
1130
|
+
// Set focus to root trigger and unmount the focus trap.
|
|
1131
|
+
if (entry.trigger) {
|
|
1132
|
+
entry.trigger.focus();
|
|
1133
|
+
entry.trigger = null;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
this.focusTrap.unmount();
|
|
1137
|
+
}
|
|
892
1138
|
}
|
|
893
1139
|
|
|
894
|
-
var
|
|
1140
|
+
var open$2 = function open(query, transition, focus) {
|
|
1141
|
+
if (focus === void 0) {
|
|
1142
|
+
focus = true;
|
|
1143
|
+
}
|
|
1144
|
+
|
|
895
1145
|
try {
|
|
1146
|
+
var _temp3 = function _temp3() {
|
|
1147
|
+
// Set focus to the drawer element if the focus param is true.
|
|
1148
|
+
if (focus) {
|
|
1149
|
+
updateFocusState$1.call(_this2, drawer);
|
|
1150
|
+
} // Dispatch custom opened event.
|
|
1151
|
+
|
|
1152
|
+
|
|
1153
|
+
drawer.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'opened', {
|
|
1154
|
+
detail: _this2,
|
|
1155
|
+
bubbles: true
|
|
1156
|
+
})); // Return the drawer.
|
|
1157
|
+
|
|
1158
|
+
return drawer;
|
|
1159
|
+
};
|
|
1160
|
+
|
|
896
1161
|
var _this2 = this;
|
|
897
1162
|
|
|
898
|
-
|
|
1163
|
+
// Get the drawer from collection.
|
|
1164
|
+
var drawer = getDrawer.call(_this2, query); // Get the modal configuration.
|
|
899
1165
|
|
|
900
|
-
|
|
1166
|
+
var config = _extends({}, _this2.settings, drawer.settings); // Add transition parameter to configuration.
|
|
901
1167
|
|
|
902
|
-
if (hasClass(drawer, _this2.settings.stateOpened)) {
|
|
903
|
-
_this2.working = true;
|
|
904
1168
|
|
|
905
|
-
|
|
906
|
-
setInert(false, _this2.settings.selectorInert);
|
|
907
|
-
setOverflowHidden(false, _this2.settings.selectorOverflow);
|
|
908
|
-
}
|
|
1169
|
+
if (transition !== undefined) config.transition = transition; // If drawer is closed.
|
|
909
1170
|
|
|
910
|
-
|
|
911
|
-
|
|
1171
|
+
var _temp4 = function () {
|
|
1172
|
+
if (drawer.state === 'closed') {
|
|
1173
|
+
// Update drawer state.
|
|
1174
|
+
drawer.state = 'opening'; // Run the open transition.
|
|
912
1175
|
|
|
913
|
-
|
|
1176
|
+
return Promise.resolve(openTransition(drawer.el, config)).then(function () {
|
|
1177
|
+
// Update the global state if mode is modal.
|
|
1178
|
+
if (drawer.mode === 'modal') updateGlobalState(true, config); // Update drawer state.
|
|
914
1179
|
|
|
915
|
-
|
|
1180
|
+
drawer.state = 'opened';
|
|
1181
|
+
});
|
|
1182
|
+
}
|
|
1183
|
+
}();
|
|
916
1184
|
|
|
917
|
-
|
|
918
|
-
detail: _this2,
|
|
919
|
-
bubbles: true
|
|
920
|
-
}));
|
|
921
|
-
_this2.working = false;
|
|
922
|
-
return drawer;
|
|
923
|
-
});
|
|
924
|
-
} else {
|
|
925
|
-
return Promise.resolve(drawer);
|
|
926
|
-
}
|
|
1185
|
+
return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(_temp3) : _temp3(_temp4));
|
|
927
1186
|
} catch (e) {
|
|
928
1187
|
return Promise.reject(e);
|
|
929
1188
|
}
|
|
930
1189
|
};
|
|
931
1190
|
|
|
932
|
-
function
|
|
933
|
-
|
|
934
|
-
|
|
1191
|
+
var close$2 = function close(query, transition, focus) {
|
|
1192
|
+
if (focus === void 0) {
|
|
1193
|
+
focus = true;
|
|
1194
|
+
}
|
|
935
1195
|
|
|
936
|
-
|
|
1196
|
+
try {
|
|
1197
|
+
var _this2 = this;
|
|
937
1198
|
|
|
938
|
-
|
|
939
|
-
var
|
|
940
|
-
this.memory.trigger = trigger;
|
|
941
|
-
this.toggle(selector);
|
|
942
|
-
event.preventDefault();
|
|
943
|
-
return;
|
|
944
|
-
} // Open data trigger
|
|
1199
|
+
// Get the drawer from collection.
|
|
1200
|
+
var drawer = getDrawer.call(_this2, query); // Get the modal configuration.
|
|
945
1201
|
|
|
1202
|
+
var config = _extends({}, _this2.settings, drawer.settings); // Add transition parameter to configuration.
|
|
946
1203
|
|
|
947
|
-
trigger = event.target.closest("[data-" + this.settings.dataOpen + "]");
|
|
948
1204
|
|
|
949
|
-
|
|
950
|
-
var _selector = trigger.getAttribute("data-" + this.settings.dataOpen);
|
|
1205
|
+
if (transition !== undefined) config.transition = transition; // If drawer is opened.
|
|
951
1206
|
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
} // Close data trigger
|
|
1207
|
+
var _temp2 = function () {
|
|
1208
|
+
if (drawer.state === 'opened') {
|
|
1209
|
+
// Update drawer state.
|
|
1210
|
+
drawer.state = 'closing'; // Remove focus from active element.
|
|
957
1211
|
|
|
1212
|
+
document.activeElement.blur(); // Run the close transition.
|
|
958
1213
|
|
|
959
|
-
|
|
1214
|
+
return Promise.resolve(closeTransition(drawer.el, config)).then(function () {
|
|
1215
|
+
// Update the global state if mode is modal.
|
|
1216
|
+
if (drawer.mode === 'modal') updateGlobalState(false, config); // Set focus to the trigger element if the focus param is true.
|
|
960
1217
|
|
|
961
|
-
|
|
962
|
-
|
|
1218
|
+
if (focus) {
|
|
1219
|
+
updateFocusState$1.call(_this2, drawer);
|
|
1220
|
+
} // Update drawer state.
|
|
963
1221
|
|
|
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
1222
|
|
|
972
|
-
|
|
973
|
-
return;
|
|
974
|
-
} // Screen modal trigger
|
|
1223
|
+
drawer.state = 'closed'; // Dispatch custom closed event.
|
|
975
1224
|
|
|
1225
|
+
drawer.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'closed', {
|
|
1226
|
+
detail: _this2,
|
|
1227
|
+
bubbles: true
|
|
1228
|
+
}));
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
}();
|
|
976
1232
|
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
1233
|
+
return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {
|
|
1234
|
+
// Return the drawer.
|
|
1235
|
+
return drawer;
|
|
1236
|
+
}) : drawer);
|
|
1237
|
+
} catch (e) {
|
|
1238
|
+
return Promise.reject(e);
|
|
980
1239
|
}
|
|
981
|
-
}
|
|
982
|
-
function handlerKeydown$1(event) {
|
|
983
|
-
// Working catch
|
|
984
|
-
if (this.working) return;
|
|
1240
|
+
};
|
|
985
1241
|
|
|
986
|
-
|
|
987
|
-
|
|
1242
|
+
var toggle = function toggle(query, transition, focus) {
|
|
1243
|
+
try {
|
|
1244
|
+
var _this2 = this;
|
|
1245
|
+
|
|
1246
|
+
// Get the drawer from collection.
|
|
1247
|
+
var drawer = getDrawer.call(_this2, query); // Open or close the drawer based on its current state.
|
|
988
1248
|
|
|
989
|
-
if (
|
|
990
|
-
|
|
1249
|
+
if (drawer.state === 'closed') {
|
|
1250
|
+
return Promise.resolve(open$2.call(_this2, drawer, transition, focus));
|
|
1251
|
+
} else {
|
|
1252
|
+
return Promise.resolve(close$2.call(_this2, drawer, transition, focus));
|
|
991
1253
|
}
|
|
1254
|
+
} catch (e) {
|
|
1255
|
+
return Promise.reject(e);
|
|
992
1256
|
}
|
|
993
|
-
}
|
|
1257
|
+
};
|
|
994
1258
|
|
|
995
|
-
var
|
|
1259
|
+
var toModal = function toModal(entry) {
|
|
996
1260
|
try {
|
|
997
|
-
var
|
|
998
|
-
|
|
999
|
-
var drawer = _this2.getDrawer(drawerKey);
|
|
1000
|
-
|
|
1001
|
-
if (!drawer) return Promise.resolve(drawerNotFound(drawerKey));
|
|
1261
|
+
var _this4 = this;
|
|
1002
1262
|
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1263
|
+
// Get the drawer configuration.
|
|
1264
|
+
// Add the modal class.
|
|
1265
|
+
entry.el.classList.add(entry.getSetting('classModal')); // Set aria-modal attribute to true.
|
|
1006
1266
|
|
|
1007
|
-
|
|
1008
|
-
setOverflowHidden(true, _this2.settings.selectorOverflow);
|
|
1009
|
-
}
|
|
1267
|
+
entry.dialog.setAttribute('aria-modal', 'true'); // If there isn't a stored state but also has the opened state class...
|
|
1010
1268
|
|
|
1011
|
-
|
|
1012
|
-
|
|
1269
|
+
if (!_this4.store[entry.id] && entry.el.classList.contains(entry.getSetting('stateOpened'))) {
|
|
1270
|
+
// Save the opened state in local store.
|
|
1271
|
+
_this4.store[entry.id] = 'opened';
|
|
1272
|
+
} // Modal drawer defaults to closed state.
|
|
1013
1273
|
|
|
1014
|
-
if (isModal) {
|
|
1015
|
-
_this2.focusTrap.init(drawer);
|
|
1016
1274
|
|
|
1017
|
-
|
|
1018
|
-
|
|
1275
|
+
return Promise.resolve(close$2.call(_this4, entry, false, false)).then(function () {
|
|
1276
|
+
// Dispatch custom switch event.
|
|
1277
|
+
entry.el.dispatchEvent(new CustomEvent(entry.getSetting('customEventPrefix') + 'switchMode', {
|
|
1278
|
+
detail: _this4,
|
|
1279
|
+
bubbles: true
|
|
1280
|
+
})); // Return the entry.
|
|
1019
1281
|
|
|
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
|
-
}
|
|
1282
|
+
return entry;
|
|
1283
|
+
});
|
|
1032
1284
|
} catch (e) {
|
|
1033
1285
|
return Promise.reject(e);
|
|
1034
1286
|
}
|
|
1035
1287
|
};
|
|
1036
1288
|
|
|
1037
|
-
function
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
var storageCheck = localStorage.getItem(settings.stateKey);
|
|
1289
|
+
var toInline = function toInline(entry) {
|
|
1290
|
+
try {
|
|
1291
|
+
var _this2 = this;
|
|
1042
1292
|
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
} // Set the existing state
|
|
1293
|
+
// Remove the modal class.
|
|
1294
|
+
entry.el.classList.remove(entry.getSetting('classModal')); // Remove the aria-modal attribute.
|
|
1046
1295
|
|
|
1296
|
+
entry.dialog.removeAttribute('aria-modal'); // Update the global state.
|
|
1047
1297
|
|
|
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
|
|
1298
|
+
updateGlobalState(false, _extends({}, _this2.settings, entry.settings)); // Remove any focus traps.
|
|
1059
1299
|
|
|
1060
|
-
|
|
1300
|
+
_this2.focusTrap.unmount(); // Setup initial state.
|
|
1061
1301
|
|
|
1062
|
-
var drawers = target ? [target] : document.querySelectorAll("[data-" + settings.dataDrawer + "]"); // Loop through drawers and save their states
|
|
1063
1302
|
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1303
|
+
return Promise.resolve(initialState.call(_this2, entry)).then(function () {
|
|
1304
|
+
// Dispatch custom switch event.
|
|
1305
|
+
entry.el.dispatchEvent(new CustomEvent(entry.getSetting('customEventPrefix') + 'switchMode', {
|
|
1306
|
+
detail: _this2,
|
|
1307
|
+
bubbles: true
|
|
1308
|
+
})); // Return the entry.
|
|
1069
1309
|
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
if (localStorage.getItem(settings.stateKey)) {
|
|
1075
|
-
localStorage.removeItem(settings.stateKey);
|
|
1310
|
+
return entry;
|
|
1311
|
+
});
|
|
1312
|
+
} catch (e) {
|
|
1313
|
+
return Promise.reject(e);
|
|
1076
1314
|
}
|
|
1315
|
+
};
|
|
1077
1316
|
|
|
1078
|
-
|
|
1317
|
+
function switchMode(entry) {
|
|
1318
|
+
switch (entry.mode) {
|
|
1319
|
+
case 'inline':
|
|
1320
|
+
return toInline.call(this, entry);
|
|
1321
|
+
|
|
1322
|
+
case 'modal':
|
|
1323
|
+
return toModal.call(this, entry);
|
|
1324
|
+
|
|
1325
|
+
default:
|
|
1326
|
+
throw new Error("\"" + entry.mode + "\" is not a valid drawer mode.");
|
|
1327
|
+
}
|
|
1079
1328
|
}
|
|
1080
1329
|
|
|
1081
|
-
var
|
|
1330
|
+
var register$2 = function register(el, dialog) {
|
|
1082
1331
|
try {
|
|
1083
|
-
var
|
|
1332
|
+
var _this2 = this;
|
|
1084
1333
|
|
|
1085
|
-
//
|
|
1086
|
-
|
|
1334
|
+
// Deregister entry incase it has already been registered.
|
|
1335
|
+
return Promise.resolve(deregister$2.call(_this2, el, false)).then(function () {
|
|
1336
|
+
// Save root this for use inside methods API.
|
|
1337
|
+
var root = _this2; // Create an instance of the Breakpoint class.
|
|
1087
1338
|
|
|
1088
|
-
|
|
1089
|
-
if (!hasClass(drawer, _this4.settings.classModal)) return Promise.resolve(); // Tear down modal state
|
|
1339
|
+
var breakpoint = new Breakpoint(); // Setup methods API.
|
|
1090
1340
|
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1341
|
+
var methods = {
|
|
1342
|
+
open: function open(transition, focus) {
|
|
1343
|
+
return open$2.call(root, this, transition, focus);
|
|
1344
|
+
},
|
|
1345
|
+
close: function close(transition, focus) {
|
|
1346
|
+
return close$2.call(root, this, transition, focus);
|
|
1347
|
+
},
|
|
1348
|
+
toggle: function toggle$1(transition, focus) {
|
|
1349
|
+
return toggle.call(root, this, transition, focus);
|
|
1350
|
+
},
|
|
1351
|
+
deregister: function deregister() {
|
|
1352
|
+
return deregister$2.call(root, this);
|
|
1353
|
+
},
|
|
1354
|
+
mountBreakpoint: function mountBreakpoint() {
|
|
1355
|
+
var value = this.breakpoint;
|
|
1356
|
+
var handler = this.handleBreakpoint.bind(this);
|
|
1357
|
+
breakpoint.mount(value, handler);
|
|
1358
|
+
return this;
|
|
1359
|
+
},
|
|
1360
|
+
unmountBreakpoint: function unmountBreakpoint() {
|
|
1361
|
+
breakpoint.unmount();
|
|
1362
|
+
return this;
|
|
1363
|
+
},
|
|
1364
|
+
handleBreakpoint: function handleBreakpoint(event) {
|
|
1365
|
+
this.mode = event.matches ? 'inline' : 'modal';
|
|
1366
|
+
return this;
|
|
1367
|
+
},
|
|
1368
|
+
getSetting: function getSetting(key) {
|
|
1369
|
+
return key in this.settings ? this.settings[key] : root.settings[key];
|
|
1370
|
+
}
|
|
1371
|
+
}; // Setup the drawer object.
|
|
1094
1372
|
|
|
1095
|
-
|
|
1373
|
+
var entry = _extends({
|
|
1374
|
+
id: el.id,
|
|
1375
|
+
el: el,
|
|
1376
|
+
dialog: dialog,
|
|
1377
|
+
trigger: null,
|
|
1378
|
+
settings: getConfig$1(el, _this2.settings.dataConfig),
|
|
1096
1379
|
|
|
1380
|
+
get breakpoint() {
|
|
1381
|
+
return getBreakpoint.call(root, el);
|
|
1382
|
+
},
|
|
1097
1383
|
|
|
1098
|
-
|
|
1099
|
-
|
|
1384
|
+
get state() {
|
|
1385
|
+
return __state;
|
|
1386
|
+
},
|
|
1100
1387
|
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
removeClass(drawer, _this4.settings.stateClosed);
|
|
1104
|
-
} // Dispatch custom event
|
|
1388
|
+
set state(value) {
|
|
1389
|
+
__state = value; // Save 'opened' and 'closed' states to store if mode is inline.
|
|
1105
1390
|
|
|
1391
|
+
if (value === 'opened' || value === 'closed') {
|
|
1392
|
+
if (this.mode === 'inline') root.store[this.id] = this.state;
|
|
1393
|
+
}
|
|
1394
|
+
},
|
|
1106
1395
|
|
|
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;
|
|
1396
|
+
get mode() {
|
|
1397
|
+
return __mode;
|
|
1398
|
+
},
|
|
1118
1399
|
|
|
1119
|
-
|
|
1120
|
-
|
|
1400
|
+
set mode(value) {
|
|
1401
|
+
__mode = value;
|
|
1402
|
+
switchMode.call(root, this);
|
|
1403
|
+
}
|
|
1121
1404
|
|
|
1122
|
-
|
|
1123
|
-
if (hasClass(drawer, _this2.settings.classModal)) return Promise.resolve(); // Enable modal state
|
|
1405
|
+
}, methods); // Create the state var with the initial state.
|
|
1124
1406
|
|
|
1125
|
-
addClass(drawer, _this2.settings.classModal);
|
|
1126
|
-
addClass(drawer, _this2.settings.stateClosed);
|
|
1127
|
-
removeClass(drawer, _this2.settings.stateOpened); // Dispatch custom event
|
|
1128
1407
|
|
|
1129
|
-
|
|
1130
|
-
bubbles: true
|
|
1131
|
-
}));
|
|
1132
|
-
return Promise.resolve(drawer);
|
|
1133
|
-
} catch (e) {
|
|
1134
|
-
return Promise.reject(e);
|
|
1135
|
-
}
|
|
1136
|
-
};
|
|
1408
|
+
var __state = el.classList.contains(entry.getSetting('stateOpened')) ? 'opened' : 'closed'; // Create the mode var with the initial mode.
|
|
1137
1409
|
|
|
1138
|
-
var toggle = function toggle(drawerKey) {
|
|
1139
|
-
try {
|
|
1140
|
-
var _this2 = this;
|
|
1141
1410
|
|
|
1142
|
-
|
|
1411
|
+
var __mode = el.classList.contains(entry.getSetting('classModal')) ? 'modal' : 'inline'; // Setup mode specific attributes.
|
|
1143
1412
|
|
|
1144
|
-
if (!drawer) return Promise.resolve(drawerNotFound(drawerKey));
|
|
1145
|
-
var isClosed = !hasClass(drawer, _this2.settings.stateOpened);
|
|
1146
1413
|
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1414
|
+
if (entry.mode === 'modal') {
|
|
1415
|
+
// Set aria-modal attribute to true.
|
|
1416
|
+
entry.dialog.setAttribute('aria-modal', 'true');
|
|
1417
|
+
} else {
|
|
1418
|
+
// Remove the aria-modal attribute.
|
|
1419
|
+
entry.dialog.removeAttribute('aria-modal');
|
|
1420
|
+
} // Set tabindex="-1" so dialog is focusable via JS or click.
|
|
1421
|
+
|
|
1422
|
+
|
|
1423
|
+
if (entry.getSetting('setTabindex')) {
|
|
1424
|
+
entry.dialog.setAttribute('tabindex', '-1');
|
|
1425
|
+
} // Add entry to collection.
|
|
1426
|
+
|
|
1427
|
+
|
|
1428
|
+
_this2.collection.push(entry); // If the entry has a breakpoint...
|
|
1429
|
+
|
|
1430
|
+
|
|
1431
|
+
var _temp = function () {
|
|
1432
|
+
if (entry.breakpoint) {
|
|
1433
|
+
// Mount media query breakpoint functionality.
|
|
1434
|
+
entry.mountBreakpoint();
|
|
1435
|
+
} else {
|
|
1436
|
+
// Else, Setup initial state.
|
|
1437
|
+
return Promise.resolve(initialState.call(_this2, entry)).then(function () {});
|
|
1438
|
+
}
|
|
1439
|
+
}();
|
|
1440
|
+
|
|
1441
|
+
return _temp && _temp.then ? _temp.then(function () {
|
|
1442
|
+
// Return the registered entry.
|
|
1443
|
+
return entry;
|
|
1444
|
+
}) : entry;
|
|
1445
|
+
});
|
|
1152
1446
|
} catch (e) {
|
|
1153
1447
|
return Promise.reject(e);
|
|
1154
1448
|
}
|
|
1155
1449
|
};
|
|
1156
1450
|
|
|
1157
|
-
var
|
|
1451
|
+
var _handleClick$1 = /*#__PURE__*/_classPrivateFieldLooseKey("handleClick");
|
|
1452
|
+
|
|
1453
|
+
var _handleKeydown$2 = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
|
|
1454
|
+
|
|
1455
|
+
var Drawer = /*#__PURE__*/function (_Collection) {
|
|
1456
|
+
_inheritsLoose(Drawer, _Collection);
|
|
1457
|
+
|
|
1158
1458
|
function Drawer(options) {
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1459
|
+
var _this;
|
|
1460
|
+
|
|
1461
|
+
_this = _Collection.call(this) || this;
|
|
1462
|
+
Object.defineProperty(_assertThisInitialized(_this), _handleClick$1, {
|
|
1463
|
+
writable: true,
|
|
1464
|
+
value: void 0
|
|
1465
|
+
});
|
|
1466
|
+
Object.defineProperty(_assertThisInitialized(_this), _handleKeydown$2, {
|
|
1467
|
+
writable: true,
|
|
1468
|
+
value: void 0
|
|
1469
|
+
});
|
|
1470
|
+
_this.defaults = defaults$2;
|
|
1471
|
+
_this.settings = _extends({}, _this.defaults, options);
|
|
1472
|
+
_this.focusTrap = new FocusTrap(); // Setup local store for inline drawer state management.
|
|
1473
|
+
|
|
1474
|
+
_this.store = localStore(_this.settings.storeKey, _this.settings.store);
|
|
1475
|
+
_classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleClick$1)[_handleClick$1] = handleClick$2.bind(_assertThisInitialized(_this));
|
|
1476
|
+
_classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleKeydown$2)[_handleKeydown$2] = handleKeydown$2.bind(_assertThisInitialized(_this));
|
|
1477
|
+
if (_this.settings.autoInit) _this.init();
|
|
1478
|
+
return _this;
|
|
1169
1479
|
}
|
|
1170
1480
|
|
|
1171
1481
|
var _proto = Drawer.prototype;
|
|
@@ -1175,109 +1485,91 @@ var Drawer = /*#__PURE__*/function () {
|
|
|
1175
1485
|
options = null;
|
|
1176
1486
|
}
|
|
1177
1487
|
|
|
1178
|
-
|
|
1179
|
-
|
|
1488
|
+
try {
|
|
1489
|
+
var _this3 = this;
|
|
1180
1490
|
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1491
|
+
// Update settings with passed options.
|
|
1492
|
+
if (options) _this3.settings = _extends({}, _this3.settings, options); // Get all the modals.
|
|
1493
|
+
|
|
1494
|
+
var drawers = document.querySelectorAll(_this3.settings.selectorDrawer); // Register the collections array with modal instances.
|
|
1184
1495
|
|
|
1185
|
-
|
|
1496
|
+
return Promise.resolve(_this3.registerCollection(drawers)).then(function () {
|
|
1497
|
+
// If eventListeners are enabled, init event listeners.
|
|
1498
|
+
if (_this3.settings.eventListeners) {
|
|
1499
|
+
_this3.initEventListeners();
|
|
1500
|
+
}
|
|
1186
1501
|
|
|
1187
|
-
|
|
1188
|
-
|
|
1502
|
+
return _this3;
|
|
1503
|
+
});
|
|
1504
|
+
} catch (e) {
|
|
1505
|
+
return Promise.reject(e);
|
|
1189
1506
|
}
|
|
1190
1507
|
};
|
|
1191
1508
|
|
|
1192
1509
|
_proto.destroy = function destroy() {
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1510
|
+
try {
|
|
1511
|
+
var _this5 = this;
|
|
1512
|
+
|
|
1513
|
+
// Remove all entries from the collection.
|
|
1514
|
+
return Promise.resolve(_this5.deregisterCollection()).then(function () {
|
|
1515
|
+
// If eventListeners are enabled, init event listeners.
|
|
1516
|
+
if (_this5.settings.eventListeners) {
|
|
1517
|
+
_this5.destroyEventListeners();
|
|
1518
|
+
}
|
|
1197
1519
|
|
|
1198
|
-
|
|
1199
|
-
|
|
1520
|
+
return _this5;
|
|
1521
|
+
});
|
|
1522
|
+
} catch (e) {
|
|
1523
|
+
return Promise.reject(e);
|
|
1200
1524
|
}
|
|
1201
|
-
}
|
|
1202
|
-
/**
|
|
1203
|
-
* Event listeners
|
|
1204
|
-
*/
|
|
1205
|
-
;
|
|
1525
|
+
};
|
|
1206
1526
|
|
|
1207
1527
|
_proto.initEventListeners = function initEventListeners() {
|
|
1208
|
-
document.addEventListener('click', this
|
|
1209
|
-
document.addEventListener('touchend', this
|
|
1210
|
-
document.addEventListener('keydown', this
|
|
1528
|
+
document.addEventListener('click', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
|
|
1529
|
+
document.addEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
|
|
1530
|
+
document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$2)[_handleKeydown$2], false);
|
|
1211
1531
|
};
|
|
1212
1532
|
|
|
1213
1533
|
_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);
|
|
1534
|
+
document.removeEventListener('click', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
|
|
1535
|
+
document.removeEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
|
|
1536
|
+
document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$2)[_handleKeydown$2], false);
|
|
1225
1537
|
};
|
|
1226
1538
|
|
|
1227
|
-
_proto.
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
* Save state functionality
|
|
1232
|
-
*/
|
|
1233
|
-
;
|
|
1234
|
-
|
|
1235
|
-
_proto.stateSet = function stateSet$1() {
|
|
1236
|
-
this.state = stateSet(this.settings);
|
|
1539
|
+
_proto.register = function register(query) {
|
|
1540
|
+
var els = getDrawerElements.call(this, query);
|
|
1541
|
+
if (els.error) return Promise.reject(els.error);
|
|
1542
|
+
return register$2.call(this, els.drawer, els.dialog);
|
|
1237
1543
|
};
|
|
1238
1544
|
|
|
1239
|
-
_proto.
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
}
|
|
1243
|
-
|
|
1244
|
-
this.state = stateSave(target, this.settings);
|
|
1545
|
+
_proto.deregister = function deregister(query) {
|
|
1546
|
+
var entry = this.get(getDrawerID.call(this, query));
|
|
1547
|
+
return deregister$2.call(this, entry);
|
|
1245
1548
|
};
|
|
1246
1549
|
|
|
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);
|
|
1550
|
+
_proto.open = function open(id, transition, focus) {
|
|
1551
|
+
return open$2.call(this, id, transition, focus);
|
|
1257
1552
|
};
|
|
1258
1553
|
|
|
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);
|
|
1554
|
+
_proto.close = function close(id, transition, focus) {
|
|
1555
|
+
return close$2.call(this, id, transition, focus);
|
|
1269
1556
|
};
|
|
1270
1557
|
|
|
1271
|
-
_proto.
|
|
1272
|
-
return
|
|
1558
|
+
_proto.toggle = function toggle$1(id, transition, focus) {
|
|
1559
|
+
return toggle.call(this, id, transition, focus);
|
|
1273
1560
|
};
|
|
1274
1561
|
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1562
|
+
_createClass(Drawer, [{
|
|
1563
|
+
key: "activeModal",
|
|
1564
|
+
get: function get() {
|
|
1565
|
+
return this.collection.find(function (entry) {
|
|
1566
|
+
return entry.state === 'opened' && entry.mode === 'modal';
|
|
1567
|
+
});
|
|
1568
|
+
}
|
|
1569
|
+
}]);
|
|
1278
1570
|
|
|
1279
1571
|
return Drawer;
|
|
1280
|
-
}();
|
|
1572
|
+
}(Collection);
|
|
1281
1573
|
|
|
1282
1574
|
var defaults$1 = {
|
|
1283
1575
|
autoInit: false,
|
|
@@ -1307,38 +1599,6 @@ var defaults$1 = {
|
|
|
1307
1599
|
transition: true
|
|
1308
1600
|
};
|
|
1309
1601
|
|
|
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
1602
|
function getModal(query) {
|
|
1343
1603
|
// Get the entry from collection.
|
|
1344
1604
|
var entry = typeof query === 'string' ? this.get(query) : this.get(query.id); // Return entry if it was resolved, otherwise throw error.
|
|
@@ -1346,9 +1606,10 @@ function getModal(query) {
|
|
|
1346
1606
|
if (entry) {
|
|
1347
1607
|
return entry;
|
|
1348
1608
|
} else {
|
|
1349
|
-
throw new Error("Modal not found in collection with id of \"" + query + "\".");
|
|
1609
|
+
throw new Error("Modal not found in collection with id of \"" + (query.id || query) + "\".");
|
|
1350
1610
|
}
|
|
1351
1611
|
}
|
|
1612
|
+
|
|
1352
1613
|
function getModalID(obj) {
|
|
1353
1614
|
// If it's a string, return the string.
|
|
1354
1615
|
if (typeof obj === 'string') {
|
|
@@ -1364,7 +1625,7 @@ function getModalID(obj) {
|
|
|
1364
1625
|
} // If it's a modal replace trigger, return data value.
|
|
1365
1626
|
else if (obj.hasAttribute("data-" + this.settings.dataReplace)) {
|
|
1366
1627
|
return obj.getAttribute("data-" + this.settings.dataReplace);
|
|
1367
|
-
} // If it's a modal
|
|
1628
|
+
} // If it's a modal element, return the id.
|
|
1368
1629
|
else if (obj.closest(this.settings.selectorModal)) {
|
|
1369
1630
|
obj = obj.closest(this.settings.selectorModal);
|
|
1370
1631
|
return obj.id || false;
|
|
@@ -1376,14 +1637,15 @@ function getModalID(obj) {
|
|
|
1376
1637
|
} // Return false if no id was found.
|
|
1377
1638
|
else return false;
|
|
1378
1639
|
}
|
|
1640
|
+
|
|
1379
1641
|
function getModalElements(query) {
|
|
1380
1642
|
var id = getModalID.call(this, query);
|
|
1381
1643
|
|
|
1382
1644
|
if (id) {
|
|
1383
|
-
var
|
|
1384
|
-
var dialog =
|
|
1645
|
+
var modal = document.querySelector("#" + id);
|
|
1646
|
+
var dialog = modal ? modal.querySelector(this.settings.selectorDialog) : null;
|
|
1385
1647
|
|
|
1386
|
-
if (!
|
|
1648
|
+
if (!modal && !dialog) {
|
|
1387
1649
|
return {
|
|
1388
1650
|
error: new Error("No modal elements found using the ID: \"" + id + "\".")
|
|
1389
1651
|
};
|
|
@@ -1393,7 +1655,7 @@ function getModalElements(query) {
|
|
|
1393
1655
|
};
|
|
1394
1656
|
} else {
|
|
1395
1657
|
return {
|
|
1396
|
-
|
|
1658
|
+
modal: modal,
|
|
1397
1659
|
dialog: dialog
|
|
1398
1660
|
};
|
|
1399
1661
|
}
|
|
@@ -1404,7 +1666,31 @@ function getModalElements(query) {
|
|
|
1404
1666
|
}
|
|
1405
1667
|
}
|
|
1406
1668
|
|
|
1407
|
-
|
|
1669
|
+
function updateFocusState() {
|
|
1670
|
+
// Check if there's an active modal
|
|
1671
|
+
if (this.active) {
|
|
1672
|
+
// Mount the focus trap on the active modal.
|
|
1673
|
+
this.focusTrap.mount(this.active.dialog, this.settings.selectorFocus);
|
|
1674
|
+
} else {
|
|
1675
|
+
// Set focus to root trigger and unmount the focus trap.
|
|
1676
|
+
if (this.trigger) {
|
|
1677
|
+
this.trigger.focus();
|
|
1678
|
+
this.trigger = null;
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
this.focusTrap.unmount();
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
function updateStackIndex(stack) {
|
|
1686
|
+
stack.forEach(function (entry, index) {
|
|
1687
|
+
entry.el.style.zIndex = null;
|
|
1688
|
+
var value = getComputedStyle(entry.el)['z-index'];
|
|
1689
|
+
entry.el.style.zIndex = parseInt(value) + index + 1;
|
|
1690
|
+
});
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
var handleClick$1 = function handleClick(event) {
|
|
1408
1694
|
try {
|
|
1409
1695
|
var _this2 = this;
|
|
1410
1696
|
|
|
@@ -1415,7 +1701,7 @@ var handleClick = function handleClick(event) {
|
|
|
1415
1701
|
event.preventDefault(); // Save the trigger if it's not coming from inside a modal.
|
|
1416
1702
|
|
|
1417
1703
|
var fromModal = event.target.closest(_this2.settings.selectorModal);
|
|
1418
|
-
if (!fromModal) _this2.
|
|
1704
|
+
if (!fromModal) _this2.trigger = trigger; // Get the modal.
|
|
1419
1705
|
|
|
1420
1706
|
var modal = _this2.get(getModalID.call(_this2, trigger)); // Depending on the button type, either open or replace the modal.
|
|
1421
1707
|
|
|
@@ -1444,7 +1730,7 @@ var handleClick = function handleClick(event) {
|
|
|
1444
1730
|
return Promise.reject(e);
|
|
1445
1731
|
}
|
|
1446
1732
|
};
|
|
1447
|
-
function handleKeydown(event) {
|
|
1733
|
+
function handleKeydown$1(event) {
|
|
1448
1734
|
// If escape key was pressed.
|
|
1449
1735
|
if (event.key === 'Escape') {
|
|
1450
1736
|
// If a modal is opened and not required, close the modal.
|
|
@@ -1519,20 +1805,20 @@ var deregister$1 = function deregister(obj, close) {
|
|
|
1519
1805
|
}
|
|
1520
1806
|
};
|
|
1521
1807
|
|
|
1522
|
-
var open$1 = function open(query, transition,
|
|
1523
|
-
if (
|
|
1524
|
-
|
|
1808
|
+
var open$1 = function open(query, transition, focus) {
|
|
1809
|
+
if (focus === void 0) {
|
|
1810
|
+
focus = true;
|
|
1525
1811
|
}
|
|
1526
1812
|
|
|
1527
1813
|
try {
|
|
1528
1814
|
var _temp3 = function _temp3() {
|
|
1529
|
-
// Update
|
|
1530
|
-
if (
|
|
1815
|
+
// Update focus if the focus param is true.
|
|
1816
|
+
if (focus) {
|
|
1531
1817
|
updateFocusState.call(_this2);
|
|
1532
1818
|
} // Dispatch custom opened event.
|
|
1533
1819
|
|
|
1534
1820
|
|
|
1535
|
-
modal.
|
|
1821
|
+
modal.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'opened', {
|
|
1536
1822
|
detail: _this2,
|
|
1537
1823
|
bubbles: true
|
|
1538
1824
|
})); // Return the modal.
|
|
@@ -1569,14 +1855,14 @@ var open$1 = function open(query, transition, bulk) {
|
|
|
1569
1855
|
// Update modal state.
|
|
1570
1856
|
modal.state = 'opening'; // Apply z-index styles based on stack length.
|
|
1571
1857
|
|
|
1572
|
-
modal.
|
|
1573
|
-
var value = getComputedStyle(modal.
|
|
1574
|
-
modal.
|
|
1858
|
+
modal.el.style.zIndex = null;
|
|
1859
|
+
var value = getComputedStyle(modal.el)['z-index'];
|
|
1860
|
+
modal.el.style.zIndex = parseInt(value) + _this2.stack.length + 1; // Store modal in stack array.
|
|
1575
1861
|
|
|
1576
1862
|
_this2.stack.push(modal); // Run the open transition.
|
|
1577
1863
|
|
|
1578
1864
|
|
|
1579
|
-
return Promise.resolve(openTransition(modal.
|
|
1865
|
+
return Promise.resolve(openTransition(modal.el, config)).then(function () {
|
|
1580
1866
|
// Update modal state.
|
|
1581
1867
|
modal.state = 'opened';
|
|
1582
1868
|
});
|
|
@@ -1589,9 +1875,9 @@ var open$1 = function open(query, transition, bulk) {
|
|
|
1589
1875
|
}
|
|
1590
1876
|
};
|
|
1591
1877
|
|
|
1592
|
-
var close$1 = function close(query, transition,
|
|
1593
|
-
if (
|
|
1594
|
-
|
|
1878
|
+
var close$1 = function close(query, transition, focus) {
|
|
1879
|
+
if (focus === void 0) {
|
|
1880
|
+
focus = true;
|
|
1595
1881
|
}
|
|
1596
1882
|
|
|
1597
1883
|
try {
|
|
@@ -1612,26 +1898,26 @@ var close$1 = function close(query, transition, bulk) {
|
|
|
1612
1898
|
|
|
1613
1899
|
document.activeElement.blur(); // Run the close transition.
|
|
1614
1900
|
|
|
1615
|
-
return Promise.resolve(closeTransition(modal.
|
|
1901
|
+
return Promise.resolve(closeTransition(modal.el, config)).then(function () {
|
|
1616
1902
|
// Remove z-index styles.
|
|
1617
|
-
modal.
|
|
1903
|
+
modal.el.style.zIndex = null; // Get index of modal in stack array.
|
|
1618
1904
|
|
|
1619
1905
|
var index = _this2.stack.findIndex(function (entry) {
|
|
1620
1906
|
return entry.id === modal.id;
|
|
1621
1907
|
}); // Remove modal from stack array.
|
|
1622
1908
|
|
|
1623
1909
|
|
|
1624
|
-
_this2.stack.splice(index, 1); // Update
|
|
1910
|
+
_this2.stack.splice(index, 1); // Update focus if the focus param is true.
|
|
1625
1911
|
|
|
1626
1912
|
|
|
1627
|
-
if (
|
|
1913
|
+
if (focus) {
|
|
1628
1914
|
updateFocusState.call(_this2);
|
|
1629
1915
|
} // Update modal state.
|
|
1630
1916
|
|
|
1631
1917
|
|
|
1632
1918
|
modal.state = 'closed'; // Dispatch custom closed event.
|
|
1633
1919
|
|
|
1634
|
-
modal.
|
|
1920
|
+
modal.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'closed', {
|
|
1635
1921
|
detail: _this2,
|
|
1636
1922
|
bubbles: true
|
|
1637
1923
|
}));
|
|
@@ -1664,7 +1950,7 @@ var closeAll$1 = function closeAll(exclude, transition) {
|
|
|
1664
1950
|
Promise.resolve();
|
|
1665
1951
|
} else {
|
|
1666
1952
|
var _push2 = result.push;
|
|
1667
|
-
return Promise.resolve(close$1.call(_this2, modal, transition,
|
|
1953
|
+
return Promise.resolve(close$1.call(_this2, modal, transition, false)).then(function (_close$call) {
|
|
1668
1954
|
_push2.call(result, _close$call);
|
|
1669
1955
|
});
|
|
1670
1956
|
}
|
|
@@ -1682,11 +1968,18 @@ var closeAll$1 = function closeAll(exclude, transition) {
|
|
|
1682
1968
|
}
|
|
1683
1969
|
};
|
|
1684
1970
|
|
|
1685
|
-
var replace = function replace(query, transition) {
|
|
1971
|
+
var replace = function replace(query, transition, focus) {
|
|
1972
|
+
if (focus === void 0) {
|
|
1973
|
+
focus = true;
|
|
1974
|
+
}
|
|
1975
|
+
|
|
1686
1976
|
try {
|
|
1687
1977
|
var _temp3 = function _temp3() {
|
|
1688
|
-
// Update the focus
|
|
1689
|
-
|
|
1978
|
+
// Update focus if the focus param is true.
|
|
1979
|
+
if (focus) {
|
|
1980
|
+
updateFocusState.call(_this2);
|
|
1981
|
+
} // Return the modals there were opened and closed.
|
|
1982
|
+
|
|
1690
1983
|
|
|
1691
1984
|
return {
|
|
1692
1985
|
opened: resultOpened,
|
|
@@ -1710,7 +2003,7 @@ var replace = function replace(query, transition) {
|
|
|
1710
2003
|
});
|
|
1711
2004
|
} else {
|
|
1712
2005
|
// If modal is closed, close all and open replacement at the same time.
|
|
1713
|
-
resultOpened = open$1.call(_this2, modal, transition,
|
|
2006
|
+
resultOpened = open$1.call(_this2, modal, transition, false);
|
|
1714
2007
|
resultClosed = closeAll$1.call(_this2, false, transition);
|
|
1715
2008
|
return Promise.resolve(Promise.all([resultOpened, resultClosed])).then(function () {});
|
|
1716
2009
|
}
|
|
@@ -1722,24 +2015,24 @@ var replace = function replace(query, transition) {
|
|
|
1722
2015
|
}
|
|
1723
2016
|
};
|
|
1724
2017
|
|
|
1725
|
-
var register$1 = function register(
|
|
2018
|
+
var register$1 = function register(el, dialog) {
|
|
1726
2019
|
try {
|
|
1727
2020
|
var _this2 = this;
|
|
1728
2021
|
|
|
1729
2022
|
// Deregister entry incase it has already been registered.
|
|
1730
|
-
return Promise.resolve(deregister$1.call(_this2,
|
|
2023
|
+
return Promise.resolve(deregister$1.call(_this2, el, false)).then(function () {
|
|
1731
2024
|
// Save root this for use inside methods API.
|
|
1732
2025
|
var root = _this2; // Setup methods API.
|
|
1733
2026
|
|
|
1734
2027
|
var methods = {
|
|
1735
|
-
open: function open(transition) {
|
|
1736
|
-
return open$1.call(root, this, transition);
|
|
2028
|
+
open: function open(transition, focus) {
|
|
2029
|
+
return open$1.call(root, this, transition, focus);
|
|
1737
2030
|
},
|
|
1738
|
-
close: function close(transition) {
|
|
1739
|
-
return close$1.call(root, this, transition);
|
|
2031
|
+
close: function close(transition, focus) {
|
|
2032
|
+
return close$1.call(root, this, transition, focus);
|
|
1740
2033
|
},
|
|
1741
|
-
replace: function replace$1(transition) {
|
|
1742
|
-
return replace.call(root, this, transition);
|
|
2034
|
+
replace: function replace$1(transition, focus) {
|
|
2035
|
+
return replace.call(root, this, transition, focus);
|
|
1743
2036
|
},
|
|
1744
2037
|
deregister: function deregister() {
|
|
1745
2038
|
return deregister$1.call(root, this);
|
|
@@ -1754,19 +2047,19 @@ var register$1 = function register(target, dialog) {
|
|
|
1754
2047
|
}
|
|
1755
2048
|
|
|
1756
2049
|
if (!this.returnRef) {
|
|
1757
|
-
this.returnRef = teleport(this.
|
|
1758
|
-
return this.
|
|
2050
|
+
this.returnRef = teleport(this.el, ref, method);
|
|
2051
|
+
return this.el;
|
|
1759
2052
|
} else {
|
|
1760
|
-
console.error('Element has already been teleported:', this.
|
|
2053
|
+
console.error('Element has already been teleported:', this.el);
|
|
1761
2054
|
return false;
|
|
1762
2055
|
}
|
|
1763
2056
|
},
|
|
1764
2057
|
teleportReturn: function teleportReturn() {
|
|
1765
2058
|
if (this.returnRef) {
|
|
1766
|
-
this.returnRef = teleport(this.
|
|
1767
|
-
return this.
|
|
2059
|
+
this.returnRef = teleport(this.el, this.returnRef);
|
|
2060
|
+
return this.el;
|
|
1768
2061
|
} else {
|
|
1769
|
-
console.error('No return reference found:', this.
|
|
2062
|
+
console.error('No return reference found:', this.el);
|
|
1770
2063
|
return false;
|
|
1771
2064
|
}
|
|
1772
2065
|
},
|
|
@@ -1776,12 +2069,12 @@ var register$1 = function register(target, dialog) {
|
|
|
1776
2069
|
}; // Setup the modal object.
|
|
1777
2070
|
|
|
1778
2071
|
var entry = _extends({
|
|
1779
|
-
id:
|
|
2072
|
+
id: el.id,
|
|
1780
2073
|
state: 'closed',
|
|
1781
|
-
|
|
1782
|
-
target: target,
|
|
2074
|
+
el: el,
|
|
1783
2075
|
dialog: dialog,
|
|
1784
|
-
returnRef: null
|
|
2076
|
+
returnRef: null,
|
|
2077
|
+
settings: getConfig$1(el, _this2.settings.dataConfig)
|
|
1785
2078
|
}, methods); // Set aria-modal attribute to true.
|
|
1786
2079
|
|
|
1787
2080
|
|
|
@@ -1805,25 +2098,33 @@ var register$1 = function register(target, dialog) {
|
|
|
1805
2098
|
_this2.collection.push(entry); // Setup initial state.
|
|
1806
2099
|
|
|
1807
2100
|
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
entry.target.classList.add(_this2.settings.stateClosed);
|
|
1817
|
-
} // Return the registered entry.
|
|
2101
|
+
var _temp = function () {
|
|
2102
|
+
if (entry.el.classList.contains(_this2.settings.stateOpened)) {
|
|
2103
|
+
// Open entry with transitions disabled.
|
|
2104
|
+
return Promise.resolve(entry.open(false)).then(function () {});
|
|
2105
|
+
} else {
|
|
2106
|
+
// Remove transition state classes.
|
|
2107
|
+
entry.el.classList.remove(_this2.settings.stateOpening);
|
|
2108
|
+
entry.el.classList.remove(_this2.settings.stateClosing); // Add closed state class.
|
|
1818
2109
|
|
|
2110
|
+
entry.el.classList.add(_this2.settings.stateClosed);
|
|
2111
|
+
}
|
|
2112
|
+
}();
|
|
1819
2113
|
|
|
1820
|
-
return
|
|
2114
|
+
return _temp && _temp.then ? _temp.then(function () {
|
|
2115
|
+
// Return the registered entry.
|
|
2116
|
+
return entry;
|
|
2117
|
+
}) : entry;
|
|
1821
2118
|
});
|
|
1822
2119
|
} catch (e) {
|
|
1823
2120
|
return Promise.reject(e);
|
|
1824
2121
|
}
|
|
1825
2122
|
};
|
|
1826
2123
|
|
|
2124
|
+
var _handleClick = /*#__PURE__*/_classPrivateFieldLooseKey("handleClick");
|
|
2125
|
+
|
|
2126
|
+
var _handleKeydown$1 = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
|
|
2127
|
+
|
|
1827
2128
|
var Modal = /*#__PURE__*/function (_Collection) {
|
|
1828
2129
|
_inheritsLoose(Modal, _Collection);
|
|
1829
2130
|
|
|
@@ -1831,24 +2132,33 @@ var Modal = /*#__PURE__*/function (_Collection) {
|
|
|
1831
2132
|
var _this;
|
|
1832
2133
|
|
|
1833
2134
|
_this = _Collection.call(this) || this;
|
|
2135
|
+
Object.defineProperty(_assertThisInitialized(_this), _handleClick, {
|
|
2136
|
+
writable: true,
|
|
2137
|
+
value: void 0
|
|
2138
|
+
});
|
|
2139
|
+
Object.defineProperty(_assertThisInitialized(_this), _handleKeydown$1, {
|
|
2140
|
+
writable: true,
|
|
2141
|
+
value: void 0
|
|
2142
|
+
});
|
|
1834
2143
|
_this.defaults = defaults$1;
|
|
1835
2144
|
_this.settings = _extends({}, _this.defaults, options);
|
|
1836
|
-
_this.
|
|
2145
|
+
_this.trigger = null;
|
|
1837
2146
|
_this.focusTrap = new FocusTrap(); // Setup a proxy for stack array.
|
|
1838
2147
|
|
|
1839
2148
|
_this.stack = new Proxy([], {
|
|
1840
2149
|
set: function set(target, property, value) {
|
|
1841
|
-
target[property] = value; // Update global state
|
|
2150
|
+
target[property] = value; // Update global state if stack length changed.
|
|
1842
2151
|
|
|
1843
2152
|
if (property === 'length') {
|
|
1844
|
-
updateGlobalState
|
|
2153
|
+
updateGlobalState(_this.active, _this.settings);
|
|
2154
|
+
updateStackIndex(_this.stack);
|
|
1845
2155
|
}
|
|
1846
2156
|
|
|
1847
2157
|
return true;
|
|
1848
2158
|
}
|
|
1849
2159
|
});
|
|
1850
|
-
_this
|
|
1851
|
-
_this
|
|
2160
|
+
_classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleClick)[_handleClick] = handleClick$1.bind(_assertThisInitialized(_this));
|
|
2161
|
+
_classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleKeydown$1)[_handleKeydown$1] = handleKeydown$1.bind(_assertThisInitialized(_this));
|
|
1852
2162
|
if (_this.settings.autoInit) _this.init();
|
|
1853
2163
|
return _this;
|
|
1854
2164
|
}
|
|
@@ -1865,10 +2175,13 @@ var Modal = /*#__PURE__*/function (_Collection) {
|
|
|
1865
2175
|
var modals = document.querySelectorAll(_this3.settings.selectorModal); // Register the collections array with modal instances.
|
|
1866
2176
|
|
|
1867
2177
|
return Promise.resolve(_this3.registerCollection(modals)).then(function () {
|
|
2178
|
+
// If eventListeners are enabled, init event listeners.
|
|
1868
2179
|
if (_this3.settings.eventListeners) {
|
|
1869
2180
|
_this3.initEventListeners();
|
|
1870
2181
|
}
|
|
1871
|
-
|
|
2182
|
+
|
|
2183
|
+
return _this3;
|
|
2184
|
+
});
|
|
1872
2185
|
} catch (e) {
|
|
1873
2186
|
return Promise.reject(e);
|
|
1874
2187
|
}
|
|
@@ -1878,35 +2191,38 @@ var Modal = /*#__PURE__*/function (_Collection) {
|
|
|
1878
2191
|
try {
|
|
1879
2192
|
var _this5 = this;
|
|
1880
2193
|
|
|
1881
|
-
// Clear
|
|
1882
|
-
_this5.
|
|
2194
|
+
// Clear stored trigger.
|
|
2195
|
+
_this5.trigger = null; // Remove all entries from the collection.
|
|
1883
2196
|
|
|
1884
2197
|
return Promise.resolve(_this5.deregisterCollection()).then(function () {
|
|
2198
|
+
// If eventListeners are enabled, destroy event listeners.
|
|
1885
2199
|
if (_this5.settings.eventListeners) {
|
|
1886
2200
|
_this5.destroyEventListeners();
|
|
1887
2201
|
}
|
|
1888
|
-
|
|
2202
|
+
|
|
2203
|
+
return _this5;
|
|
2204
|
+
});
|
|
1889
2205
|
} catch (e) {
|
|
1890
2206
|
return Promise.reject(e);
|
|
1891
2207
|
}
|
|
1892
2208
|
};
|
|
1893
2209
|
|
|
1894
2210
|
_proto.initEventListeners = function initEventListeners() {
|
|
1895
|
-
document.addEventListener('click', this
|
|
1896
|
-
document.addEventListener('touchend', this
|
|
1897
|
-
document.addEventListener('keydown', this
|
|
2211
|
+
document.addEventListener('click', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
|
|
2212
|
+
document.addEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
|
|
2213
|
+
document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$1)[_handleKeydown$1], false);
|
|
1898
2214
|
};
|
|
1899
2215
|
|
|
1900
2216
|
_proto.destroyEventListeners = function destroyEventListeners() {
|
|
1901
|
-
document.removeEventListener('click', this
|
|
1902
|
-
document.removeEventListener('touchend', this
|
|
1903
|
-
document.removeEventListener('keydown', this
|
|
2217
|
+
document.removeEventListener('click', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
|
|
2218
|
+
document.removeEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
|
|
2219
|
+
document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$1)[_handleKeydown$1], false);
|
|
1904
2220
|
};
|
|
1905
2221
|
|
|
1906
2222
|
_proto.register = function register(query) {
|
|
1907
2223
|
var els = getModalElements.call(this, query);
|
|
1908
2224
|
if (els.error) return Promise.reject(els.error);
|
|
1909
|
-
return register$1.call(this, els.
|
|
2225
|
+
return register$1.call(this, els.modal, els.dialog);
|
|
1910
2226
|
};
|
|
1911
2227
|
|
|
1912
2228
|
_proto.deregister = function deregister(query) {
|
|
@@ -1914,28 +2230,36 @@ var Modal = /*#__PURE__*/function (_Collection) {
|
|
|
1914
2230
|
return deregister$1.call(this, modal);
|
|
1915
2231
|
};
|
|
1916
2232
|
|
|
1917
|
-
_proto.open = function open(id, transition) {
|
|
1918
|
-
return open$1.call(this, id, transition);
|
|
2233
|
+
_proto.open = function open(id, transition, focus) {
|
|
2234
|
+
return open$1.call(this, id, transition, focus);
|
|
1919
2235
|
};
|
|
1920
2236
|
|
|
1921
|
-
_proto.close = function close(id, transition) {
|
|
1922
|
-
return close$1.call(this, id, transition);
|
|
2237
|
+
_proto.close = function close(id, transition, focus) {
|
|
2238
|
+
return close$1.call(this, id, transition, focus);
|
|
1923
2239
|
};
|
|
1924
2240
|
|
|
1925
|
-
_proto.replace = function replace$1(id, transition) {
|
|
1926
|
-
return replace.call(this, id, transition);
|
|
2241
|
+
_proto.replace = function replace$1(id, transition, focus) {
|
|
2242
|
+
return replace.call(this, id, transition, focus);
|
|
1927
2243
|
};
|
|
1928
2244
|
|
|
1929
|
-
_proto.closeAll = function closeAll(exclude, transition) {
|
|
2245
|
+
_proto.closeAll = function closeAll(exclude, transition, focus) {
|
|
1930
2246
|
if (exclude === void 0) {
|
|
1931
2247
|
exclude = false;
|
|
1932
2248
|
}
|
|
1933
2249
|
|
|
2250
|
+
if (focus === void 0) {
|
|
2251
|
+
focus = true;
|
|
2252
|
+
}
|
|
2253
|
+
|
|
1934
2254
|
try {
|
|
1935
2255
|
var _this7 = this;
|
|
1936
2256
|
|
|
1937
2257
|
return Promise.resolve(closeAll$1.call(_this7, exclude, transition)).then(function (result) {
|
|
1938
|
-
|
|
2258
|
+
// Update focus if the focus param is true.
|
|
2259
|
+
if (focus) {
|
|
2260
|
+
updateFocusState.call(_this7);
|
|
2261
|
+
}
|
|
2262
|
+
|
|
1939
2263
|
return result;
|
|
1940
2264
|
});
|
|
1941
2265
|
} catch (e) {
|
|
@@ -1993,6 +2317,7 @@ function getConfig(el, settings) {
|
|
|
1993
2317
|
|
|
1994
2318
|
return config;
|
|
1995
2319
|
}
|
|
2320
|
+
|
|
1996
2321
|
function getPadding(value) {
|
|
1997
2322
|
var padding; // Split the value by spaces if it's a string.
|
|
1998
2323
|
|
|
@@ -2042,6 +2367,7 @@ function getPadding(value) {
|
|
|
2042
2367
|
|
|
2043
2368
|
return padding;
|
|
2044
2369
|
}
|
|
2370
|
+
|
|
2045
2371
|
function getModifiers(options) {
|
|
2046
2372
|
return [{
|
|
2047
2373
|
name: 'offset',
|
|
@@ -2066,6 +2392,7 @@ function getModifiers(options) {
|
|
|
2066
2392
|
}
|
|
2067
2393
|
}];
|
|
2068
2394
|
}
|
|
2395
|
+
|
|
2069
2396
|
function getPopover(query) {
|
|
2070
2397
|
// Get the entry from collection.
|
|
2071
2398
|
var entry = typeof query === 'string' ? this.get(query) : this.get(query.id); // Return entry if it was resolved, otherwise throw error.
|
|
@@ -2076,13 +2403,14 @@ function getPopover(query) {
|
|
|
2076
2403
|
throw new Error("Popover not found in collection with id of \"" + query + "\".");
|
|
2077
2404
|
}
|
|
2078
2405
|
}
|
|
2406
|
+
|
|
2079
2407
|
function getPopoverID(obj) {
|
|
2080
2408
|
// If it's a string, return the string.
|
|
2081
2409
|
if (typeof obj === 'string') {
|
|
2082
2410
|
return obj;
|
|
2083
2411
|
} // If it's an HTML element.
|
|
2084
2412
|
else if (typeof obj.hasAttribute === 'function') {
|
|
2085
|
-
// If it's a popover
|
|
2413
|
+
// If it's a popover element, return the id.
|
|
2086
2414
|
if (obj.closest(this.settings.selectorPopover)) {
|
|
2087
2415
|
obj = obj.closest(this.settings.selectorPopover);
|
|
2088
2416
|
return obj.id;
|
|
@@ -2100,14 +2428,15 @@ function getPopoverID(obj) {
|
|
|
2100
2428
|
} // Return false if no id was found.
|
|
2101
2429
|
else return false;
|
|
2102
2430
|
}
|
|
2431
|
+
|
|
2103
2432
|
function getPopoverElements(query) {
|
|
2104
2433
|
var id = getPopoverID.call(this, query);
|
|
2105
2434
|
|
|
2106
2435
|
if (id) {
|
|
2436
|
+
var popover = document.querySelector("#" + id);
|
|
2107
2437
|
var trigger = document.querySelector("[aria-controls=\"" + id + "\"]") || document.querySelector("[aria-describedby=\"" + id + "\"]");
|
|
2108
|
-
var target = document.querySelector("#" + id);
|
|
2109
2438
|
|
|
2110
|
-
if (!trigger && !
|
|
2439
|
+
if (!trigger && !popover) {
|
|
2111
2440
|
return {
|
|
2112
2441
|
error: new Error("No popover elements found using the ID: \"" + id + "\".")
|
|
2113
2442
|
};
|
|
@@ -2115,14 +2444,14 @@ function getPopoverElements(query) {
|
|
|
2115
2444
|
return {
|
|
2116
2445
|
error: new Error('No popover trigger associated with the provided popover.')
|
|
2117
2446
|
};
|
|
2118
|
-
} else if (!
|
|
2447
|
+
} else if (!popover) {
|
|
2119
2448
|
return {
|
|
2120
2449
|
error: new Error('No popover associated with the provided popover trigger.')
|
|
2121
2450
|
};
|
|
2122
2451
|
} else {
|
|
2123
2452
|
return {
|
|
2124
|
-
|
|
2125
|
-
|
|
2453
|
+
popover: popover,
|
|
2454
|
+
trigger: trigger
|
|
2126
2455
|
};
|
|
2127
2456
|
}
|
|
2128
2457
|
} else {
|
|
@@ -2165,7 +2494,7 @@ var close = function close(query) {
|
|
|
2165
2494
|
// If a modal exists and its state is opened.
|
|
2166
2495
|
if (popover && popover.state === 'opened') {
|
|
2167
2496
|
// Update state class.
|
|
2168
|
-
popover.
|
|
2497
|
+
popover.el.classList.remove(_this2.settings.stateActive); // Update accessibility attribute(s).
|
|
2169
2498
|
|
|
2170
2499
|
if (popover.trigger.hasAttribute('aria-controls')) {
|
|
2171
2500
|
popover.trigger.setAttribute('aria-expanded', 'false');
|
|
@@ -2179,10 +2508,10 @@ var close = function close(query) {
|
|
|
2179
2508
|
}]
|
|
2180
2509
|
}); // Update popover state.
|
|
2181
2510
|
|
|
2182
|
-
popover.state = 'closed'; // Clear
|
|
2511
|
+
popover.state = 'closed'; // Clear root trigger if popover trigger matches.
|
|
2183
2512
|
|
|
2184
|
-
if (popover.trigger === _this2.
|
|
2185
|
-
_this2.
|
|
2513
|
+
if (popover.trigger === _this2.trigger) {
|
|
2514
|
+
_this2.trigger = null;
|
|
2186
2515
|
}
|
|
2187
2516
|
} // Return the popover.
|
|
2188
2517
|
|
|
@@ -2203,10 +2532,10 @@ function closeCheck(popover) {
|
|
|
2203
2532
|
if (popover.state != 'opened') return; // Needed to correctly check which element is currently being focused.
|
|
2204
2533
|
|
|
2205
2534
|
setTimeout(function () {
|
|
2206
|
-
// Check if trigger or
|
|
2207
|
-
var isHovered = popover.
|
|
2535
|
+
// Check if trigger or element are being hovered.
|
|
2536
|
+
var isHovered = popover.el.closest(':hover') === popover.el || popover.trigger.closest(':hover') === popover.trigger; // Check if trigger or element are being focused.
|
|
2208
2537
|
|
|
2209
|
-
var isFocused = document.activeElement.closest("#" + popover.id + ", [aria-controls=\"" + popover.id + "\"]"); // Close if the trigger and
|
|
2538
|
+
var isFocused = document.activeElement.closest("#" + popover.id + ", [aria-controls=\"" + popover.id + "\"]"); // Close if the trigger and element are not currently hovered or focused.
|
|
2210
2539
|
|
|
2211
2540
|
if (!isHovered && !isFocused) {
|
|
2212
2541
|
popover.close();
|
|
@@ -2217,22 +2546,22 @@ function closeCheck(popover) {
|
|
|
2217
2546
|
}, 1);
|
|
2218
2547
|
}
|
|
2219
2548
|
|
|
2220
|
-
function
|
|
2549
|
+
function handleClick(popover) {
|
|
2221
2550
|
if (popover.state === 'opened') {
|
|
2222
2551
|
popover.close();
|
|
2223
2552
|
} else {
|
|
2224
|
-
this.
|
|
2553
|
+
this.trigger = popover.trigger;
|
|
2225
2554
|
popover.open();
|
|
2226
|
-
|
|
2555
|
+
handleDocumentClick.call(this, popover);
|
|
2227
2556
|
}
|
|
2228
2557
|
}
|
|
2229
|
-
function
|
|
2558
|
+
function handleKeydown(event) {
|
|
2230
2559
|
var _this = this;
|
|
2231
2560
|
|
|
2232
2561
|
switch (event.key) {
|
|
2233
2562
|
case 'Escape':
|
|
2234
|
-
if (this.
|
|
2235
|
-
this.
|
|
2563
|
+
if (this.trigger) {
|
|
2564
|
+
this.trigger.focus();
|
|
2236
2565
|
}
|
|
2237
2566
|
|
|
2238
2567
|
closeAll.call(this);
|
|
@@ -2248,7 +2577,7 @@ function handlerKeydown(event) {
|
|
|
2248
2577
|
return;
|
|
2249
2578
|
}
|
|
2250
2579
|
}
|
|
2251
|
-
function
|
|
2580
|
+
function handleDocumentClick(popover) {
|
|
2252
2581
|
var root = this;
|
|
2253
2582
|
document.addEventListener('click', function _f(event) {
|
|
2254
2583
|
// Check if a popover was clicked.
|
|
@@ -2256,14 +2585,14 @@ function documentClick(popover) {
|
|
|
2256
2585
|
|
|
2257
2586
|
if (!result) {
|
|
2258
2587
|
// If it doesn't match and popover is open, close it and remove event listener.
|
|
2259
|
-
if (popover.
|
|
2588
|
+
if (popover.el && popover.el.classList.contains(root.settings.stateActive)) {
|
|
2260
2589
|
popover.close();
|
|
2261
2590
|
}
|
|
2262
2591
|
|
|
2263
2592
|
this.removeEventListener('click', _f);
|
|
2264
2593
|
} else {
|
|
2265
2594
|
// If it does match and popover isn't currently active, remove event listener.
|
|
2266
|
-
if (popover.
|
|
2595
|
+
if (popover.el && !popover.el.classList.contains(root.settings.stateActive)) {
|
|
2267
2596
|
this.removeEventListener('click', _f);
|
|
2268
2597
|
}
|
|
2269
2598
|
}
|
|
@@ -4121,14 +4450,14 @@ var open = function open(query) {
|
|
|
4121
4450
|
// Get the popover from collection.
|
|
4122
4451
|
var popover = getPopover.call(_this2, query); // Update state class.
|
|
4123
4452
|
|
|
4124
|
-
popover.
|
|
4453
|
+
popover.el.classList.add(_this2.settings.stateActive); // Update accessibility attribute(s).
|
|
4125
4454
|
|
|
4126
4455
|
if (popover.trigger.hasAttribute('aria-controls')) {
|
|
4127
4456
|
popover.trigger.setAttribute('aria-expanded', 'true');
|
|
4128
4457
|
} // Update popover config.
|
|
4129
4458
|
|
|
4130
4459
|
|
|
4131
|
-
popover.config = getConfig(popover.
|
|
4460
|
+
popover.config = getConfig(popover.el, _this2.settings); // Enable popper event listeners and set placement/modifiers.
|
|
4132
4461
|
|
|
4133
4462
|
popover.popper.setOptions({
|
|
4134
4463
|
placement: popover.config['placement'],
|
|
@@ -4148,12 +4477,12 @@ var open = function open(query) {
|
|
|
4148
4477
|
}
|
|
4149
4478
|
};
|
|
4150
4479
|
|
|
4151
|
-
var register = function register(
|
|
4480
|
+
var register = function register(el, trigger) {
|
|
4152
4481
|
try {
|
|
4153
4482
|
var _this2 = this;
|
|
4154
4483
|
|
|
4155
4484
|
// Deregister entry incase it has already been registered.
|
|
4156
|
-
deregister.call(_this2,
|
|
4485
|
+
deregister.call(_this2, el); // Save root this for use inside methods API.
|
|
4157
4486
|
|
|
4158
4487
|
|
|
4159
4488
|
var root = _this2; // Setup methods API.
|
|
@@ -4171,12 +4500,12 @@ var register = function register(trigger, target) {
|
|
|
4171
4500
|
}; // Setup the popover object.
|
|
4172
4501
|
|
|
4173
4502
|
var entry = _extends({
|
|
4174
|
-
id:
|
|
4503
|
+
id: el.id,
|
|
4175
4504
|
state: 'closed',
|
|
4505
|
+
el: el,
|
|
4176
4506
|
trigger: trigger,
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
config: getConfig(target, _this2.settings)
|
|
4507
|
+
popper: createPopper(trigger, el),
|
|
4508
|
+
config: getConfig(el, _this2.settings)
|
|
4180
4509
|
}, methods); // Set aria-expanded to false if trigger has aria-controls attribute.
|
|
4181
4510
|
|
|
4182
4511
|
|
|
@@ -4191,9 +4520,9 @@ var register = function register(trigger, target) {
|
|
|
4191
4520
|
|
|
4192
4521
|
|
|
4193
4522
|
var _temp2 = function () {
|
|
4194
|
-
if (entry.
|
|
4523
|
+
if (entry.el.classList.contains(_this2.settings.stateActive)) {
|
|
4195
4524
|
return Promise.resolve(entry.open()).then(function () {
|
|
4196
|
-
|
|
4525
|
+
handleDocumentClick.call(_this2, entry);
|
|
4197
4526
|
});
|
|
4198
4527
|
}
|
|
4199
4528
|
}();
|
|
@@ -4219,7 +4548,7 @@ function registerEventListeners(entry) {
|
|
|
4219
4548
|
type: ['mouseenter', 'focus'],
|
|
4220
4549
|
listener: open.bind(this, entry)
|
|
4221
4550
|
}, {
|
|
4222
|
-
el: ['
|
|
4551
|
+
el: ['el', 'trigger'],
|
|
4223
4552
|
type: ['mouseleave', 'focusout'],
|
|
4224
4553
|
listener: closeCheck.bind(this, entry)
|
|
4225
4554
|
}]; // Loop through listeners and apply to the appropriate elements.
|
|
@@ -4237,7 +4566,7 @@ function registerEventListeners(entry) {
|
|
|
4237
4566
|
entry.__eventListeners = [{
|
|
4238
4567
|
el: ['trigger'],
|
|
4239
4568
|
type: ['click'],
|
|
4240
|
-
listener:
|
|
4569
|
+
listener: handleClick.bind(this, entry)
|
|
4241
4570
|
}]; // Loop through listeners and apply to the appropriate elements.
|
|
4242
4571
|
|
|
4243
4572
|
entry.__eventListeners.forEach(function (evObj) {
|
|
@@ -4254,6 +4583,8 @@ function registerEventListeners(entry) {
|
|
|
4254
4583
|
return entry;
|
|
4255
4584
|
}
|
|
4256
4585
|
|
|
4586
|
+
var _handleKeydown = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
|
|
4587
|
+
|
|
4257
4588
|
var Popover = /*#__PURE__*/function (_Collection) {
|
|
4258
4589
|
_inheritsLoose(Popover, _Collection);
|
|
4259
4590
|
|
|
@@ -4261,10 +4592,14 @@ var Popover = /*#__PURE__*/function (_Collection) {
|
|
|
4261
4592
|
var _this;
|
|
4262
4593
|
|
|
4263
4594
|
_this = _Collection.call(this) || this;
|
|
4595
|
+
Object.defineProperty(_assertThisInitialized(_this), _handleKeydown, {
|
|
4596
|
+
writable: true,
|
|
4597
|
+
value: void 0
|
|
4598
|
+
});
|
|
4264
4599
|
_this.defaults = defaults;
|
|
4265
4600
|
_this.settings = _extends({}, _this.defaults, options);
|
|
4266
|
-
_this.
|
|
4267
|
-
_this
|
|
4601
|
+
_this.trigger = null;
|
|
4602
|
+
_classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleKeydown)[_handleKeydown] = handleKeydown.bind(_assertThisInitialized(_this));
|
|
4268
4603
|
if (_this.settings.autoInit) _this.init();
|
|
4269
4604
|
return _this;
|
|
4270
4605
|
}
|
|
@@ -4281,12 +4616,15 @@ var Popover = /*#__PURE__*/function (_Collection) {
|
|
|
4281
4616
|
var popovers = document.querySelectorAll(_this3.settings.selectorPopover); // Register the collections array with popover instances.
|
|
4282
4617
|
|
|
4283
4618
|
return Promise.resolve(_this3.registerCollection(popovers)).then(function () {
|
|
4619
|
+
// If eventListeners are enabled, init event listeners.
|
|
4284
4620
|
if (_this3.settings.eventListeners) {
|
|
4285
4621
|
// Pass false to initEventListeners() since registerCollection()
|
|
4286
4622
|
// already adds event listeners to popovers.
|
|
4287
4623
|
_this3.initEventListeners(false);
|
|
4288
4624
|
}
|
|
4289
|
-
|
|
4625
|
+
|
|
4626
|
+
return _this3;
|
|
4627
|
+
});
|
|
4290
4628
|
} catch (e) {
|
|
4291
4629
|
return Promise.reject(e);
|
|
4292
4630
|
}
|
|
@@ -4296,16 +4634,19 @@ var Popover = /*#__PURE__*/function (_Collection) {
|
|
|
4296
4634
|
try {
|
|
4297
4635
|
var _this5 = this;
|
|
4298
4636
|
|
|
4299
|
-
// Clear
|
|
4300
|
-
_this5.
|
|
4637
|
+
// Clear stored trigger.
|
|
4638
|
+
_this5.trigger = null; // Remove all entries from the collection.
|
|
4301
4639
|
|
|
4302
4640
|
return Promise.resolve(_this5.deregisterCollection()).then(function () {
|
|
4641
|
+
// If eventListeners are enabled, destroy event listeners.
|
|
4303
4642
|
if (_this5.settings.eventListeners) {
|
|
4304
4643
|
// Pass false to destroyEventListeners() since deregisterCollection()
|
|
4305
4644
|
// already removes event listeners from popovers.
|
|
4306
4645
|
_this5.destroyEventListeners(false);
|
|
4307
4646
|
}
|
|
4308
|
-
|
|
4647
|
+
|
|
4648
|
+
return _this5;
|
|
4649
|
+
});
|
|
4309
4650
|
} catch (e) {
|
|
4310
4651
|
return Promise.reject(e);
|
|
4311
4652
|
}
|
|
@@ -4326,7 +4667,7 @@ var Popover = /*#__PURE__*/function (_Collection) {
|
|
|
4326
4667
|
} // Add keydown global event listener.
|
|
4327
4668
|
|
|
4328
4669
|
|
|
4329
|
-
document.addEventListener('keydown', this
|
|
4670
|
+
document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown)[_handleKeydown], false);
|
|
4330
4671
|
};
|
|
4331
4672
|
|
|
4332
4673
|
_proto.destroyEventListeners = function destroyEventListeners(processCollection) {
|
|
@@ -4342,13 +4683,13 @@ var Popover = /*#__PURE__*/function (_Collection) {
|
|
|
4342
4683
|
} // Remove keydown global event listener.
|
|
4343
4684
|
|
|
4344
4685
|
|
|
4345
|
-
document.removeEventListener('keydown', this
|
|
4686
|
+
document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown)[_handleKeydown], false);
|
|
4346
4687
|
};
|
|
4347
4688
|
|
|
4348
4689
|
_proto.register = function register$1(query) {
|
|
4349
4690
|
var els = getPopoverElements.call(this, query);
|
|
4350
4691
|
if (els.error) return Promise.reject(els.error);
|
|
4351
|
-
return register.call(this, els.
|
|
4692
|
+
return register.call(this, els.popover, els.trigger);
|
|
4352
4693
|
};
|
|
4353
4694
|
|
|
4354
4695
|
_proto.deregister = function deregister$1(query) {
|