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