vrembem 2.0.0 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dev/scripts.esm.js +1120 -777
- package/dev/scripts.esm.js.map +1 -1
- package/dev/scripts.js +1120 -777
- package/dev/scripts.js.map +1 -1
- package/dev/scripts.modern.js +931 -687
- package/dev/scripts.modern.js.map +1 -1
- package/dev/scripts.umd.js +1120 -777
- package/dev/scripts.umd.js.map +1 -1
- package/dev/styles.css +29 -38
- package/dev/styles.css.map +1 -1
- package/dist/scripts.esm.js +1 -1
- package/dist/scripts.esm.js.map +1 -1
- package/dist/scripts.js +1 -1
- package/dist/scripts.js.map +1 -1
- package/dist/scripts.modern.js +1 -1
- package/dist/scripts.modern.js.map +1 -1
- package/dist/scripts.umd.js +1 -1
- package/dist/scripts.umd.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.css.map +1 -1
- package/package.json +26 -26
package/dev/scripts.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,203 @@
|
|
|
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
|
-
var removeClass = function removeClass(el) {
|
|
495
|
-
var _arguments = arguments;
|
|
496
|
-
el = el.forEach ? el : [el];
|
|
497
|
-
el.forEach(function (el) {
|
|
498
|
-
var _el$classList;
|
|
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
|
+
}
|
|
499
604
|
|
|
500
|
-
|
|
605
|
+
function getPrefix() {
|
|
606
|
+
return getComputedStyle(document.body).getPropertyValue('--vrembem-variable-prefix').trim();
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
function localStore(key, enable) {
|
|
610
|
+
if (enable === void 0) {
|
|
611
|
+
enable = true;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function getStore() {
|
|
615
|
+
var value = localStorage.getItem(key);
|
|
616
|
+
return value ? JSON.parse(value) : {};
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
function setStore(obj) {
|
|
620
|
+
localStorage.setItem(key, JSON.stringify(obj));
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
return new Proxy(getStore(), {
|
|
624
|
+
set: function set(target, property, value) {
|
|
625
|
+
target[property] = value;
|
|
626
|
+
if (enable) setStore(target);
|
|
627
|
+
return true;
|
|
628
|
+
},
|
|
629
|
+
deleteProperty: function deleteProperty(target, property) {
|
|
630
|
+
delete target[property];
|
|
631
|
+
if (enable) setStore(target);
|
|
632
|
+
return true;
|
|
633
|
+
}
|
|
501
634
|
});
|
|
502
|
-
}
|
|
635
|
+
}
|
|
503
636
|
|
|
504
637
|
/**
|
|
505
638
|
* Teleports an element in the DOM based on a reference and teleport method.
|
|
@@ -543,21 +676,6 @@
|
|
|
543
676
|
return returnRef;
|
|
544
677
|
}
|
|
545
678
|
|
|
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
679
|
var openTransition = function openTransition(el, settings) {
|
|
562
680
|
return new Promise(function (resolve) {
|
|
563
681
|
if (settings.transition) {
|
|
@@ -595,86 +713,54 @@
|
|
|
595
713
|
});
|
|
596
714
|
};
|
|
597
715
|
|
|
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);
|
|
716
|
+
function setOverflowHidden(state, selector) {
|
|
717
|
+
if (selector) {
|
|
718
|
+
var els = document.querySelectorAll(selector);
|
|
719
|
+
els.forEach(function (el) {
|
|
720
|
+
if (state) {
|
|
721
|
+
el.style.overflow = 'hidden';
|
|
722
|
+
} else {
|
|
723
|
+
el.style.removeProperty('overflow');
|
|
724
|
+
}
|
|
725
|
+
});
|
|
625
726
|
}
|
|
626
727
|
}
|
|
627
728
|
|
|
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
|
-
}
|
|
729
|
+
function setInert(state, selector) {
|
|
730
|
+
if (selector) {
|
|
731
|
+
var els = document.querySelectorAll(selector);
|
|
732
|
+
els.forEach(function (el) {
|
|
733
|
+
if (state) {
|
|
734
|
+
el.inert = true;
|
|
735
|
+
el.setAttribute('aria-hidden', true);
|
|
736
|
+
} else {
|
|
737
|
+
el.inert = null;
|
|
738
|
+
el.removeAttribute('aria-hidden');
|
|
646
739
|
}
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
return target;
|
|
650
|
-
};
|
|
651
|
-
|
|
652
|
-
return _extends.apply(this, arguments);
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
function _inheritsLoose(subClass, superClass) {
|
|
656
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
657
|
-
subClass.prototype.constructor = subClass;
|
|
658
|
-
|
|
659
|
-
_setPrototypeOf(subClass, superClass);
|
|
740
|
+
});
|
|
741
|
+
}
|
|
660
742
|
}
|
|
661
743
|
|
|
662
|
-
function
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
return o;
|
|
666
|
-
};
|
|
744
|
+
function updateGlobalState(param, config) {
|
|
745
|
+
// Set inert state based on if a modal is active.
|
|
746
|
+
setInert(!!param, config.selectorInert); // Set overflow state based on if a modal is active.
|
|
667
747
|
|
|
668
|
-
|
|
748
|
+
setOverflowHidden(!!param, config.selectorOverflow);
|
|
669
749
|
}
|
|
670
750
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
751
|
+
var index = {
|
|
752
|
+
__proto__: null,
|
|
753
|
+
Breakpoint: Breakpoint,
|
|
754
|
+
Collection: Collection,
|
|
755
|
+
FocusTrap: FocusTrap,
|
|
756
|
+
getConfig: getConfig$1,
|
|
757
|
+
getPrefix: getPrefix,
|
|
758
|
+
localStore: localStore,
|
|
759
|
+
teleport: teleport,
|
|
760
|
+
openTransition: openTransition,
|
|
761
|
+
closeTransition: closeTransition,
|
|
762
|
+
updateGlobalState: updateGlobalState
|
|
763
|
+
};
|
|
678
764
|
|
|
679
765
|
var defaults$3 = {
|
|
680
766
|
autoInit: false,
|
|
@@ -757,16 +843,17 @@
|
|
|
757
843
|
var defaults$2 = {
|
|
758
844
|
autoInit: false,
|
|
759
845
|
// Data attributes
|
|
760
|
-
dataDrawer: 'drawer',
|
|
761
|
-
dataDialog: 'drawer-dialog',
|
|
762
|
-
dataToggle: 'drawer-toggle',
|
|
763
846
|
dataOpen: 'drawer-open',
|
|
764
847
|
dataClose: 'drawer-close',
|
|
848
|
+
dataToggle: 'drawer-toggle',
|
|
765
849
|
dataBreakpoint: 'drawer-breakpoint',
|
|
850
|
+
dataConfig: 'drawer-config',
|
|
766
851
|
// Selectors
|
|
852
|
+
selectorDrawer: '.drawer',
|
|
853
|
+
selectorDialog: '.drawer__dialog',
|
|
767
854
|
selectorFocus: '[data-focus]',
|
|
768
855
|
selectorInert: null,
|
|
769
|
-
selectorOverflow:
|
|
856
|
+
selectorOverflow: 'body',
|
|
770
857
|
// State classes
|
|
771
858
|
stateOpened: 'is-opened',
|
|
772
859
|
stateOpening: 'is-opening',
|
|
@@ -778,399 +865,624 @@
|
|
|
778
865
|
breakpoints: null,
|
|
779
866
|
customEventPrefix: 'drawer:',
|
|
780
867
|
eventListeners: true,
|
|
781
|
-
|
|
782
|
-
|
|
868
|
+
store: true,
|
|
869
|
+
storeKey: 'VB:DrawerState',
|
|
783
870
|
setTabindex: true,
|
|
784
871
|
transition: true
|
|
785
872
|
};
|
|
786
873
|
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
this.mediaQueryLists = [];
|
|
790
|
-
this.parent = parent;
|
|
791
|
-
this.prefix = this.getVariablePrefix();
|
|
792
|
-
this.__check = this.check.bind(this);
|
|
793
|
-
}
|
|
874
|
+
function handleClick$2(event) {
|
|
875
|
+
var _this = this;
|
|
794
876
|
|
|
795
|
-
|
|
877
|
+
// If an open, close or toggle button was clicked, handle the click event.
|
|
878
|
+
var trigger = event.target.closest("\n [data-" + this.settings.dataOpen + "],\n [data-" + this.settings.dataToggle + "],\n [data-" + this.settings.dataClose + "]\n ");
|
|
796
879
|
|
|
797
|
-
|
|
798
|
-
|
|
880
|
+
if (trigger) {
|
|
881
|
+
// Prevent the default behavior of the trigger.
|
|
882
|
+
event.preventDefault(); // If it's a toggle trigger...
|
|
799
883
|
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
884
|
+
if (trigger.matches("[data-" + this.settings.dataToggle + "]")) {
|
|
885
|
+
var selectors = trigger.getAttribute("data-" + this.settings.dataToggle).trim().split(' ');
|
|
886
|
+
selectors.forEach(function (selector) {
|
|
887
|
+
// Get the entry from collection using the attribute value.
|
|
888
|
+
var entry = _this.get(selector); // Store the trigger on the entry.
|
|
805
889
|
|
|
806
|
-
var bp = _this.getBreakpoint(key);
|
|
807
890
|
|
|
808
|
-
|
|
891
|
+
entry.trigger = trigger; // Toggle the drawer
|
|
809
892
|
|
|
810
|
-
|
|
893
|
+
entry.toggle();
|
|
894
|
+
});
|
|
895
|
+
} // If it's a open trigger...
|
|
811
896
|
|
|
812
897
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
} else {
|
|
816
|
-
mql.addListener(_this.__check);
|
|
817
|
-
} // Push to mediaQueryLists array along with drawer ID
|
|
898
|
+
if (trigger.matches("[data-" + this.settings.dataOpen + "]")) {
|
|
899
|
+
var _selectors = trigger.getAttribute("data-" + this.settings.dataOpen).trim().split(' ');
|
|
818
900
|
|
|
901
|
+
_selectors.forEach(function (selector) {
|
|
902
|
+
// Get the entry from collection using the attribute value.
|
|
903
|
+
var entry = _this.get(selector); // Store the trigger on the entry.
|
|
819
904
|
|
|
820
|
-
_this.mediaQueryLists.push({
|
|
821
|
-
'mql': mql,
|
|
822
|
-
'drawer': id
|
|
823
|
-
});
|
|
824
|
-
});
|
|
825
|
-
};
|
|
826
905
|
|
|
827
|
-
|
|
828
|
-
var _this2 = this;
|
|
906
|
+
entry.trigger = trigger; // Open the drawer.
|
|
829
907
|
|
|
830
|
-
|
|
831
|
-
this.mediaQueryLists.forEach(function (item) {
|
|
832
|
-
item.mql.removeListener(_this2.__check);
|
|
908
|
+
entry.open();
|
|
833
909
|
});
|
|
834
|
-
}
|
|
910
|
+
} // If it's a close trigger...
|
|
835
911
|
|
|
836
|
-
this.mediaQueryLists = null;
|
|
837
|
-
};
|
|
838
912
|
|
|
839
|
-
|
|
840
|
-
|
|
913
|
+
if (trigger.matches("[data-" + this.settings.dataClose + "]")) {
|
|
914
|
+
var _selectors2 = trigger.getAttribute("data-" + this.settings.dataClose).trim().split(' ');
|
|
841
915
|
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
916
|
+
_selectors2.forEach(function (selector) {
|
|
917
|
+
if (selector) {
|
|
918
|
+
// Get the entry from collection using the attribute value.
|
|
919
|
+
var entry = _this.get(selector); // Store the trigger on the entry.
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
entry.trigger = trigger; // Close the drawer.
|
|
845
923
|
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
if (drawer) _this3.match(item.mql, drawer);
|
|
924
|
+
entry.close();
|
|
925
|
+
} else {
|
|
926
|
+
// If no value is set on close trigger, get the parent drawer.
|
|
927
|
+
var parent = event.target.closest(_this.settings.selectorDrawer); // If a parent drawer was found, close it.
|
|
928
|
+
|
|
929
|
+
if (parent) _this.close(parent);
|
|
930
|
+
}
|
|
854
931
|
});
|
|
855
|
-
document.dispatchEvent(new CustomEvent(this.parent.settings.customEventPrefix + 'breakpoint', {
|
|
856
|
-
bubbles: true
|
|
857
|
-
}));
|
|
858
932
|
}
|
|
859
|
-
};
|
|
860
933
|
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
934
|
+
return;
|
|
935
|
+
} // If the modal drawer screen was clicked...
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
if (event.target.matches(this.settings.selectorDrawer)) {
|
|
939
|
+
// Close the modal drawer.
|
|
940
|
+
this.close(event.target.id);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
function handleKeydown$2(event) {
|
|
944
|
+
if (event.key === 'Escape') {
|
|
945
|
+
var modal = this.activeModal;
|
|
946
|
+
if (modal) this.close(modal);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
var deregister$2 = function deregister(obj, close) {
|
|
951
|
+
if (close === void 0) {
|
|
952
|
+
close = true;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
try {
|
|
956
|
+
var _temp5 = function _temp5() {
|
|
957
|
+
// Return the modified collection.
|
|
958
|
+
return _this2.collection;
|
|
959
|
+
};
|
|
960
|
+
|
|
961
|
+
var _this2 = this;
|
|
962
|
+
|
|
963
|
+
// Return collection if nothing was passed.
|
|
964
|
+
if (!obj) return Promise.resolve(_this2.collection); // Check if entry has been registered in the collection.
|
|
965
|
+
|
|
966
|
+
var index = _this2.collection.findIndex(function (entry) {
|
|
967
|
+
return entry.id === obj.id;
|
|
968
|
+
});
|
|
969
|
+
|
|
970
|
+
var _temp6 = function () {
|
|
971
|
+
if (index >= 0) {
|
|
972
|
+
var _temp7 = function _temp7() {
|
|
973
|
+
// Remove entry from local store.
|
|
974
|
+
delete _this2.store[_entry.id]; // Unmount the MatchMedia functionality.
|
|
975
|
+
|
|
976
|
+
_entry.unmountBreakpoint(); // Delete properties from collection entry.
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
Object.getOwnPropertyNames(_entry).forEach(function (prop) {
|
|
980
|
+
delete _entry[prop];
|
|
981
|
+
}); // Remove entry from collection.
|
|
982
|
+
|
|
983
|
+
_this2.collection.splice(index, 1);
|
|
984
|
+
};
|
|
985
|
+
|
|
986
|
+
// Get the collection entry.
|
|
987
|
+
var _entry = _this2.collection[index]; // If entry is in the opened state.
|
|
988
|
+
|
|
989
|
+
var _temp8 = function () {
|
|
990
|
+
if (close && _entry.state === 'opened') {
|
|
991
|
+
// Close the drawer.
|
|
992
|
+
return Promise.resolve(_entry.close(false)).then(function () {});
|
|
993
|
+
}
|
|
994
|
+
}();
|
|
995
|
+
|
|
996
|
+
return _temp8 && _temp8.then ? _temp8.then(_temp7) : _temp7(_temp8);
|
|
997
|
+
}
|
|
998
|
+
}();
|
|
999
|
+
|
|
1000
|
+
return Promise.resolve(_temp6 && _temp6.then ? _temp6.then(_temp5) : _temp5(_temp6));
|
|
1001
|
+
} catch (e) {
|
|
1002
|
+
return Promise.reject(e);
|
|
1003
|
+
}
|
|
1004
|
+
};
|
|
1005
|
+
|
|
1006
|
+
function L() {
|
|
1007
|
+
return getComputedStyle(document.body).getPropertyValue("--vrembem-variable-prefix").trim();
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
function getBreakpoint(drawer) {
|
|
1011
|
+
var prefix = L();
|
|
1012
|
+
var bp = drawer.getAttribute("data-" + this.settings.dataBreakpoint);
|
|
1013
|
+
|
|
1014
|
+
if (this.settings.breakpoints && this.settings.breakpoints[bp]) {
|
|
1015
|
+
return this.settings.breakpoints[bp];
|
|
1016
|
+
} else if (getComputedStyle(document.body).getPropertyValue("--" + prefix + "breakpoint-" + bp).trim()) {
|
|
1017
|
+
return getComputedStyle(document.body).getPropertyValue("--" + prefix + "breakpoint-" + bp).trim();
|
|
1018
|
+
} else {
|
|
1019
|
+
return bp;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
function getDrawer(query) {
|
|
1024
|
+
// Get the entry from collection.
|
|
1025
|
+
var entry = typeof query === 'string' ? this.get(query) : this.get(query.id); // Return entry if it was resolved, otherwise throw error.
|
|
1026
|
+
|
|
1027
|
+
if (entry) {
|
|
1028
|
+
return entry;
|
|
1029
|
+
} else {
|
|
1030
|
+
throw new Error("Drawer not found in collection with id of \"" + (query.id || query) + "\".");
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
function getDrawerID(obj) {
|
|
1035
|
+
// If it's a string, return the string.
|
|
1036
|
+
if (typeof obj === 'string') {
|
|
1037
|
+
return obj;
|
|
1038
|
+
} // If it's an HTML element.
|
|
1039
|
+
else if (typeof obj.hasAttribute === 'function') {
|
|
1040
|
+
// If it's a drawer open trigger, return data value.
|
|
1041
|
+
if (obj.hasAttribute("data-" + this.settings.dataOpen)) {
|
|
1042
|
+
return obj.getAttribute("data-" + this.settings.dataOpen);
|
|
1043
|
+
} // If it's a drawer close trigger, return data value or false.
|
|
1044
|
+
else if (obj.hasAttribute("data-" + this.settings.dataClose)) {
|
|
1045
|
+
return obj.getAttribute("data-" + this.settings.dataClose) || false;
|
|
1046
|
+
} // If it's a drawer toggle trigger, return data value.
|
|
1047
|
+
else if (obj.hasAttribute("data-" + this.settings.dataToggle)) {
|
|
1048
|
+
return obj.getAttribute("data-" + this.settings.dataToggle);
|
|
1049
|
+
} // If it's a drawer element, return the id.
|
|
1050
|
+
else if (obj.closest(this.settings.selectorDrawer)) {
|
|
1051
|
+
obj = obj.closest(this.settings.selectorDrawer);
|
|
1052
|
+
return obj.id || false;
|
|
1053
|
+
} // Return false if no id was found.
|
|
1054
|
+
else return false;
|
|
1055
|
+
} // If it has an id property, return its value.
|
|
1056
|
+
else if (obj.id) {
|
|
1057
|
+
return obj.id;
|
|
1058
|
+
} // Return false if no id was found.
|
|
1059
|
+
else return false;
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
function getDrawerElements(query) {
|
|
1063
|
+
var id = getDrawerID.call(this, query);
|
|
1064
|
+
|
|
1065
|
+
if (id) {
|
|
1066
|
+
var drawer = document.querySelector("#" + id);
|
|
1067
|
+
var dialog = drawer ? drawer.querySelector(this.settings.selectorDialog) : null;
|
|
1068
|
+
|
|
1069
|
+
if (!drawer && !dialog) {
|
|
1070
|
+
return {
|
|
1071
|
+
error: new Error("No drawer elements found using the ID: \"" + id + "\".")
|
|
1072
|
+
};
|
|
1073
|
+
} else if (!dialog) {
|
|
1074
|
+
return {
|
|
1075
|
+
error: new Error('Drawer is missing dialog element.')
|
|
1076
|
+
};
|
|
864
1077
|
} else {
|
|
865
|
-
|
|
1078
|
+
return {
|
|
1079
|
+
drawer: drawer,
|
|
1080
|
+
dialog: dialog
|
|
1081
|
+
};
|
|
866
1082
|
}
|
|
867
|
-
}
|
|
1083
|
+
} else {
|
|
1084
|
+
return {
|
|
1085
|
+
error: new Error('Could not resolve the drawer ID.')
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
868
1089
|
|
|
869
|
-
|
|
870
|
-
|
|
1090
|
+
var initialState = function initialState(entry) {
|
|
1091
|
+
try {
|
|
1092
|
+
var _this2 = this;
|
|
871
1093
|
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
1094
|
+
var _temp3 = function () {
|
|
1095
|
+
if (_this2.store[entry.id]) {
|
|
1096
|
+
var _temp4 = function () {
|
|
1097
|
+
if (_this2.store[entry.id] === 'opened') {
|
|
1098
|
+
return Promise.resolve(entry.open(false, false)).then(function () {});
|
|
1099
|
+
} else {
|
|
1100
|
+
return Promise.resolve(entry.close(false, false)).then(function () {});
|
|
1101
|
+
}
|
|
1102
|
+
}();
|
|
877
1103
|
|
|
878
|
-
|
|
879
|
-
|
|
1104
|
+
if (_temp4 && _temp4.then) return _temp4.then(function () {});
|
|
1105
|
+
} else if (entry.el.classList.contains(_this2.settings.stateOpened)) {
|
|
1106
|
+
// Update drawer state.
|
|
1107
|
+
entry.state = 'opened';
|
|
1108
|
+
} else {
|
|
1109
|
+
// Remove transition state classes.
|
|
1110
|
+
entry.el.classList.remove(_this2.settings.stateOpening);
|
|
1111
|
+
entry.el.classList.remove(_this2.settings.stateClosing); // Add closed state class.
|
|
880
1112
|
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
prefix += 'breakpoint-';
|
|
885
|
-
return prefix;
|
|
886
|
-
};
|
|
1113
|
+
entry.el.classList.add(_this2.settings.stateClosed);
|
|
1114
|
+
}
|
|
1115
|
+
}();
|
|
887
1116
|
|
|
888
|
-
|
|
889
|
-
|
|
1117
|
+
// Setup initial state using the following priority:
|
|
1118
|
+
// 1. If a store state is available, restore from local store.
|
|
1119
|
+
// 2. If opened state class is set, set state to opened.
|
|
1120
|
+
// 3. Else, initialize default state.
|
|
1121
|
+
return Promise.resolve(_temp3 && _temp3.then ? _temp3.then(function () {}) : void 0);
|
|
1122
|
+
} catch (e) {
|
|
1123
|
+
return Promise.reject(e);
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
890
1126
|
|
|
891
|
-
function
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
1127
|
+
function updateFocusState$1(entry) {
|
|
1128
|
+
// Check if there's an active modal
|
|
1129
|
+
if (entry.state === 'opened') {
|
|
1130
|
+
// Mount the focus trap on the opened drawer.
|
|
1131
|
+
if (entry.mode === 'modal') {
|
|
1132
|
+
this.focusTrap.mount(entry.dialog, this.settings.selectorFocus);
|
|
1133
|
+
} else {
|
|
1134
|
+
this.focusTrap.focus(entry.dialog, this.settings.selectorFocus);
|
|
1135
|
+
}
|
|
1136
|
+
} else {
|
|
1137
|
+
// Set focus to root trigger and unmount the focus trap.
|
|
1138
|
+
if (entry.trigger) {
|
|
1139
|
+
entry.trigger.focus();
|
|
1140
|
+
entry.trigger = null;
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
this.focusTrap.unmount();
|
|
1144
|
+
}
|
|
897
1145
|
}
|
|
898
1146
|
|
|
899
|
-
var
|
|
1147
|
+
var open$2 = function open(query, transition, focus) {
|
|
1148
|
+
if (focus === void 0) {
|
|
1149
|
+
focus = true;
|
|
1150
|
+
}
|
|
1151
|
+
|
|
900
1152
|
try {
|
|
1153
|
+
var _temp3 = function _temp3() {
|
|
1154
|
+
// Set focus to the drawer element if the focus param is true.
|
|
1155
|
+
if (focus) {
|
|
1156
|
+
updateFocusState$1.call(_this2, drawer);
|
|
1157
|
+
} // Dispatch custom opened event.
|
|
1158
|
+
|
|
1159
|
+
|
|
1160
|
+
drawer.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'opened', {
|
|
1161
|
+
detail: _this2,
|
|
1162
|
+
bubbles: true
|
|
1163
|
+
})); // Return the drawer.
|
|
1164
|
+
|
|
1165
|
+
return drawer;
|
|
1166
|
+
};
|
|
1167
|
+
|
|
901
1168
|
var _this2 = this;
|
|
902
1169
|
|
|
903
|
-
|
|
1170
|
+
// Get the drawer from collection.
|
|
1171
|
+
var drawer = getDrawer.call(_this2, query); // Get the modal configuration.
|
|
904
1172
|
|
|
905
|
-
|
|
1173
|
+
var config = _extends({}, _this2.settings, drawer.settings); // Add transition parameter to configuration.
|
|
906
1174
|
|
|
907
|
-
if (hasClass(drawer, _this2.settings.stateOpened)) {
|
|
908
|
-
_this2.working = true;
|
|
909
1175
|
|
|
910
|
-
|
|
911
|
-
setInert(false, _this2.settings.selectorInert);
|
|
912
|
-
setOverflowHidden(false, _this2.settings.selectorOverflow);
|
|
913
|
-
}
|
|
1176
|
+
if (transition !== undefined) config.transition = transition; // If drawer is closed.
|
|
914
1177
|
|
|
915
|
-
|
|
916
|
-
|
|
1178
|
+
var _temp4 = function () {
|
|
1179
|
+
if (drawer.state === 'closed') {
|
|
1180
|
+
// Update drawer state.
|
|
1181
|
+
drawer.state = 'opening'; // Run the open transition.
|
|
917
1182
|
|
|
918
|
-
|
|
1183
|
+
return Promise.resolve(openTransition(drawer.el, config)).then(function () {
|
|
1184
|
+
// Update the global state if mode is modal.
|
|
1185
|
+
if (drawer.mode === 'modal') updateGlobalState(true, config); // Update drawer state.
|
|
919
1186
|
|
|
920
|
-
|
|
1187
|
+
drawer.state = 'opened';
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
}();
|
|
921
1191
|
|
|
922
|
-
|
|
923
|
-
detail: _this2,
|
|
924
|
-
bubbles: true
|
|
925
|
-
}));
|
|
926
|
-
_this2.working = false;
|
|
927
|
-
return drawer;
|
|
928
|
-
});
|
|
929
|
-
} else {
|
|
930
|
-
return Promise.resolve(drawer);
|
|
931
|
-
}
|
|
1192
|
+
return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(_temp3) : _temp3(_temp4));
|
|
932
1193
|
} catch (e) {
|
|
933
1194
|
return Promise.reject(e);
|
|
934
1195
|
}
|
|
935
1196
|
};
|
|
936
1197
|
|
|
937
|
-
function
|
|
938
|
-
|
|
939
|
-
|
|
1198
|
+
var close$2 = function close(query, transition, focus) {
|
|
1199
|
+
if (focus === void 0) {
|
|
1200
|
+
focus = true;
|
|
1201
|
+
}
|
|
940
1202
|
|
|
941
|
-
|
|
1203
|
+
try {
|
|
1204
|
+
var _this2 = this;
|
|
942
1205
|
|
|
943
|
-
|
|
944
|
-
var
|
|
945
|
-
this.memory.trigger = trigger;
|
|
946
|
-
this.toggle(selector);
|
|
947
|
-
event.preventDefault();
|
|
948
|
-
return;
|
|
949
|
-
} // Open data trigger
|
|
1206
|
+
// Get the drawer from collection.
|
|
1207
|
+
var drawer = getDrawer.call(_this2, query); // Get the modal configuration.
|
|
950
1208
|
|
|
1209
|
+
var config = _extends({}, _this2.settings, drawer.settings); // Add transition parameter to configuration.
|
|
951
1210
|
|
|
952
|
-
trigger = event.target.closest("[data-" + this.settings.dataOpen + "]");
|
|
953
1211
|
|
|
954
|
-
|
|
955
|
-
var _selector = trigger.getAttribute("data-" + this.settings.dataOpen);
|
|
1212
|
+
if (transition !== undefined) config.transition = transition; // If drawer is opened.
|
|
956
1213
|
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
} // Close data trigger
|
|
1214
|
+
var _temp2 = function () {
|
|
1215
|
+
if (drawer.state === 'opened') {
|
|
1216
|
+
// Update drawer state.
|
|
1217
|
+
drawer.state = 'closing'; // Remove focus from active element.
|
|
962
1218
|
|
|
1219
|
+
document.activeElement.blur(); // Run the close transition.
|
|
963
1220
|
|
|
964
|
-
|
|
1221
|
+
return Promise.resolve(closeTransition(drawer.el, config)).then(function () {
|
|
1222
|
+
// Update the global state if mode is modal.
|
|
1223
|
+
if (drawer.mode === 'modal') updateGlobalState(false, config); // Set focus to the trigger element if the focus param is true.
|
|
965
1224
|
|
|
966
|
-
|
|
967
|
-
|
|
1225
|
+
if (focus) {
|
|
1226
|
+
updateFocusState$1.call(_this2, drawer);
|
|
1227
|
+
} // Update drawer state.
|
|
968
1228
|
|
|
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
1229
|
|
|
977
|
-
|
|
978
|
-
return;
|
|
979
|
-
} // Screen modal trigger
|
|
1230
|
+
drawer.state = 'closed'; // Dispatch custom closed event.
|
|
980
1231
|
|
|
1232
|
+
drawer.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'closed', {
|
|
1233
|
+
detail: _this2,
|
|
1234
|
+
bubbles: true
|
|
1235
|
+
}));
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
}();
|
|
981
1239
|
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
1240
|
+
return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {
|
|
1241
|
+
// Return the drawer.
|
|
1242
|
+
return drawer;
|
|
1243
|
+
}) : drawer);
|
|
1244
|
+
} catch (e) {
|
|
1245
|
+
return Promise.reject(e);
|
|
985
1246
|
}
|
|
986
|
-
}
|
|
987
|
-
function handlerKeydown$1(event) {
|
|
988
|
-
// Working catch
|
|
989
|
-
if (this.working) return;
|
|
1247
|
+
};
|
|
990
1248
|
|
|
991
|
-
|
|
992
|
-
|
|
1249
|
+
var toggle = function toggle(query, transition, focus) {
|
|
1250
|
+
try {
|
|
1251
|
+
var _this2 = this;
|
|
1252
|
+
|
|
1253
|
+
// Get the drawer from collection.
|
|
1254
|
+
var drawer = getDrawer.call(_this2, query); // Open or close the drawer based on its current state.
|
|
993
1255
|
|
|
994
|
-
if (
|
|
995
|
-
|
|
1256
|
+
if (drawer.state === 'closed') {
|
|
1257
|
+
return Promise.resolve(open$2.call(_this2, drawer, transition, focus));
|
|
1258
|
+
} else {
|
|
1259
|
+
return Promise.resolve(close$2.call(_this2, drawer, transition, focus));
|
|
996
1260
|
}
|
|
1261
|
+
} catch (e) {
|
|
1262
|
+
return Promise.reject(e);
|
|
997
1263
|
}
|
|
998
|
-
}
|
|
1264
|
+
};
|
|
999
1265
|
|
|
1000
|
-
var
|
|
1266
|
+
var toModal = function toModal(entry) {
|
|
1001
1267
|
try {
|
|
1002
|
-
var
|
|
1003
|
-
|
|
1004
|
-
var drawer = _this2.getDrawer(drawerKey);
|
|
1005
|
-
|
|
1006
|
-
if (!drawer) return Promise.resolve(drawerNotFound(drawerKey));
|
|
1268
|
+
var _this4 = this;
|
|
1007
1269
|
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1270
|
+
// Get the drawer configuration.
|
|
1271
|
+
// Add the modal class.
|
|
1272
|
+
entry.el.classList.add(entry.getSetting('classModal')); // Set aria-modal attribute to true.
|
|
1011
1273
|
|
|
1012
|
-
|
|
1013
|
-
setOverflowHidden(true, _this2.settings.selectorOverflow);
|
|
1014
|
-
}
|
|
1274
|
+
entry.dialog.setAttribute('aria-modal', 'true'); // If there isn't a stored state but also has the opened state class...
|
|
1015
1275
|
|
|
1016
|
-
|
|
1017
|
-
|
|
1276
|
+
if (!_this4.store[entry.id] && entry.el.classList.contains(entry.getSetting('stateOpened'))) {
|
|
1277
|
+
// Save the opened state in local store.
|
|
1278
|
+
_this4.store[entry.id] = 'opened';
|
|
1279
|
+
} // Modal drawer defaults to closed state.
|
|
1018
1280
|
|
|
1019
|
-
if (isModal) {
|
|
1020
|
-
_this2.focusTrap.init(drawer);
|
|
1021
1281
|
|
|
1022
|
-
|
|
1023
|
-
|
|
1282
|
+
return Promise.resolve(close$2.call(_this4, entry, false, false)).then(function () {
|
|
1283
|
+
// Dispatch custom switch event.
|
|
1284
|
+
entry.el.dispatchEvent(new CustomEvent(entry.getSetting('customEventPrefix') + 'switchMode', {
|
|
1285
|
+
detail: _this4,
|
|
1286
|
+
bubbles: true
|
|
1287
|
+
})); // Return the entry.
|
|
1024
1288
|
|
|
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
|
-
}
|
|
1289
|
+
return entry;
|
|
1290
|
+
});
|
|
1037
1291
|
} catch (e) {
|
|
1038
1292
|
return Promise.reject(e);
|
|
1039
1293
|
}
|
|
1040
1294
|
};
|
|
1041
1295
|
|
|
1042
|
-
function
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
var storageCheck = localStorage.getItem(settings.stateKey);
|
|
1296
|
+
var toInline = function toInline(entry) {
|
|
1297
|
+
try {
|
|
1298
|
+
var _this2 = this;
|
|
1047
1299
|
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
} // Set the existing state
|
|
1300
|
+
// Remove the modal class.
|
|
1301
|
+
entry.el.classList.remove(entry.getSetting('classModal')); // Remove the aria-modal attribute.
|
|
1051
1302
|
|
|
1303
|
+
entry.dialog.removeAttribute('aria-modal'); // Update the global state.
|
|
1052
1304
|
|
|
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
|
|
1305
|
+
updateGlobalState(false, _extends({}, _this2.settings, entry.settings)); // Remove any focus traps.
|
|
1064
1306
|
|
|
1065
|
-
|
|
1307
|
+
_this2.focusTrap.unmount(); // Setup initial state.
|
|
1066
1308
|
|
|
1067
|
-
var drawers = target ? [target] : document.querySelectorAll("[data-" + settings.dataDrawer + "]"); // Loop through drawers and save their states
|
|
1068
1309
|
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1310
|
+
return Promise.resolve(initialState.call(_this2, entry)).then(function () {
|
|
1311
|
+
// Dispatch custom switch event.
|
|
1312
|
+
entry.el.dispatchEvent(new CustomEvent(entry.getSetting('customEventPrefix') + 'switchMode', {
|
|
1313
|
+
detail: _this2,
|
|
1314
|
+
bubbles: true
|
|
1315
|
+
})); // Return the entry.
|
|
1074
1316
|
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
if (localStorage.getItem(settings.stateKey)) {
|
|
1080
|
-
localStorage.removeItem(settings.stateKey);
|
|
1317
|
+
return entry;
|
|
1318
|
+
});
|
|
1319
|
+
} catch (e) {
|
|
1320
|
+
return Promise.reject(e);
|
|
1081
1321
|
}
|
|
1322
|
+
};
|
|
1082
1323
|
|
|
1083
|
-
|
|
1324
|
+
function switchMode(entry) {
|
|
1325
|
+
switch (entry.mode) {
|
|
1326
|
+
case 'inline':
|
|
1327
|
+
return toInline.call(this, entry);
|
|
1328
|
+
|
|
1329
|
+
case 'modal':
|
|
1330
|
+
return toModal.call(this, entry);
|
|
1331
|
+
|
|
1332
|
+
default:
|
|
1333
|
+
throw new Error("\"" + entry.mode + "\" is not a valid drawer mode.");
|
|
1334
|
+
}
|
|
1084
1335
|
}
|
|
1085
1336
|
|
|
1086
|
-
var
|
|
1337
|
+
var register$2 = function register(el, dialog) {
|
|
1087
1338
|
try {
|
|
1088
|
-
var
|
|
1339
|
+
var _this2 = this;
|
|
1089
1340
|
|
|
1090
|
-
//
|
|
1091
|
-
|
|
1341
|
+
// Deregister entry incase it has already been registered.
|
|
1342
|
+
return Promise.resolve(deregister$2.call(_this2, el, false)).then(function () {
|
|
1343
|
+
// Save root this for use inside methods API.
|
|
1344
|
+
var root = _this2; // Create an instance of the Breakpoint class.
|
|
1092
1345
|
|
|
1093
|
-
|
|
1094
|
-
if (!hasClass(drawer, _this4.settings.classModal)) return Promise.resolve(); // Tear down modal state
|
|
1346
|
+
var breakpoint = new Breakpoint(); // Setup methods API.
|
|
1095
1347
|
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1348
|
+
var methods = {
|
|
1349
|
+
open: function open(transition, focus) {
|
|
1350
|
+
return open$2.call(root, this, transition, focus);
|
|
1351
|
+
},
|
|
1352
|
+
close: function close(transition, focus) {
|
|
1353
|
+
return close$2.call(root, this, transition, focus);
|
|
1354
|
+
},
|
|
1355
|
+
toggle: function toggle$1(transition, focus) {
|
|
1356
|
+
return toggle.call(root, this, transition, focus);
|
|
1357
|
+
},
|
|
1358
|
+
deregister: function deregister() {
|
|
1359
|
+
return deregister$2.call(root, this);
|
|
1360
|
+
},
|
|
1361
|
+
mountBreakpoint: function mountBreakpoint() {
|
|
1362
|
+
var value = this.breakpoint;
|
|
1363
|
+
var handler = this.handleBreakpoint.bind(this);
|
|
1364
|
+
breakpoint.mount(value, handler);
|
|
1365
|
+
return this;
|
|
1366
|
+
},
|
|
1367
|
+
unmountBreakpoint: function unmountBreakpoint() {
|
|
1368
|
+
breakpoint.unmount();
|
|
1369
|
+
return this;
|
|
1370
|
+
},
|
|
1371
|
+
handleBreakpoint: function handleBreakpoint(event) {
|
|
1372
|
+
this.mode = event.matches ? 'inline' : 'modal';
|
|
1373
|
+
return this;
|
|
1374
|
+
},
|
|
1375
|
+
getSetting: function getSetting(key) {
|
|
1376
|
+
return key in this.settings ? this.settings[key] : root.settings[key];
|
|
1377
|
+
}
|
|
1378
|
+
}; // Setup the drawer object.
|
|
1099
1379
|
|
|
1100
|
-
|
|
1380
|
+
var entry = _extends({
|
|
1381
|
+
id: el.id,
|
|
1382
|
+
el: el,
|
|
1383
|
+
dialog: dialog,
|
|
1384
|
+
trigger: null,
|
|
1385
|
+
settings: getConfig$1(el, _this2.settings.dataConfig),
|
|
1101
1386
|
|
|
1387
|
+
get breakpoint() {
|
|
1388
|
+
return getBreakpoint.call(root, el);
|
|
1389
|
+
},
|
|
1102
1390
|
|
|
1103
|
-
|
|
1104
|
-
|
|
1391
|
+
get state() {
|
|
1392
|
+
return __state;
|
|
1393
|
+
},
|
|
1105
1394
|
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
removeClass(drawer, _this4.settings.stateClosed);
|
|
1109
|
-
} // Dispatch custom event
|
|
1395
|
+
set state(value) {
|
|
1396
|
+
__state = value; // Save 'opened' and 'closed' states to store if mode is inline.
|
|
1110
1397
|
|
|
1398
|
+
if (value === 'opened' || value === 'closed') {
|
|
1399
|
+
if (this.mode === 'inline') root.store[this.id] = this.state;
|
|
1400
|
+
}
|
|
1401
|
+
},
|
|
1111
1402
|
|
|
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;
|
|
1403
|
+
get mode() {
|
|
1404
|
+
return __mode;
|
|
1405
|
+
},
|
|
1123
1406
|
|
|
1124
|
-
|
|
1125
|
-
|
|
1407
|
+
set mode(value) {
|
|
1408
|
+
__mode = value;
|
|
1409
|
+
switchMode.call(root, this);
|
|
1410
|
+
}
|
|
1126
1411
|
|
|
1127
|
-
|
|
1128
|
-
if (hasClass(drawer, _this2.settings.classModal)) return Promise.resolve(); // Enable modal state
|
|
1412
|
+
}, methods); // Create the state var with the initial state.
|
|
1129
1413
|
|
|
1130
|
-
addClass(drawer, _this2.settings.classModal);
|
|
1131
|
-
addClass(drawer, _this2.settings.stateClosed);
|
|
1132
|
-
removeClass(drawer, _this2.settings.stateOpened); // Dispatch custom event
|
|
1133
1414
|
|
|
1134
|
-
|
|
1135
|
-
bubbles: true
|
|
1136
|
-
}));
|
|
1137
|
-
return Promise.resolve(drawer);
|
|
1138
|
-
} catch (e) {
|
|
1139
|
-
return Promise.reject(e);
|
|
1140
|
-
}
|
|
1141
|
-
};
|
|
1415
|
+
var __state = el.classList.contains(entry.getSetting('stateOpened')) ? 'opened' : 'closed'; // Create the mode var with the initial mode.
|
|
1142
1416
|
|
|
1143
|
-
var toggle = function toggle(drawerKey) {
|
|
1144
|
-
try {
|
|
1145
|
-
var _this2 = this;
|
|
1146
1417
|
|
|
1147
|
-
|
|
1418
|
+
var __mode = el.classList.contains(entry.getSetting('classModal')) ? 'modal' : 'inline'; // Setup mode specific attributes.
|
|
1148
1419
|
|
|
1149
|
-
if (!drawer) return Promise.resolve(drawerNotFound(drawerKey));
|
|
1150
|
-
var isClosed = !hasClass(drawer, _this2.settings.stateOpened);
|
|
1151
1420
|
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1421
|
+
if (entry.mode === 'modal') {
|
|
1422
|
+
// Set aria-modal attribute to true.
|
|
1423
|
+
entry.dialog.setAttribute('aria-modal', 'true');
|
|
1424
|
+
} else {
|
|
1425
|
+
// Remove the aria-modal attribute.
|
|
1426
|
+
entry.dialog.removeAttribute('aria-modal');
|
|
1427
|
+
} // Set tabindex="-1" so dialog is focusable via JS or click.
|
|
1428
|
+
|
|
1429
|
+
|
|
1430
|
+
if (entry.getSetting('setTabindex')) {
|
|
1431
|
+
entry.dialog.setAttribute('tabindex', '-1');
|
|
1432
|
+
} // Add entry to collection.
|
|
1433
|
+
|
|
1434
|
+
|
|
1435
|
+
_this2.collection.push(entry); // If the entry has a breakpoint...
|
|
1436
|
+
|
|
1437
|
+
|
|
1438
|
+
var _temp = function () {
|
|
1439
|
+
if (entry.breakpoint) {
|
|
1440
|
+
// Mount media query breakpoint functionality.
|
|
1441
|
+
entry.mountBreakpoint();
|
|
1442
|
+
} else {
|
|
1443
|
+
// Else, Setup initial state.
|
|
1444
|
+
return Promise.resolve(initialState.call(_this2, entry)).then(function () {});
|
|
1445
|
+
}
|
|
1446
|
+
}();
|
|
1447
|
+
|
|
1448
|
+
return _temp && _temp.then ? _temp.then(function () {
|
|
1449
|
+
// Return the registered entry.
|
|
1450
|
+
return entry;
|
|
1451
|
+
}) : entry;
|
|
1452
|
+
});
|
|
1157
1453
|
} catch (e) {
|
|
1158
1454
|
return Promise.reject(e);
|
|
1159
1455
|
}
|
|
1160
1456
|
};
|
|
1161
1457
|
|
|
1162
|
-
var
|
|
1458
|
+
var _handleClick$1 = /*#__PURE__*/_classPrivateFieldLooseKey("handleClick");
|
|
1459
|
+
|
|
1460
|
+
var _handleKeydown$2 = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
|
|
1461
|
+
|
|
1462
|
+
var Drawer = /*#__PURE__*/function (_Collection) {
|
|
1463
|
+
_inheritsLoose(Drawer, _Collection);
|
|
1464
|
+
|
|
1163
1465
|
function Drawer(options) {
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1466
|
+
var _this;
|
|
1467
|
+
|
|
1468
|
+
_this = _Collection.call(this) || this;
|
|
1469
|
+
Object.defineProperty(_assertThisInitialized(_this), _handleClick$1, {
|
|
1470
|
+
writable: true,
|
|
1471
|
+
value: void 0
|
|
1472
|
+
});
|
|
1473
|
+
Object.defineProperty(_assertThisInitialized(_this), _handleKeydown$2, {
|
|
1474
|
+
writable: true,
|
|
1475
|
+
value: void 0
|
|
1476
|
+
});
|
|
1477
|
+
_this.defaults = defaults$2;
|
|
1478
|
+
_this.settings = _extends({}, _this.defaults, options);
|
|
1479
|
+
_this.focusTrap = new FocusTrap(); // Setup local store for inline drawer state management.
|
|
1480
|
+
|
|
1481
|
+
_this.store = localStore(_this.settings.storeKey, _this.settings.store);
|
|
1482
|
+
_classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleClick$1)[_handleClick$1] = handleClick$2.bind(_assertThisInitialized(_this));
|
|
1483
|
+
_classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleKeydown$2)[_handleKeydown$2] = handleKeydown$2.bind(_assertThisInitialized(_this));
|
|
1484
|
+
if (_this.settings.autoInit) _this.init();
|
|
1485
|
+
return _this;
|
|
1174
1486
|
}
|
|
1175
1487
|
|
|
1176
1488
|
var _proto = Drawer.prototype;
|
|
@@ -1180,109 +1492,91 @@
|
|
|
1180
1492
|
options = null;
|
|
1181
1493
|
}
|
|
1182
1494
|
|
|
1183
|
-
|
|
1184
|
-
|
|
1495
|
+
try {
|
|
1496
|
+
var _this3 = this;
|
|
1185
1497
|
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1498
|
+
// Update settings with passed options.
|
|
1499
|
+
if (options) _this3.settings = _extends({}, _this3.settings, options); // Get all the modals.
|
|
1500
|
+
|
|
1501
|
+
var drawers = document.querySelectorAll(_this3.settings.selectorDrawer); // Register the collections array with modal instances.
|
|
1189
1502
|
|
|
1190
|
-
|
|
1503
|
+
return Promise.resolve(_this3.registerCollection(drawers)).then(function () {
|
|
1504
|
+
// If eventListeners are enabled, init event listeners.
|
|
1505
|
+
if (_this3.settings.eventListeners) {
|
|
1506
|
+
_this3.initEventListeners();
|
|
1507
|
+
}
|
|
1191
1508
|
|
|
1192
|
-
|
|
1193
|
-
|
|
1509
|
+
return _this3;
|
|
1510
|
+
});
|
|
1511
|
+
} catch (e) {
|
|
1512
|
+
return Promise.reject(e);
|
|
1194
1513
|
}
|
|
1195
1514
|
};
|
|
1196
1515
|
|
|
1197
1516
|
_proto.destroy = function destroy() {
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1517
|
+
try {
|
|
1518
|
+
var _this5 = this;
|
|
1519
|
+
|
|
1520
|
+
// Remove all entries from the collection.
|
|
1521
|
+
return Promise.resolve(_this5.deregisterCollection()).then(function () {
|
|
1522
|
+
// If eventListeners are enabled, init event listeners.
|
|
1523
|
+
if (_this5.settings.eventListeners) {
|
|
1524
|
+
_this5.destroyEventListeners();
|
|
1525
|
+
}
|
|
1202
1526
|
|
|
1203
|
-
|
|
1204
|
-
|
|
1527
|
+
return _this5;
|
|
1528
|
+
});
|
|
1529
|
+
} catch (e) {
|
|
1530
|
+
return Promise.reject(e);
|
|
1205
1531
|
}
|
|
1206
|
-
}
|
|
1207
|
-
/**
|
|
1208
|
-
* Event listeners
|
|
1209
|
-
*/
|
|
1210
|
-
;
|
|
1532
|
+
};
|
|
1211
1533
|
|
|
1212
1534
|
_proto.initEventListeners = function initEventListeners() {
|
|
1213
|
-
document.addEventListener('click', this
|
|
1214
|
-
document.addEventListener('touchend', this
|
|
1215
|
-
document.addEventListener('keydown', this
|
|
1535
|
+
document.addEventListener('click', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
|
|
1536
|
+
document.addEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
|
|
1537
|
+
document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$2)[_handleKeydown$2], false);
|
|
1216
1538
|
};
|
|
1217
1539
|
|
|
1218
1540
|
_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);
|
|
1541
|
+
document.removeEventListener('click', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
|
|
1542
|
+
document.removeEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
|
|
1543
|
+
document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$2)[_handleKeydown$2], false);
|
|
1230
1544
|
};
|
|
1231
1545
|
|
|
1232
|
-
_proto.
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
* Save state functionality
|
|
1237
|
-
*/
|
|
1238
|
-
;
|
|
1239
|
-
|
|
1240
|
-
_proto.stateSet = function stateSet$1() {
|
|
1241
|
-
this.state = stateSet(this.settings);
|
|
1546
|
+
_proto.register = function register(query) {
|
|
1547
|
+
var els = getDrawerElements.call(this, query);
|
|
1548
|
+
if (els.error) return Promise.reject(els.error);
|
|
1549
|
+
return register$2.call(this, els.drawer, els.dialog);
|
|
1242
1550
|
};
|
|
1243
1551
|
|
|
1244
|
-
_proto.
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
this.state = stateSave(target, this.settings);
|
|
1552
|
+
_proto.deregister = function deregister(query) {
|
|
1553
|
+
var entry = this.get(getDrawerID.call(this, query));
|
|
1554
|
+
return deregister$2.call(this, entry);
|
|
1250
1555
|
};
|
|
1251
1556
|
|
|
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);
|
|
1557
|
+
_proto.open = function open(id, transition, focus) {
|
|
1558
|
+
return open$2.call(this, id, transition, focus);
|
|
1262
1559
|
};
|
|
1263
1560
|
|
|
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);
|
|
1561
|
+
_proto.close = function close(id, transition, focus) {
|
|
1562
|
+
return close$2.call(this, id, transition, focus);
|
|
1274
1563
|
};
|
|
1275
1564
|
|
|
1276
|
-
_proto.
|
|
1277
|
-
return
|
|
1565
|
+
_proto.toggle = function toggle$1(id, transition, focus) {
|
|
1566
|
+
return toggle.call(this, id, transition, focus);
|
|
1278
1567
|
};
|
|
1279
1568
|
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1569
|
+
_createClass(Drawer, [{
|
|
1570
|
+
key: "activeModal",
|
|
1571
|
+
get: function get() {
|
|
1572
|
+
return this.collection.find(function (entry) {
|
|
1573
|
+
return entry.state === 'opened' && entry.mode === 'modal';
|
|
1574
|
+
});
|
|
1575
|
+
}
|
|
1576
|
+
}]);
|
|
1283
1577
|
|
|
1284
1578
|
return Drawer;
|
|
1285
|
-
}();
|
|
1579
|
+
}(Collection);
|
|
1286
1580
|
|
|
1287
1581
|
var defaults$1 = {
|
|
1288
1582
|
autoInit: false,
|
|
@@ -1312,38 +1606,6 @@
|
|
|
1312
1606
|
transition: true
|
|
1313
1607
|
};
|
|
1314
1608
|
|
|
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
1609
|
function getModal(query) {
|
|
1348
1610
|
// Get the entry from collection.
|
|
1349
1611
|
var entry = typeof query === 'string' ? this.get(query) : this.get(query.id); // Return entry if it was resolved, otherwise throw error.
|
|
@@ -1351,9 +1613,10 @@
|
|
|
1351
1613
|
if (entry) {
|
|
1352
1614
|
return entry;
|
|
1353
1615
|
} else {
|
|
1354
|
-
throw new Error("Modal not found in collection with id of \"" + query + "\".");
|
|
1616
|
+
throw new Error("Modal not found in collection with id of \"" + (query.id || query) + "\".");
|
|
1355
1617
|
}
|
|
1356
1618
|
}
|
|
1619
|
+
|
|
1357
1620
|
function getModalID(obj) {
|
|
1358
1621
|
// If it's a string, return the string.
|
|
1359
1622
|
if (typeof obj === 'string') {
|
|
@@ -1369,7 +1632,7 @@
|
|
|
1369
1632
|
} // If it's a modal replace trigger, return data value.
|
|
1370
1633
|
else if (obj.hasAttribute("data-" + this.settings.dataReplace)) {
|
|
1371
1634
|
return obj.getAttribute("data-" + this.settings.dataReplace);
|
|
1372
|
-
} // If it's a modal
|
|
1635
|
+
} // If it's a modal element, return the id.
|
|
1373
1636
|
else if (obj.closest(this.settings.selectorModal)) {
|
|
1374
1637
|
obj = obj.closest(this.settings.selectorModal);
|
|
1375
1638
|
return obj.id || false;
|
|
@@ -1381,14 +1644,15 @@
|
|
|
1381
1644
|
} // Return false if no id was found.
|
|
1382
1645
|
else return false;
|
|
1383
1646
|
}
|
|
1647
|
+
|
|
1384
1648
|
function getModalElements(query) {
|
|
1385
1649
|
var id = getModalID.call(this, query);
|
|
1386
1650
|
|
|
1387
1651
|
if (id) {
|
|
1388
|
-
var
|
|
1389
|
-
var dialog =
|
|
1652
|
+
var modal = document.querySelector("#" + id);
|
|
1653
|
+
var dialog = modal ? modal.querySelector(this.settings.selectorDialog) : null;
|
|
1390
1654
|
|
|
1391
|
-
if (!
|
|
1655
|
+
if (!modal && !dialog) {
|
|
1392
1656
|
return {
|
|
1393
1657
|
error: new Error("No modal elements found using the ID: \"" + id + "\".")
|
|
1394
1658
|
};
|
|
@@ -1398,7 +1662,7 @@
|
|
|
1398
1662
|
};
|
|
1399
1663
|
} else {
|
|
1400
1664
|
return {
|
|
1401
|
-
|
|
1665
|
+
modal: modal,
|
|
1402
1666
|
dialog: dialog
|
|
1403
1667
|
};
|
|
1404
1668
|
}
|
|
@@ -1409,7 +1673,31 @@
|
|
|
1409
1673
|
}
|
|
1410
1674
|
}
|
|
1411
1675
|
|
|
1412
|
-
|
|
1676
|
+
function updateFocusState() {
|
|
1677
|
+
// Check if there's an active modal
|
|
1678
|
+
if (this.active) {
|
|
1679
|
+
// Mount the focus trap on the active modal.
|
|
1680
|
+
this.focusTrap.mount(this.active.dialog, this.settings.selectorFocus);
|
|
1681
|
+
} else {
|
|
1682
|
+
// Set focus to root trigger and unmount the focus trap.
|
|
1683
|
+
if (this.trigger) {
|
|
1684
|
+
this.trigger.focus();
|
|
1685
|
+
this.trigger = null;
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
this.focusTrap.unmount();
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
function updateStackIndex(stack) {
|
|
1693
|
+
stack.forEach(function (entry, index) {
|
|
1694
|
+
entry.el.style.zIndex = null;
|
|
1695
|
+
var value = getComputedStyle(entry.el)['z-index'];
|
|
1696
|
+
entry.el.style.zIndex = parseInt(value) + index + 1;
|
|
1697
|
+
});
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
var handleClick$1 = function handleClick(event) {
|
|
1413
1701
|
try {
|
|
1414
1702
|
var _this2 = this;
|
|
1415
1703
|
|
|
@@ -1420,7 +1708,7 @@
|
|
|
1420
1708
|
event.preventDefault(); // Save the trigger if it's not coming from inside a modal.
|
|
1421
1709
|
|
|
1422
1710
|
var fromModal = event.target.closest(_this2.settings.selectorModal);
|
|
1423
|
-
if (!fromModal) _this2.
|
|
1711
|
+
if (!fromModal) _this2.trigger = trigger; // Get the modal.
|
|
1424
1712
|
|
|
1425
1713
|
var modal = _this2.get(getModalID.call(_this2, trigger)); // Depending on the button type, either open or replace the modal.
|
|
1426
1714
|
|
|
@@ -1449,7 +1737,7 @@
|
|
|
1449
1737
|
return Promise.reject(e);
|
|
1450
1738
|
}
|
|
1451
1739
|
};
|
|
1452
|
-
function handleKeydown(event) {
|
|
1740
|
+
function handleKeydown$1(event) {
|
|
1453
1741
|
// If escape key was pressed.
|
|
1454
1742
|
if (event.key === 'Escape') {
|
|
1455
1743
|
// If a modal is opened and not required, close the modal.
|
|
@@ -1524,20 +1812,20 @@
|
|
|
1524
1812
|
}
|
|
1525
1813
|
};
|
|
1526
1814
|
|
|
1527
|
-
var open$1 = function open(query, transition,
|
|
1528
|
-
if (
|
|
1529
|
-
|
|
1815
|
+
var open$1 = function open(query, transition, focus) {
|
|
1816
|
+
if (focus === void 0) {
|
|
1817
|
+
focus = true;
|
|
1530
1818
|
}
|
|
1531
1819
|
|
|
1532
1820
|
try {
|
|
1533
1821
|
var _temp3 = function _temp3() {
|
|
1534
|
-
// Update
|
|
1535
|
-
if (
|
|
1822
|
+
// Update focus if the focus param is true.
|
|
1823
|
+
if (focus) {
|
|
1536
1824
|
updateFocusState.call(_this2);
|
|
1537
1825
|
} // Dispatch custom opened event.
|
|
1538
1826
|
|
|
1539
1827
|
|
|
1540
|
-
modal.
|
|
1828
|
+
modal.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'opened', {
|
|
1541
1829
|
detail: _this2,
|
|
1542
1830
|
bubbles: true
|
|
1543
1831
|
})); // Return the modal.
|
|
@@ -1574,14 +1862,14 @@
|
|
|
1574
1862
|
// Update modal state.
|
|
1575
1863
|
modal.state = 'opening'; // Apply z-index styles based on stack length.
|
|
1576
1864
|
|
|
1577
|
-
modal.
|
|
1578
|
-
var value = getComputedStyle(modal.
|
|
1579
|
-
modal.
|
|
1865
|
+
modal.el.style.zIndex = null;
|
|
1866
|
+
var value = getComputedStyle(modal.el)['z-index'];
|
|
1867
|
+
modal.el.style.zIndex = parseInt(value) + _this2.stack.length + 1; // Store modal in stack array.
|
|
1580
1868
|
|
|
1581
1869
|
_this2.stack.push(modal); // Run the open transition.
|
|
1582
1870
|
|
|
1583
1871
|
|
|
1584
|
-
return Promise.resolve(openTransition(modal.
|
|
1872
|
+
return Promise.resolve(openTransition(modal.el, config)).then(function () {
|
|
1585
1873
|
// Update modal state.
|
|
1586
1874
|
modal.state = 'opened';
|
|
1587
1875
|
});
|
|
@@ -1594,9 +1882,9 @@
|
|
|
1594
1882
|
}
|
|
1595
1883
|
};
|
|
1596
1884
|
|
|
1597
|
-
var close$1 = function close(query, transition,
|
|
1598
|
-
if (
|
|
1599
|
-
|
|
1885
|
+
var close$1 = function close(query, transition, focus) {
|
|
1886
|
+
if (focus === void 0) {
|
|
1887
|
+
focus = true;
|
|
1600
1888
|
}
|
|
1601
1889
|
|
|
1602
1890
|
try {
|
|
@@ -1617,26 +1905,26 @@
|
|
|
1617
1905
|
|
|
1618
1906
|
document.activeElement.blur(); // Run the close transition.
|
|
1619
1907
|
|
|
1620
|
-
return Promise.resolve(closeTransition(modal.
|
|
1908
|
+
return Promise.resolve(closeTransition(modal.el, config)).then(function () {
|
|
1621
1909
|
// Remove z-index styles.
|
|
1622
|
-
modal.
|
|
1910
|
+
modal.el.style.zIndex = null; // Get index of modal in stack array.
|
|
1623
1911
|
|
|
1624
1912
|
var index = _this2.stack.findIndex(function (entry) {
|
|
1625
1913
|
return entry.id === modal.id;
|
|
1626
1914
|
}); // Remove modal from stack array.
|
|
1627
1915
|
|
|
1628
1916
|
|
|
1629
|
-
_this2.stack.splice(index, 1); // Update
|
|
1917
|
+
_this2.stack.splice(index, 1); // Update focus if the focus param is true.
|
|
1630
1918
|
|
|
1631
1919
|
|
|
1632
|
-
if (
|
|
1920
|
+
if (focus) {
|
|
1633
1921
|
updateFocusState.call(_this2);
|
|
1634
1922
|
} // Update modal state.
|
|
1635
1923
|
|
|
1636
1924
|
|
|
1637
1925
|
modal.state = 'closed'; // Dispatch custom closed event.
|
|
1638
1926
|
|
|
1639
|
-
modal.
|
|
1927
|
+
modal.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'closed', {
|
|
1640
1928
|
detail: _this2,
|
|
1641
1929
|
bubbles: true
|
|
1642
1930
|
}));
|
|
@@ -1669,7 +1957,7 @@
|
|
|
1669
1957
|
Promise.resolve();
|
|
1670
1958
|
} else {
|
|
1671
1959
|
var _push2 = result.push;
|
|
1672
|
-
return Promise.resolve(close$1.call(_this2, modal, transition,
|
|
1960
|
+
return Promise.resolve(close$1.call(_this2, modal, transition, false)).then(function (_close$call) {
|
|
1673
1961
|
_push2.call(result, _close$call);
|
|
1674
1962
|
});
|
|
1675
1963
|
}
|
|
@@ -1687,11 +1975,18 @@
|
|
|
1687
1975
|
}
|
|
1688
1976
|
};
|
|
1689
1977
|
|
|
1690
|
-
var replace = function replace(query, transition) {
|
|
1978
|
+
var replace = function replace(query, transition, focus) {
|
|
1979
|
+
if (focus === void 0) {
|
|
1980
|
+
focus = true;
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1691
1983
|
try {
|
|
1692
1984
|
var _temp3 = function _temp3() {
|
|
1693
|
-
// Update the focus
|
|
1694
|
-
|
|
1985
|
+
// Update focus if the focus param is true.
|
|
1986
|
+
if (focus) {
|
|
1987
|
+
updateFocusState.call(_this2);
|
|
1988
|
+
} // Return the modals there were opened and closed.
|
|
1989
|
+
|
|
1695
1990
|
|
|
1696
1991
|
return {
|
|
1697
1992
|
opened: resultOpened,
|
|
@@ -1715,7 +2010,7 @@
|
|
|
1715
2010
|
});
|
|
1716
2011
|
} else {
|
|
1717
2012
|
// If modal is closed, close all and open replacement at the same time.
|
|
1718
|
-
resultOpened = open$1.call(_this2, modal, transition,
|
|
2013
|
+
resultOpened = open$1.call(_this2, modal, transition, false);
|
|
1719
2014
|
resultClosed = closeAll$1.call(_this2, false, transition);
|
|
1720
2015
|
return Promise.resolve(Promise.all([resultOpened, resultClosed])).then(function () {});
|
|
1721
2016
|
}
|
|
@@ -1727,24 +2022,24 @@
|
|
|
1727
2022
|
}
|
|
1728
2023
|
};
|
|
1729
2024
|
|
|
1730
|
-
var register$1 = function register(
|
|
2025
|
+
var register$1 = function register(el, dialog) {
|
|
1731
2026
|
try {
|
|
1732
2027
|
var _this2 = this;
|
|
1733
2028
|
|
|
1734
2029
|
// Deregister entry incase it has already been registered.
|
|
1735
|
-
return Promise.resolve(deregister$1.call(_this2,
|
|
2030
|
+
return Promise.resolve(deregister$1.call(_this2, el, false)).then(function () {
|
|
1736
2031
|
// Save root this for use inside methods API.
|
|
1737
2032
|
var root = _this2; // Setup methods API.
|
|
1738
2033
|
|
|
1739
2034
|
var methods = {
|
|
1740
|
-
open: function open(transition) {
|
|
1741
|
-
return open$1.call(root, this, transition);
|
|
2035
|
+
open: function open(transition, focus) {
|
|
2036
|
+
return open$1.call(root, this, transition, focus);
|
|
1742
2037
|
},
|
|
1743
|
-
close: function close(transition) {
|
|
1744
|
-
return close$1.call(root, this, transition);
|
|
2038
|
+
close: function close(transition, focus) {
|
|
2039
|
+
return close$1.call(root, this, transition, focus);
|
|
1745
2040
|
},
|
|
1746
|
-
replace: function replace$1(transition) {
|
|
1747
|
-
return replace.call(root, this, transition);
|
|
2041
|
+
replace: function replace$1(transition, focus) {
|
|
2042
|
+
return replace.call(root, this, transition, focus);
|
|
1748
2043
|
},
|
|
1749
2044
|
deregister: function deregister() {
|
|
1750
2045
|
return deregister$1.call(root, this);
|
|
@@ -1759,19 +2054,19 @@
|
|
|
1759
2054
|
}
|
|
1760
2055
|
|
|
1761
2056
|
if (!this.returnRef) {
|
|
1762
|
-
this.returnRef = teleport(this.
|
|
1763
|
-
return this.
|
|
2057
|
+
this.returnRef = teleport(this.el, ref, method);
|
|
2058
|
+
return this.el;
|
|
1764
2059
|
} else {
|
|
1765
|
-
console.error('Element has already been teleported:', this.
|
|
2060
|
+
console.error('Element has already been teleported:', this.el);
|
|
1766
2061
|
return false;
|
|
1767
2062
|
}
|
|
1768
2063
|
},
|
|
1769
2064
|
teleportReturn: function teleportReturn() {
|
|
1770
2065
|
if (this.returnRef) {
|
|
1771
|
-
this.returnRef = teleport(this.
|
|
1772
|
-
return this.
|
|
2066
|
+
this.returnRef = teleport(this.el, this.returnRef);
|
|
2067
|
+
return this.el;
|
|
1773
2068
|
} else {
|
|
1774
|
-
console.error('No return reference found:', this.
|
|
2069
|
+
console.error('No return reference found:', this.el);
|
|
1775
2070
|
return false;
|
|
1776
2071
|
}
|
|
1777
2072
|
},
|
|
@@ -1781,12 +2076,12 @@
|
|
|
1781
2076
|
}; // Setup the modal object.
|
|
1782
2077
|
|
|
1783
2078
|
var entry = _extends({
|
|
1784
|
-
id:
|
|
2079
|
+
id: el.id,
|
|
1785
2080
|
state: 'closed',
|
|
1786
|
-
|
|
1787
|
-
target: target,
|
|
2081
|
+
el: el,
|
|
1788
2082
|
dialog: dialog,
|
|
1789
|
-
returnRef: null
|
|
2083
|
+
returnRef: null,
|
|
2084
|
+
settings: getConfig$1(el, _this2.settings.dataConfig)
|
|
1790
2085
|
}, methods); // Set aria-modal attribute to true.
|
|
1791
2086
|
|
|
1792
2087
|
|
|
@@ -1810,25 +2105,33 @@
|
|
|
1810
2105
|
_this2.collection.push(entry); // Setup initial state.
|
|
1811
2106
|
|
|
1812
2107
|
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
entry.target.classList.add(_this2.settings.stateClosed);
|
|
1822
|
-
} // Return the registered entry.
|
|
2108
|
+
var _temp = function () {
|
|
2109
|
+
if (entry.el.classList.contains(_this2.settings.stateOpened)) {
|
|
2110
|
+
// Open entry with transitions disabled.
|
|
2111
|
+
return Promise.resolve(entry.open(false)).then(function () {});
|
|
2112
|
+
} else {
|
|
2113
|
+
// Remove transition state classes.
|
|
2114
|
+
entry.el.classList.remove(_this2.settings.stateOpening);
|
|
2115
|
+
entry.el.classList.remove(_this2.settings.stateClosing); // Add closed state class.
|
|
1823
2116
|
|
|
2117
|
+
entry.el.classList.add(_this2.settings.stateClosed);
|
|
2118
|
+
}
|
|
2119
|
+
}();
|
|
1824
2120
|
|
|
1825
|
-
return
|
|
2121
|
+
return _temp && _temp.then ? _temp.then(function () {
|
|
2122
|
+
// Return the registered entry.
|
|
2123
|
+
return entry;
|
|
2124
|
+
}) : entry;
|
|
1826
2125
|
});
|
|
1827
2126
|
} catch (e) {
|
|
1828
2127
|
return Promise.reject(e);
|
|
1829
2128
|
}
|
|
1830
2129
|
};
|
|
1831
2130
|
|
|
2131
|
+
var _handleClick = /*#__PURE__*/_classPrivateFieldLooseKey("handleClick");
|
|
2132
|
+
|
|
2133
|
+
var _handleKeydown$1 = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
|
|
2134
|
+
|
|
1832
2135
|
var Modal = /*#__PURE__*/function (_Collection) {
|
|
1833
2136
|
_inheritsLoose(Modal, _Collection);
|
|
1834
2137
|
|
|
@@ -1836,24 +2139,33 @@
|
|
|
1836
2139
|
var _this;
|
|
1837
2140
|
|
|
1838
2141
|
_this = _Collection.call(this) || this;
|
|
2142
|
+
Object.defineProperty(_assertThisInitialized(_this), _handleClick, {
|
|
2143
|
+
writable: true,
|
|
2144
|
+
value: void 0
|
|
2145
|
+
});
|
|
2146
|
+
Object.defineProperty(_assertThisInitialized(_this), _handleKeydown$1, {
|
|
2147
|
+
writable: true,
|
|
2148
|
+
value: void 0
|
|
2149
|
+
});
|
|
1839
2150
|
_this.defaults = defaults$1;
|
|
1840
2151
|
_this.settings = _extends({}, _this.defaults, options);
|
|
1841
|
-
_this.
|
|
2152
|
+
_this.trigger = null;
|
|
1842
2153
|
_this.focusTrap = new FocusTrap(); // Setup a proxy for stack array.
|
|
1843
2154
|
|
|
1844
2155
|
_this.stack = new Proxy([], {
|
|
1845
2156
|
set: function set(target, property, value) {
|
|
1846
|
-
target[property] = value; // Update global state
|
|
2157
|
+
target[property] = value; // Update global state if stack length changed.
|
|
1847
2158
|
|
|
1848
2159
|
if (property === 'length') {
|
|
1849
|
-
updateGlobalState
|
|
2160
|
+
updateGlobalState(_this.active, _this.settings);
|
|
2161
|
+
updateStackIndex(_this.stack);
|
|
1850
2162
|
}
|
|
1851
2163
|
|
|
1852
2164
|
return true;
|
|
1853
2165
|
}
|
|
1854
2166
|
});
|
|
1855
|
-
_this
|
|
1856
|
-
_this
|
|
2167
|
+
_classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleClick)[_handleClick] = handleClick$1.bind(_assertThisInitialized(_this));
|
|
2168
|
+
_classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleKeydown$1)[_handleKeydown$1] = handleKeydown$1.bind(_assertThisInitialized(_this));
|
|
1857
2169
|
if (_this.settings.autoInit) _this.init();
|
|
1858
2170
|
return _this;
|
|
1859
2171
|
}
|
|
@@ -1870,10 +2182,13 @@
|
|
|
1870
2182
|
var modals = document.querySelectorAll(_this3.settings.selectorModal); // Register the collections array with modal instances.
|
|
1871
2183
|
|
|
1872
2184
|
return Promise.resolve(_this3.registerCollection(modals)).then(function () {
|
|
2185
|
+
// If eventListeners are enabled, init event listeners.
|
|
1873
2186
|
if (_this3.settings.eventListeners) {
|
|
1874
2187
|
_this3.initEventListeners();
|
|
1875
2188
|
}
|
|
1876
|
-
|
|
2189
|
+
|
|
2190
|
+
return _this3;
|
|
2191
|
+
});
|
|
1877
2192
|
} catch (e) {
|
|
1878
2193
|
return Promise.reject(e);
|
|
1879
2194
|
}
|
|
@@ -1883,35 +2198,38 @@
|
|
|
1883
2198
|
try {
|
|
1884
2199
|
var _this5 = this;
|
|
1885
2200
|
|
|
1886
|
-
// Clear
|
|
1887
|
-
_this5.
|
|
2201
|
+
// Clear stored trigger.
|
|
2202
|
+
_this5.trigger = null; // Remove all entries from the collection.
|
|
1888
2203
|
|
|
1889
2204
|
return Promise.resolve(_this5.deregisterCollection()).then(function () {
|
|
2205
|
+
// If eventListeners are enabled, destroy event listeners.
|
|
1890
2206
|
if (_this5.settings.eventListeners) {
|
|
1891
2207
|
_this5.destroyEventListeners();
|
|
1892
2208
|
}
|
|
1893
|
-
|
|
2209
|
+
|
|
2210
|
+
return _this5;
|
|
2211
|
+
});
|
|
1894
2212
|
} catch (e) {
|
|
1895
2213
|
return Promise.reject(e);
|
|
1896
2214
|
}
|
|
1897
2215
|
};
|
|
1898
2216
|
|
|
1899
2217
|
_proto.initEventListeners = function initEventListeners() {
|
|
1900
|
-
document.addEventListener('click', this
|
|
1901
|
-
document.addEventListener('touchend', this
|
|
1902
|
-
document.addEventListener('keydown', this
|
|
2218
|
+
document.addEventListener('click', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
|
|
2219
|
+
document.addEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
|
|
2220
|
+
document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$1)[_handleKeydown$1], false);
|
|
1903
2221
|
};
|
|
1904
2222
|
|
|
1905
2223
|
_proto.destroyEventListeners = function destroyEventListeners() {
|
|
1906
|
-
document.removeEventListener('click', this
|
|
1907
|
-
document.removeEventListener('touchend', this
|
|
1908
|
-
document.removeEventListener('keydown', this
|
|
2224
|
+
document.removeEventListener('click', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
|
|
2225
|
+
document.removeEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
|
|
2226
|
+
document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$1)[_handleKeydown$1], false);
|
|
1909
2227
|
};
|
|
1910
2228
|
|
|
1911
2229
|
_proto.register = function register(query) {
|
|
1912
2230
|
var els = getModalElements.call(this, query);
|
|
1913
2231
|
if (els.error) return Promise.reject(els.error);
|
|
1914
|
-
return register$1.call(this, els.
|
|
2232
|
+
return register$1.call(this, els.modal, els.dialog);
|
|
1915
2233
|
};
|
|
1916
2234
|
|
|
1917
2235
|
_proto.deregister = function deregister(query) {
|
|
@@ -1919,28 +2237,36 @@
|
|
|
1919
2237
|
return deregister$1.call(this, modal);
|
|
1920
2238
|
};
|
|
1921
2239
|
|
|
1922
|
-
_proto.open = function open(id, transition) {
|
|
1923
|
-
return open$1.call(this, id, transition);
|
|
2240
|
+
_proto.open = function open(id, transition, focus) {
|
|
2241
|
+
return open$1.call(this, id, transition, focus);
|
|
1924
2242
|
};
|
|
1925
2243
|
|
|
1926
|
-
_proto.close = function close(id, transition) {
|
|
1927
|
-
return close$1.call(this, id, transition);
|
|
2244
|
+
_proto.close = function close(id, transition, focus) {
|
|
2245
|
+
return close$1.call(this, id, transition, focus);
|
|
1928
2246
|
};
|
|
1929
2247
|
|
|
1930
|
-
_proto.replace = function replace$1(id, transition) {
|
|
1931
|
-
return replace.call(this, id, transition);
|
|
2248
|
+
_proto.replace = function replace$1(id, transition, focus) {
|
|
2249
|
+
return replace.call(this, id, transition, focus);
|
|
1932
2250
|
};
|
|
1933
2251
|
|
|
1934
|
-
_proto.closeAll = function closeAll(exclude, transition) {
|
|
2252
|
+
_proto.closeAll = function closeAll(exclude, transition, focus) {
|
|
1935
2253
|
if (exclude === void 0) {
|
|
1936
2254
|
exclude = false;
|
|
1937
2255
|
}
|
|
1938
2256
|
|
|
2257
|
+
if (focus === void 0) {
|
|
2258
|
+
focus = true;
|
|
2259
|
+
}
|
|
2260
|
+
|
|
1939
2261
|
try {
|
|
1940
2262
|
var _this7 = this;
|
|
1941
2263
|
|
|
1942
2264
|
return Promise.resolve(closeAll$1.call(_this7, exclude, transition)).then(function (result) {
|
|
1943
|
-
|
|
2265
|
+
// Update focus if the focus param is true.
|
|
2266
|
+
if (focus) {
|
|
2267
|
+
updateFocusState.call(_this7);
|
|
2268
|
+
}
|
|
2269
|
+
|
|
1944
2270
|
return result;
|
|
1945
2271
|
});
|
|
1946
2272
|
} catch (e) {
|
|
@@ -1987,7 +2313,7 @@
|
|
|
1987
2313
|
|
|
1988
2314
|
for (var prop in config) {
|
|
1989
2315
|
// Get the CSS variable property values.
|
|
1990
|
-
var prefix =
|
|
2316
|
+
var prefix = L();
|
|
1991
2317
|
var value = styles.getPropertyValue("--" + prefix + "popover-" + prop).trim(); // If a value was found, replace the default in config obj.
|
|
1992
2318
|
|
|
1993
2319
|
if (value) {
|
|
@@ -1998,6 +2324,7 @@
|
|
|
1998
2324
|
|
|
1999
2325
|
return config;
|
|
2000
2326
|
}
|
|
2327
|
+
|
|
2001
2328
|
function getPadding(value) {
|
|
2002
2329
|
var padding; // Split the value by spaces if it's a string.
|
|
2003
2330
|
|
|
@@ -2047,6 +2374,7 @@
|
|
|
2047
2374
|
|
|
2048
2375
|
return padding;
|
|
2049
2376
|
}
|
|
2377
|
+
|
|
2050
2378
|
function getModifiers(options) {
|
|
2051
2379
|
return [{
|
|
2052
2380
|
name: 'offset',
|
|
@@ -2071,6 +2399,7 @@
|
|
|
2071
2399
|
}
|
|
2072
2400
|
}];
|
|
2073
2401
|
}
|
|
2402
|
+
|
|
2074
2403
|
function getPopover(query) {
|
|
2075
2404
|
// Get the entry from collection.
|
|
2076
2405
|
var entry = typeof query === 'string' ? this.get(query) : this.get(query.id); // Return entry if it was resolved, otherwise throw error.
|
|
@@ -2081,13 +2410,14 @@
|
|
|
2081
2410
|
throw new Error("Popover not found in collection with id of \"" + query + "\".");
|
|
2082
2411
|
}
|
|
2083
2412
|
}
|
|
2413
|
+
|
|
2084
2414
|
function getPopoverID(obj) {
|
|
2085
2415
|
// If it's a string, return the string.
|
|
2086
2416
|
if (typeof obj === 'string') {
|
|
2087
2417
|
return obj;
|
|
2088
2418
|
} // If it's an HTML element.
|
|
2089
2419
|
else if (typeof obj.hasAttribute === 'function') {
|
|
2090
|
-
// If it's a popover
|
|
2420
|
+
// If it's a popover element, return the id.
|
|
2091
2421
|
if (obj.closest(this.settings.selectorPopover)) {
|
|
2092
2422
|
obj = obj.closest(this.settings.selectorPopover);
|
|
2093
2423
|
return obj.id;
|
|
@@ -2105,14 +2435,15 @@
|
|
|
2105
2435
|
} // Return false if no id was found.
|
|
2106
2436
|
else return false;
|
|
2107
2437
|
}
|
|
2438
|
+
|
|
2108
2439
|
function getPopoverElements(query) {
|
|
2109
2440
|
var id = getPopoverID.call(this, query);
|
|
2110
2441
|
|
|
2111
2442
|
if (id) {
|
|
2443
|
+
var popover = document.querySelector("#" + id);
|
|
2112
2444
|
var trigger = document.querySelector("[aria-controls=\"" + id + "\"]") || document.querySelector("[aria-describedby=\"" + id + "\"]");
|
|
2113
|
-
var target = document.querySelector("#" + id);
|
|
2114
2445
|
|
|
2115
|
-
if (!trigger && !
|
|
2446
|
+
if (!trigger && !popover) {
|
|
2116
2447
|
return {
|
|
2117
2448
|
error: new Error("No popover elements found using the ID: \"" + id + "\".")
|
|
2118
2449
|
};
|
|
@@ -2120,14 +2451,14 @@
|
|
|
2120
2451
|
return {
|
|
2121
2452
|
error: new Error('No popover trigger associated with the provided popover.')
|
|
2122
2453
|
};
|
|
2123
|
-
} else if (!
|
|
2454
|
+
} else if (!popover) {
|
|
2124
2455
|
return {
|
|
2125
2456
|
error: new Error('No popover associated with the provided popover trigger.')
|
|
2126
2457
|
};
|
|
2127
2458
|
} else {
|
|
2128
2459
|
return {
|
|
2129
|
-
|
|
2130
|
-
|
|
2460
|
+
popover: popover,
|
|
2461
|
+
trigger: trigger
|
|
2131
2462
|
};
|
|
2132
2463
|
}
|
|
2133
2464
|
} else {
|
|
@@ -2170,7 +2501,7 @@
|
|
|
2170
2501
|
// If a modal exists and its state is opened.
|
|
2171
2502
|
if (popover && popover.state === 'opened') {
|
|
2172
2503
|
// Update state class.
|
|
2173
|
-
popover.
|
|
2504
|
+
popover.el.classList.remove(_this2.settings.stateActive); // Update accessibility attribute(s).
|
|
2174
2505
|
|
|
2175
2506
|
if (popover.trigger.hasAttribute('aria-controls')) {
|
|
2176
2507
|
popover.trigger.setAttribute('aria-expanded', 'false');
|
|
@@ -2184,10 +2515,10 @@
|
|
|
2184
2515
|
}]
|
|
2185
2516
|
}); // Update popover state.
|
|
2186
2517
|
|
|
2187
|
-
popover.state = 'closed'; // Clear
|
|
2518
|
+
popover.state = 'closed'; // Clear root trigger if popover trigger matches.
|
|
2188
2519
|
|
|
2189
|
-
if (popover.trigger === _this2.
|
|
2190
|
-
_this2.
|
|
2520
|
+
if (popover.trigger === _this2.trigger) {
|
|
2521
|
+
_this2.trigger = null;
|
|
2191
2522
|
}
|
|
2192
2523
|
} // Return the popover.
|
|
2193
2524
|
|
|
@@ -2208,10 +2539,10 @@
|
|
|
2208
2539
|
if (popover.state != 'opened') return; // Needed to correctly check which element is currently being focused.
|
|
2209
2540
|
|
|
2210
2541
|
setTimeout(function () {
|
|
2211
|
-
// Check if trigger or
|
|
2212
|
-
var isHovered = popover.
|
|
2542
|
+
// Check if trigger or element are being hovered.
|
|
2543
|
+
var isHovered = popover.el.closest(':hover') === popover.el || popover.trigger.closest(':hover') === popover.trigger; // Check if trigger or element are being focused.
|
|
2213
2544
|
|
|
2214
|
-
var isFocused = document.activeElement.closest("#" + popover.id + ", [aria-controls=\"" + popover.id + "\"]"); // Close if the trigger and
|
|
2545
|
+
var isFocused = document.activeElement.closest("#" + popover.id + ", [aria-controls=\"" + popover.id + "\"]"); // Close if the trigger and element are not currently hovered or focused.
|
|
2215
2546
|
|
|
2216
2547
|
if (!isHovered && !isFocused) {
|
|
2217
2548
|
popover.close();
|
|
@@ -2222,22 +2553,22 @@
|
|
|
2222
2553
|
}, 1);
|
|
2223
2554
|
}
|
|
2224
2555
|
|
|
2225
|
-
function
|
|
2556
|
+
function handleClick(popover) {
|
|
2226
2557
|
if (popover.state === 'opened') {
|
|
2227
2558
|
popover.close();
|
|
2228
2559
|
} else {
|
|
2229
|
-
this.
|
|
2560
|
+
this.trigger = popover.trigger;
|
|
2230
2561
|
popover.open();
|
|
2231
|
-
|
|
2562
|
+
handleDocumentClick.call(this, popover);
|
|
2232
2563
|
}
|
|
2233
2564
|
}
|
|
2234
|
-
function
|
|
2565
|
+
function handleKeydown(event) {
|
|
2235
2566
|
var _this = this;
|
|
2236
2567
|
|
|
2237
2568
|
switch (event.key) {
|
|
2238
2569
|
case 'Escape':
|
|
2239
|
-
if (this.
|
|
2240
|
-
this.
|
|
2570
|
+
if (this.trigger) {
|
|
2571
|
+
this.trigger.focus();
|
|
2241
2572
|
}
|
|
2242
2573
|
|
|
2243
2574
|
closeAll.call(this);
|
|
@@ -2253,7 +2584,7 @@
|
|
|
2253
2584
|
return;
|
|
2254
2585
|
}
|
|
2255
2586
|
}
|
|
2256
|
-
function
|
|
2587
|
+
function handleDocumentClick(popover) {
|
|
2257
2588
|
var root = this;
|
|
2258
2589
|
document.addEventListener('click', function _f(event) {
|
|
2259
2590
|
// Check if a popover was clicked.
|
|
@@ -2261,14 +2592,14 @@
|
|
|
2261
2592
|
|
|
2262
2593
|
if (!result) {
|
|
2263
2594
|
// If it doesn't match and popover is open, close it and remove event listener.
|
|
2264
|
-
if (popover.
|
|
2595
|
+
if (popover.el && popover.el.classList.contains(root.settings.stateActive)) {
|
|
2265
2596
|
popover.close();
|
|
2266
2597
|
}
|
|
2267
2598
|
|
|
2268
2599
|
this.removeEventListener('click', _f);
|
|
2269
2600
|
} else {
|
|
2270
2601
|
// If it does match and popover isn't currently active, remove event listener.
|
|
2271
|
-
if (popover.
|
|
2602
|
+
if (popover.el && !popover.el.classList.contains(root.settings.stateActive)) {
|
|
2272
2603
|
this.removeEventListener('click', _f);
|
|
2273
2604
|
}
|
|
2274
2605
|
}
|
|
@@ -4126,14 +4457,14 @@
|
|
|
4126
4457
|
// Get the popover from collection.
|
|
4127
4458
|
var popover = getPopover.call(_this2, query); // Update state class.
|
|
4128
4459
|
|
|
4129
|
-
popover.
|
|
4460
|
+
popover.el.classList.add(_this2.settings.stateActive); // Update accessibility attribute(s).
|
|
4130
4461
|
|
|
4131
4462
|
if (popover.trigger.hasAttribute('aria-controls')) {
|
|
4132
4463
|
popover.trigger.setAttribute('aria-expanded', 'true');
|
|
4133
4464
|
} // Update popover config.
|
|
4134
4465
|
|
|
4135
4466
|
|
|
4136
|
-
popover.config = getConfig(popover.
|
|
4467
|
+
popover.config = getConfig(popover.el, _this2.settings); // Enable popper event listeners and set placement/modifiers.
|
|
4137
4468
|
|
|
4138
4469
|
popover.popper.setOptions({
|
|
4139
4470
|
placement: popover.config['placement'],
|
|
@@ -4153,12 +4484,12 @@
|
|
|
4153
4484
|
}
|
|
4154
4485
|
};
|
|
4155
4486
|
|
|
4156
|
-
var register = function register(
|
|
4487
|
+
var register = function register(el, trigger) {
|
|
4157
4488
|
try {
|
|
4158
4489
|
var _this2 = this;
|
|
4159
4490
|
|
|
4160
4491
|
// Deregister entry incase it has already been registered.
|
|
4161
|
-
deregister.call(_this2,
|
|
4492
|
+
deregister.call(_this2, el); // Save root this for use inside methods API.
|
|
4162
4493
|
|
|
4163
4494
|
|
|
4164
4495
|
var root = _this2; // Setup methods API.
|
|
@@ -4176,12 +4507,12 @@
|
|
|
4176
4507
|
}; // Setup the popover object.
|
|
4177
4508
|
|
|
4178
4509
|
var entry = _extends({
|
|
4179
|
-
id:
|
|
4510
|
+
id: el.id,
|
|
4180
4511
|
state: 'closed',
|
|
4512
|
+
el: el,
|
|
4181
4513
|
trigger: trigger,
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
config: getConfig(target, _this2.settings)
|
|
4514
|
+
popper: createPopper(trigger, el),
|
|
4515
|
+
config: getConfig(el, _this2.settings)
|
|
4185
4516
|
}, methods); // Set aria-expanded to false if trigger has aria-controls attribute.
|
|
4186
4517
|
|
|
4187
4518
|
|
|
@@ -4196,9 +4527,9 @@
|
|
|
4196
4527
|
|
|
4197
4528
|
|
|
4198
4529
|
var _temp2 = function () {
|
|
4199
|
-
if (entry.
|
|
4530
|
+
if (entry.el.classList.contains(_this2.settings.stateActive)) {
|
|
4200
4531
|
return Promise.resolve(entry.open()).then(function () {
|
|
4201
|
-
|
|
4532
|
+
handleDocumentClick.call(_this2, entry);
|
|
4202
4533
|
});
|
|
4203
4534
|
}
|
|
4204
4535
|
}();
|
|
@@ -4224,7 +4555,7 @@
|
|
|
4224
4555
|
type: ['mouseenter', 'focus'],
|
|
4225
4556
|
listener: open.bind(this, entry)
|
|
4226
4557
|
}, {
|
|
4227
|
-
el: ['
|
|
4558
|
+
el: ['el', 'trigger'],
|
|
4228
4559
|
type: ['mouseleave', 'focusout'],
|
|
4229
4560
|
listener: closeCheck.bind(this, entry)
|
|
4230
4561
|
}]; // Loop through listeners and apply to the appropriate elements.
|
|
@@ -4242,7 +4573,7 @@
|
|
|
4242
4573
|
entry.__eventListeners = [{
|
|
4243
4574
|
el: ['trigger'],
|
|
4244
4575
|
type: ['click'],
|
|
4245
|
-
listener:
|
|
4576
|
+
listener: handleClick.bind(this, entry)
|
|
4246
4577
|
}]; // Loop through listeners and apply to the appropriate elements.
|
|
4247
4578
|
|
|
4248
4579
|
entry.__eventListeners.forEach(function (evObj) {
|
|
@@ -4259,6 +4590,8 @@
|
|
|
4259
4590
|
return entry;
|
|
4260
4591
|
}
|
|
4261
4592
|
|
|
4593
|
+
var _handleKeydown = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
|
|
4594
|
+
|
|
4262
4595
|
var Popover = /*#__PURE__*/function (_Collection) {
|
|
4263
4596
|
_inheritsLoose(Popover, _Collection);
|
|
4264
4597
|
|
|
@@ -4266,10 +4599,14 @@
|
|
|
4266
4599
|
var _this;
|
|
4267
4600
|
|
|
4268
4601
|
_this = _Collection.call(this) || this;
|
|
4602
|
+
Object.defineProperty(_assertThisInitialized(_this), _handleKeydown, {
|
|
4603
|
+
writable: true,
|
|
4604
|
+
value: void 0
|
|
4605
|
+
});
|
|
4269
4606
|
_this.defaults = defaults;
|
|
4270
4607
|
_this.settings = _extends({}, _this.defaults, options);
|
|
4271
|
-
_this.
|
|
4272
|
-
_this
|
|
4608
|
+
_this.trigger = null;
|
|
4609
|
+
_classPrivateFieldLooseBase(_assertThisInitialized(_this), _handleKeydown)[_handleKeydown] = handleKeydown.bind(_assertThisInitialized(_this));
|
|
4273
4610
|
if (_this.settings.autoInit) _this.init();
|
|
4274
4611
|
return _this;
|
|
4275
4612
|
}
|
|
@@ -4286,12 +4623,15 @@
|
|
|
4286
4623
|
var popovers = document.querySelectorAll(_this3.settings.selectorPopover); // Register the collections array with popover instances.
|
|
4287
4624
|
|
|
4288
4625
|
return Promise.resolve(_this3.registerCollection(popovers)).then(function () {
|
|
4626
|
+
// If eventListeners are enabled, init event listeners.
|
|
4289
4627
|
if (_this3.settings.eventListeners) {
|
|
4290
4628
|
// Pass false to initEventListeners() since registerCollection()
|
|
4291
4629
|
// already adds event listeners to popovers.
|
|
4292
4630
|
_this3.initEventListeners(false);
|
|
4293
4631
|
}
|
|
4294
|
-
|
|
4632
|
+
|
|
4633
|
+
return _this3;
|
|
4634
|
+
});
|
|
4295
4635
|
} catch (e) {
|
|
4296
4636
|
return Promise.reject(e);
|
|
4297
4637
|
}
|
|
@@ -4301,16 +4641,19 @@
|
|
|
4301
4641
|
try {
|
|
4302
4642
|
var _this5 = this;
|
|
4303
4643
|
|
|
4304
|
-
// Clear
|
|
4305
|
-
_this5.
|
|
4644
|
+
// Clear stored trigger.
|
|
4645
|
+
_this5.trigger = null; // Remove all entries from the collection.
|
|
4306
4646
|
|
|
4307
4647
|
return Promise.resolve(_this5.deregisterCollection()).then(function () {
|
|
4648
|
+
// If eventListeners are enabled, destroy event listeners.
|
|
4308
4649
|
if (_this5.settings.eventListeners) {
|
|
4309
4650
|
// Pass false to destroyEventListeners() since deregisterCollection()
|
|
4310
4651
|
// already removes event listeners from popovers.
|
|
4311
4652
|
_this5.destroyEventListeners(false);
|
|
4312
4653
|
}
|
|
4313
|
-
|
|
4654
|
+
|
|
4655
|
+
return _this5;
|
|
4656
|
+
});
|
|
4314
4657
|
} catch (e) {
|
|
4315
4658
|
return Promise.reject(e);
|
|
4316
4659
|
}
|
|
@@ -4331,7 +4674,7 @@
|
|
|
4331
4674
|
} // Add keydown global event listener.
|
|
4332
4675
|
|
|
4333
4676
|
|
|
4334
|
-
document.addEventListener('keydown', this
|
|
4677
|
+
document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown)[_handleKeydown], false);
|
|
4335
4678
|
};
|
|
4336
4679
|
|
|
4337
4680
|
_proto.destroyEventListeners = function destroyEventListeners(processCollection) {
|
|
@@ -4347,13 +4690,13 @@
|
|
|
4347
4690
|
} // Remove keydown global event listener.
|
|
4348
4691
|
|
|
4349
4692
|
|
|
4350
|
-
document.removeEventListener('keydown', this
|
|
4693
|
+
document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown)[_handleKeydown], false);
|
|
4351
4694
|
};
|
|
4352
4695
|
|
|
4353
4696
|
_proto.register = function register$1(query) {
|
|
4354
4697
|
var els = getPopoverElements.call(this, query);
|
|
4355
4698
|
if (els.error) return Promise.reject(els.error);
|
|
4356
|
-
return register.call(this, els.
|
|
4699
|
+
return register.call(this, els.popover, els.trigger);
|
|
4357
4700
|
};
|
|
4358
4701
|
|
|
4359
4702
|
_proto.deregister = function deregister$1(query) {
|