vrembem 1.40.2 → 1.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dev/scripts.esm.js +310 -219
- package/dev/scripts.esm.js.map +1 -1
- package/dev/scripts.js +310 -219
- package/dev/scripts.js.map +1 -1
- package/dev/scripts.modern.js +269 -198
- package/dev/scripts.modern.js.map +1 -1
- package/dev/scripts.umd.js +310 -219
- package/dev/scripts.umd.js.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/package.json +26 -26
package/dev/scripts.esm.js
CHANGED
|
@@ -34,10 +34,9 @@ var setTabindex = function setTabindex(selector) {
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
* Adds a class or classes to
|
|
38
|
-
*
|
|
39
|
-
* @param
|
|
40
|
-
* @param {String || Array} cl - Class(es) to add
|
|
37
|
+
* Adds a class or classes to a Node or NodeList.
|
|
38
|
+
* @param {Node || NodeList} el - Element(s) to add class(es) to.
|
|
39
|
+
* @param {String || Array} cl - Class(es) to add.
|
|
41
40
|
*/
|
|
42
41
|
var addClass = function addClass(el) {
|
|
43
42
|
var _arguments = arguments;
|
|
@@ -50,10 +49,9 @@ var addClass = function addClass(el) {
|
|
|
50
49
|
};
|
|
51
50
|
|
|
52
51
|
/**
|
|
53
|
-
* Takes a hyphen cased string and converts it to camel case
|
|
54
|
-
*
|
|
55
|
-
* @
|
|
56
|
-
* @returns {Boolean} - returns a camel cased string
|
|
52
|
+
* Takes a hyphen cased string and converts it to camel case.
|
|
53
|
+
* @param {String } str - the string to convert to camel case.
|
|
54
|
+
* @returns {Boolean} - returns a camel cased string.
|
|
57
55
|
*/
|
|
58
56
|
var camelCase = function camelCase(str) {
|
|
59
57
|
return str.replace(/-([a-z])/g, function (g) {
|
|
@@ -179,27 +177,25 @@ var FocusTrap = /*#__PURE__*/function () {
|
|
|
179
177
|
}();
|
|
180
178
|
|
|
181
179
|
/**
|
|
182
|
-
* Get an element(s) from a selector or return value if not a string
|
|
183
|
-
*
|
|
184
|
-
* @param {
|
|
185
|
-
* @param {Boolean} single - Whether to return a single or all matches
|
|
180
|
+
* Get an element(s) from a selector or return value if not a string.
|
|
181
|
+
* @param {String} selector - Selector to query.
|
|
182
|
+
* @param {Boolean} single - Whether to return a single or all matches.
|
|
186
183
|
*/
|
|
187
184
|
var getElement = function getElement(selector, single) {
|
|
188
185
|
if (single === void 0) {
|
|
189
186
|
single = 0;
|
|
190
187
|
}
|
|
191
188
|
|
|
192
|
-
if (typeof selector
|
|
189
|
+
if (typeof selector !== 'string') return selector;
|
|
193
190
|
return single ? document.querySelector(selector) : document.querySelectorAll(selector);
|
|
194
191
|
};
|
|
195
192
|
|
|
196
193
|
/**
|
|
197
|
-
* Checks an element or NodeList whether they contain a class or classes
|
|
194
|
+
* Checks an element or NodeList whether they contain a class or classes.
|
|
198
195
|
* Ref: https://davidwalsh.name/nodelist-array
|
|
199
|
-
*
|
|
200
|
-
* @param {
|
|
201
|
-
* @
|
|
202
|
-
* @returns {Boolean} - Returns true if class exists, otherwise false
|
|
196
|
+
* @param {Node} el - Element(s) to check class(es) on.
|
|
197
|
+
* @param {String || Array} c - Class(es) to check.
|
|
198
|
+
* @returns {Boolean} - Returns true if class exists, otherwise false.
|
|
203
199
|
*/
|
|
204
200
|
var hasClass = function hasClass(el) {
|
|
205
201
|
el = el.forEach ? el : [el];
|
|
@@ -212,10 +208,9 @@ var hasClass = function hasClass(el) {
|
|
|
212
208
|
};
|
|
213
209
|
|
|
214
210
|
/**
|
|
215
|
-
* Takes a camel cased string and converts it to hyphen case
|
|
216
|
-
*
|
|
217
|
-
* @
|
|
218
|
-
* @returns {Boolean} - returns a hyphen cased string
|
|
211
|
+
* Takes a camel cased string and converts it to hyphen case.
|
|
212
|
+
* @param {String } str - the string to convert to hyphen case.
|
|
213
|
+
* @returns {Boolean} - returns a hyphen cased string.
|
|
219
214
|
*/
|
|
220
215
|
var hyphenCase = function hyphenCase(str) {
|
|
221
216
|
return str.replace(/([a-z][A-Z])/g, function (g) {
|
|
@@ -224,11 +219,10 @@ var hyphenCase = function hyphenCase(str) {
|
|
|
224
219
|
};
|
|
225
220
|
|
|
226
221
|
/**
|
|
227
|
-
* Moves element(s) in the DOM based on a reference and move type
|
|
228
|
-
*
|
|
229
|
-
* @param {String}
|
|
230
|
-
* @param {String}
|
|
231
|
-
* @param {String} reference - The reference element the move is relative to
|
|
222
|
+
* Moves element(s) in the DOM based on a reference and move type.
|
|
223
|
+
* @param {String} target - The element(s) to move.
|
|
224
|
+
* @param {String} type - Move type can be 'after', 'before', 'append' or 'prepend'.
|
|
225
|
+
* @param {String} reference - The reference element the move is relative to.
|
|
232
226
|
*/
|
|
233
227
|
|
|
234
228
|
function moveElement(target, type, reference) {
|
|
@@ -283,10 +277,9 @@ function moveElement(target, type, reference) {
|
|
|
283
277
|
}
|
|
284
278
|
|
|
285
279
|
/**
|
|
286
|
-
* Remove a class or classes from an element or NodeList
|
|
287
|
-
*
|
|
288
|
-
* @param {
|
|
289
|
-
* @param {String || Array} cl - Class(es) to remove
|
|
280
|
+
* Remove a class or classes from an element or NodeList.
|
|
281
|
+
* @param {Node || NodeList} el - Element(s) to remove class(es) from.
|
|
282
|
+
* @param {String || Array} cl - Class(es) to remove.
|
|
290
283
|
*/
|
|
291
284
|
var removeClass = function removeClass(el) {
|
|
292
285
|
var _arguments = arguments;
|
|
@@ -299,10 +292,9 @@ var removeClass = function removeClass(el) {
|
|
|
299
292
|
};
|
|
300
293
|
|
|
301
294
|
/**
|
|
302
|
-
* Toggle a class or classes on an element or NodeList
|
|
303
|
-
*
|
|
304
|
-
* @param {
|
|
305
|
-
* @param {String || Array} cl - Class(es) to toggle
|
|
295
|
+
* Toggle a class or classes on an element or NodeList.
|
|
296
|
+
* @param {Node || NodeList} el - Element(s) to toggle class(es) on.
|
|
297
|
+
* @param {String || Array} cl - Class(es) to toggle.
|
|
306
298
|
*/
|
|
307
299
|
var toggleClass = function toggleClass(el) {
|
|
308
300
|
var _arguments = arguments;
|
|
@@ -389,13 +381,39 @@ function _extends() {
|
|
|
389
381
|
return _extends.apply(this, arguments);
|
|
390
382
|
}
|
|
391
383
|
|
|
384
|
+
function _inheritsLoose(subClass, superClass) {
|
|
385
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
386
|
+
subClass.prototype.constructor = subClass;
|
|
387
|
+
|
|
388
|
+
_setPrototypeOf(subClass, superClass);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function _setPrototypeOf(o, p) {
|
|
392
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
393
|
+
o.__proto__ = p;
|
|
394
|
+
return o;
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
return _setPrototypeOf(o, p);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function _assertThisInitialized(self) {
|
|
401
|
+
if (self === void 0) {
|
|
402
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
return self;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
var defaults$3 = {
|
|
409
|
+
autoInit: false,
|
|
410
|
+
stateAttr: 'aria-checked',
|
|
411
|
+
stateValue: 'mixed'
|
|
412
|
+
};
|
|
413
|
+
|
|
392
414
|
var Checkbox = /*#__PURE__*/function () {
|
|
393
415
|
function Checkbox(options) {
|
|
394
|
-
this.defaults =
|
|
395
|
-
autoInit: false,
|
|
396
|
-
stateAttr: 'aria-checked',
|
|
397
|
-
stateValue: 'mixed'
|
|
398
|
-
};
|
|
416
|
+
this.defaults = defaults$3;
|
|
399
417
|
this.settings = _extends({}, this.defaults, options);
|
|
400
418
|
this.__handlerClick = this.handlerClick.bind(this);
|
|
401
419
|
if (this.settings.autoInit) this.init();
|
|
@@ -510,16 +528,23 @@ var Breakpoint = /*#__PURE__*/function () {
|
|
|
510
528
|
|
|
511
529
|
var drawers = document.querySelectorAll("[data-" + this.parent.settings.dataBreakpoint + "]");
|
|
512
530
|
drawers.forEach(function (drawer) {
|
|
531
|
+
// Setup mediaQueryList object
|
|
513
532
|
var id = drawer.getAttribute("data-" + _this.parent.settings.dataDrawer);
|
|
514
533
|
var key = drawer.getAttribute("data-" + _this.parent.settings.dataBreakpoint);
|
|
515
534
|
|
|
516
535
|
var bp = _this.getBreakpoint(key);
|
|
517
536
|
|
|
518
|
-
var mql = window.matchMedia('(min-width:' + bp + ')');
|
|
537
|
+
var mql = window.matchMedia('(min-width:' + bp + ')'); // Run match check
|
|
538
|
+
|
|
539
|
+
_this.match(mql, drawer); // Conditionally use addListner() for IE11 support
|
|
519
540
|
|
|
520
|
-
_this.match(mql, drawer);
|
|
521
541
|
|
|
522
|
-
mql.addEventListener
|
|
542
|
+
if (typeof mql.addEventListener === 'function') {
|
|
543
|
+
mql.addEventListener('change', _this.__check);
|
|
544
|
+
} else {
|
|
545
|
+
mql.addListener(_this.__check);
|
|
546
|
+
} // Push to mediaQueryLists array along with drawer ID
|
|
547
|
+
|
|
523
548
|
|
|
524
549
|
_this.mediaQueryLists.push({
|
|
525
550
|
'mql': mql,
|
|
@@ -1272,39 +1297,96 @@ var Modal = /*#__PURE__*/function () {
|
|
|
1272
1297
|
return Modal;
|
|
1273
1298
|
}();
|
|
1274
1299
|
|
|
1300
|
+
var Collection = /*#__PURE__*/function () {
|
|
1301
|
+
function Collection() {
|
|
1302
|
+
this.collection = [];
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
var _proto = Collection.prototype;
|
|
1306
|
+
|
|
1307
|
+
_proto.register = function register(item) {
|
|
1308
|
+
this.deregister(item);
|
|
1309
|
+
this.collection.push(item);
|
|
1310
|
+
return this.collection;
|
|
1311
|
+
};
|
|
1312
|
+
|
|
1313
|
+
_proto.deregister = function deregister(ref) {
|
|
1314
|
+
var index = this.collection.findIndex(function (entry) {
|
|
1315
|
+
return entry === ref;
|
|
1316
|
+
});
|
|
1317
|
+
|
|
1318
|
+
if (index >= 0) {
|
|
1319
|
+
var entry = this.collection[index];
|
|
1320
|
+
Object.getOwnPropertyNames(entry).forEach(function (prop) {
|
|
1321
|
+
delete entry[prop];
|
|
1322
|
+
});
|
|
1323
|
+
this.collection.splice(index, 1);
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
return this.collection;
|
|
1327
|
+
};
|
|
1328
|
+
|
|
1329
|
+
_proto.registerCollection = function registerCollection(items) {
|
|
1330
|
+
var _this = this;
|
|
1331
|
+
|
|
1332
|
+
items.forEach(function (item) {
|
|
1333
|
+
_this.register(item);
|
|
1334
|
+
});
|
|
1335
|
+
return this.collection;
|
|
1336
|
+
};
|
|
1337
|
+
|
|
1338
|
+
_proto.deregisterCollection = function deregisterCollection() {
|
|
1339
|
+
while (this.collection.length > 0) {
|
|
1340
|
+
this.deregister(this.collection[0]);
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
return this.collection;
|
|
1344
|
+
};
|
|
1345
|
+
|
|
1346
|
+
_proto.get = function get(query, key) {
|
|
1347
|
+
if (key === void 0) {
|
|
1348
|
+
key = 'id';
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
var result = this.collection.find(function (item) {
|
|
1352
|
+
return item[key] === query;
|
|
1353
|
+
});
|
|
1354
|
+
return result || null;
|
|
1355
|
+
};
|
|
1356
|
+
|
|
1357
|
+
return Collection;
|
|
1358
|
+
}();
|
|
1359
|
+
|
|
1275
1360
|
var defaults = {
|
|
1276
1361
|
autoInit: false,
|
|
1277
|
-
//
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
dataArrow: 'popover-arrow',
|
|
1281
|
-
dataEventType: 'popover-event',
|
|
1282
|
-
dataPlacement: 'popover-placement',
|
|
1362
|
+
// Selectors
|
|
1363
|
+
selectorPopover: '.popover',
|
|
1364
|
+
selectorArrow: '.popover__arrow',
|
|
1283
1365
|
// State classes
|
|
1284
1366
|
stateActive: 'is-active',
|
|
1285
1367
|
// Feature toggles
|
|
1286
|
-
eventType: 'click',
|
|
1287
1368
|
eventListeners: true,
|
|
1288
|
-
|
|
1369
|
+
eventType: 'click',
|
|
1370
|
+
placement: 'bottom'
|
|
1289
1371
|
};
|
|
1290
1372
|
|
|
1291
1373
|
function close(popover) {
|
|
1292
1374
|
// Update state class
|
|
1293
1375
|
popover.target.classList.remove(this.settings.stateActive); // Update a11y attributes
|
|
1294
1376
|
|
|
1295
|
-
popover.trigger.
|
|
1377
|
+
if (popover.trigger.hasAttribute('aria-controls')) {
|
|
1378
|
+
popover.trigger.setAttribute('aria-expanded', 'false');
|
|
1379
|
+
} // Disable popper event listeners
|
|
1380
|
+
|
|
1296
1381
|
|
|
1297
1382
|
popover.popper.setOptions({
|
|
1298
1383
|
modifiers: [{
|
|
1299
1384
|
name: 'eventListeners',
|
|
1300
1385
|
enabled: false
|
|
1301
1386
|
}]
|
|
1302
|
-
}); // Update
|
|
1387
|
+
}); // Update popover state
|
|
1303
1388
|
|
|
1304
|
-
|
|
1305
|
-
return item.target === popover.target;
|
|
1306
|
-
});
|
|
1307
|
-
this.collection[index].state = 'closed'; // Clear the memory if popover trigger matches the ones saved in memory
|
|
1389
|
+
popover.state = 'closed'; // Clear memory if popover trigger matches the one saved in memory
|
|
1308
1390
|
|
|
1309
1391
|
if (popover.trigger === this.memory.trigger) {
|
|
1310
1392
|
this.memory.trigger = null;
|
|
@@ -1314,19 +1396,15 @@ function close(popover) {
|
|
|
1314
1396
|
return popover;
|
|
1315
1397
|
}
|
|
1316
1398
|
function closeAll() {
|
|
1317
|
-
var _this = this;
|
|
1318
|
-
|
|
1319
1399
|
this.collection.forEach(function (popover) {
|
|
1320
1400
|
if (popover.state === 'opened') {
|
|
1321
|
-
|
|
1401
|
+
popover.close();
|
|
1322
1402
|
}
|
|
1323
1403
|
}); // Return the collection
|
|
1324
1404
|
|
|
1325
1405
|
return this.collection;
|
|
1326
1406
|
}
|
|
1327
1407
|
function closeCheck(popover) {
|
|
1328
|
-
var _this2 = this;
|
|
1329
|
-
|
|
1330
1408
|
// Only run closeCheck if provided popover is currently open
|
|
1331
1409
|
if (popover.state != 'opened') return; // Needed to correctly check which element is currently being focused
|
|
1332
1410
|
|
|
@@ -1334,10 +1412,10 @@ function closeCheck(popover) {
|
|
|
1334
1412
|
// Check if trigger or target are being hovered
|
|
1335
1413
|
var isHovered = popover.target.closest(':hover') === popover.target || popover.trigger.closest(':hover') === popover.trigger; // Check if trigger or target are being focused
|
|
1336
1414
|
|
|
1337
|
-
var isFocused = document.activeElement.closest("
|
|
1415
|
+
var isFocused = document.activeElement.closest("#" + popover.id + ", [aria-controls=\"" + popover.id + "\"]"); // Close if the trigger and target are not currently hovered or focused
|
|
1338
1416
|
|
|
1339
1417
|
if (!isHovered && !isFocused) {
|
|
1340
|
-
|
|
1418
|
+
popover.close();
|
|
1341
1419
|
} // Return the popover
|
|
1342
1420
|
|
|
1343
1421
|
|
|
@@ -1347,10 +1425,10 @@ function closeCheck(popover) {
|
|
|
1347
1425
|
|
|
1348
1426
|
function handlerClick(popover) {
|
|
1349
1427
|
if (popover.target.classList.contains(this.settings.stateActive)) {
|
|
1350
|
-
|
|
1428
|
+
popover.close();
|
|
1351
1429
|
} else {
|
|
1352
1430
|
this.memory.trigger = popover.trigger;
|
|
1353
|
-
|
|
1431
|
+
popover.open();
|
|
1354
1432
|
documentClick.call(this, popover);
|
|
1355
1433
|
}
|
|
1356
1434
|
}
|
|
@@ -1363,7 +1441,7 @@ function handlerKeydown(event) {
|
|
|
1363
1441
|
this.memory.trigger.focus();
|
|
1364
1442
|
}
|
|
1365
1443
|
|
|
1366
|
-
|
|
1444
|
+
closeAll.call(this);
|
|
1367
1445
|
return;
|
|
1368
1446
|
|
|
1369
1447
|
case 'Tab':
|
|
@@ -1377,19 +1455,21 @@ function handlerKeydown(event) {
|
|
|
1377
1455
|
}
|
|
1378
1456
|
}
|
|
1379
1457
|
function documentClick(popover) {
|
|
1380
|
-
var
|
|
1458
|
+
var root = this;
|
|
1381
1459
|
document.addEventListener('click', function _f(event) {
|
|
1382
|
-
|
|
1383
|
-
var
|
|
1460
|
+
// Check if a popover was clicked
|
|
1461
|
+
var result = event.target.closest("#" + popover.id + ", [aria-controls=\"" + popover.id + "\"]");
|
|
1384
1462
|
|
|
1385
|
-
if (!
|
|
1386
|
-
|
|
1387
|
-
|
|
1463
|
+
if (!result) {
|
|
1464
|
+
// If it doesn't match and popover is open, close it and remove event listener
|
|
1465
|
+
if (popover.target && popover.target.classList.contains(root.settings.stateActive)) {
|
|
1466
|
+
popover.close();
|
|
1388
1467
|
}
|
|
1389
1468
|
|
|
1390
1469
|
this.removeEventListener('click', _f);
|
|
1391
1470
|
} else {
|
|
1392
|
-
|
|
1471
|
+
// If it does match and popover isn't currently active, remove event listener
|
|
1472
|
+
if (popover.target && !popover.target.classList.contains(root.settings.stateActive)) {
|
|
1393
1473
|
this.removeEventListener('click', _f);
|
|
1394
1474
|
}
|
|
1395
1475
|
}
|
|
@@ -1406,30 +1486,23 @@ function getConfig(el, settings) {
|
|
|
1406
1486
|
'offset': 0,
|
|
1407
1487
|
'overflow-padding': 0,
|
|
1408
1488
|
'flip-padding': 0,
|
|
1409
|
-
'arrow-element':
|
|
1489
|
+
'arrow-element': settings.selectorArrow,
|
|
1410
1490
|
'arrow-padding': 0
|
|
1411
1491
|
}; // Loop through config obj
|
|
1412
1492
|
|
|
1413
1493
|
for (var prop in config) {
|
|
1414
1494
|
// Get the CSS variable property values
|
|
1415
1495
|
var prefix = getComputedStyle(document.body).getPropertyValue('--vrembem-variable-prefix');
|
|
1416
|
-
var
|
|
1496
|
+
var value = styles.getPropertyValue("--" + prefix + "popover-" + prop).trim(); // If a value was found, replace the default in config obj
|
|
1417
1497
|
|
|
1418
|
-
if (
|
|
1419
|
-
config[prop] =
|
|
1498
|
+
if (value) {
|
|
1499
|
+
config[prop] = value;
|
|
1420
1500
|
}
|
|
1421
1501
|
} // Return the config obj
|
|
1422
1502
|
|
|
1423
1503
|
|
|
1424
1504
|
return config;
|
|
1425
1505
|
}
|
|
1426
|
-
function getData(el, attr, fallback) {
|
|
1427
|
-
if (fallback === void 0) {
|
|
1428
|
-
fallback = false;
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1431
|
-
return el.hasAttribute("data-" + attr) ? el.getAttribute("data-" + attr) : fallback;
|
|
1432
|
-
}
|
|
1433
1506
|
function getPadding(value) {
|
|
1434
1507
|
var padding; // Split the value by spaces if it's a string
|
|
1435
1508
|
|
|
@@ -1503,47 +1576,56 @@ function getModifiers(options) {
|
|
|
1503
1576
|
}
|
|
1504
1577
|
}];
|
|
1505
1578
|
}
|
|
1506
|
-
function
|
|
1507
|
-
//
|
|
1508
|
-
|
|
1579
|
+
function getPopoverID(obj) {
|
|
1580
|
+
// If it's a string
|
|
1581
|
+
if (typeof obj === 'string') {
|
|
1582
|
+
return obj;
|
|
1583
|
+
} // If it's an HTML element
|
|
1584
|
+
else if (typeof obj.hasAttribute === 'function') {
|
|
1585
|
+
// If it's a popover trigger
|
|
1586
|
+
if (obj.hasAttribute('aria-controls')) {
|
|
1587
|
+
return obj.getAttribute('aria-controls');
|
|
1588
|
+
} // If it's a popover tooltip trigger
|
|
1589
|
+
else if (obj.hasAttribute('aria-describedby')) {
|
|
1590
|
+
return obj.getAttribute('aria-describedby');
|
|
1591
|
+
} // If it's a popover target
|
|
1592
|
+
else if (obj.closest(this.settings.selectorPopover)) {
|
|
1593
|
+
return obj.id;
|
|
1594
|
+
} // Return false if no id was found
|
|
1595
|
+
else return false;
|
|
1596
|
+
} // If it has an ID property
|
|
1597
|
+
else if (obj.id) {
|
|
1598
|
+
return obj.id;
|
|
1599
|
+
} // Return false if no id was found
|
|
1600
|
+
else return false;
|
|
1601
|
+
}
|
|
1602
|
+
function getPopoverElements(query) {
|
|
1603
|
+
var id = getPopoverID.call(this, query);
|
|
1509
1604
|
|
|
1510
1605
|
if (id) {
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
return document.querySelector("[data-" + settings.dataPopover + "=\"" + id + "\"]");
|
|
1514
|
-
} else {
|
|
1515
|
-
// If trigger attribute value doesn't exist, check if
|
|
1516
|
-
// - There is a nextElementSibling relative to the trigger
|
|
1517
|
-
// - And it has the popover data attribute.
|
|
1518
|
-
return trigger.nextElementSibling && trigger.nextElementSibling.hasAttribute("data-" + settings.dataPopover) ? // Return the element or false if the two checks fail
|
|
1519
|
-
trigger.nextElementSibling : false;
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1522
|
-
|
|
1523
|
-
function open(popover) {
|
|
1524
|
-
// Update state class
|
|
1525
|
-
popover.target.classList.add(this.settings.stateActive); // Update a11y attributes
|
|
1526
|
-
|
|
1527
|
-
popover.trigger.setAttribute('aria-expanded', 'true'); // Update popover config
|
|
1528
|
-
|
|
1529
|
-
popover.config = getConfig(popover.target, this.settings); // Enable popper event listeners and set placement/modifiers
|
|
1530
|
-
|
|
1531
|
-
popover.popper.setOptions({
|
|
1532
|
-
placement: getData(popover.target, this.settings.dataPlacement, popover.config['placement']),
|
|
1533
|
-
modifiers: [{
|
|
1534
|
-
name: 'eventListeners',
|
|
1535
|
-
enabled: true
|
|
1536
|
-
}].concat(getModifiers(popover.config))
|
|
1537
|
-
}); // Update popover's position
|
|
1538
|
-
|
|
1539
|
-
popover.popper.update(); // Update collection status with new state
|
|
1606
|
+
var trigger = document.querySelector("[aria-controls=\"" + id + "\"]") || document.querySelector("[aria-describedby=\"" + id + "\"]");
|
|
1607
|
+
var target = document.querySelector("#" + id);
|
|
1540
1608
|
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1609
|
+
if (!trigger && !target) {
|
|
1610
|
+
console.error('No popover elements found using the provided ID:', id);
|
|
1611
|
+
} else if (!trigger) {
|
|
1612
|
+
console.error('No popover trigger associated with the provided popover:', target);
|
|
1613
|
+
} else if (!target) {
|
|
1614
|
+
console.error('No popover associated with the provided popover trigger:', trigger);
|
|
1615
|
+
}
|
|
1545
1616
|
|
|
1546
|
-
|
|
1617
|
+
if (!trigger || !target) {
|
|
1618
|
+
return false;
|
|
1619
|
+
} else {
|
|
1620
|
+
return {
|
|
1621
|
+
trigger: trigger,
|
|
1622
|
+
target: target
|
|
1623
|
+
};
|
|
1624
|
+
}
|
|
1625
|
+
} else {
|
|
1626
|
+
console.error('Could not resolve the popover ID:', query);
|
|
1627
|
+
return false;
|
|
1628
|
+
}
|
|
1547
1629
|
}
|
|
1548
1630
|
|
|
1549
1631
|
var top = 'top';
|
|
@@ -3329,72 +3411,98 @@ var createPopper = /*#__PURE__*/popperGenerator({
|
|
|
3329
3411
|
defaultModifiers: defaultModifiers
|
|
3330
3412
|
}); // eslint-disable-next-line import/no-unused-modules
|
|
3331
3413
|
|
|
3332
|
-
function
|
|
3333
|
-
//
|
|
3334
|
-
|
|
3335
|
-
// Try and get the target
|
|
3336
|
-
target = getPopover(trigger, this.settings); // If still no target is returned, log an error and return false
|
|
3414
|
+
function open(popover) {
|
|
3415
|
+
// Update state class
|
|
3416
|
+
popover.target.classList.add(this.settings.stateActive); // Update a11y attribute
|
|
3337
3417
|
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
}
|
|
3342
|
-
} // Check if this item has already been registered in the collection
|
|
3418
|
+
if (popover.trigger.hasAttribute('aria-controls')) {
|
|
3419
|
+
popover.trigger.setAttribute('aria-expanded', 'true');
|
|
3420
|
+
} // Update popover config
|
|
3343
3421
|
|
|
3344
3422
|
|
|
3345
|
-
|
|
3346
|
-
return item.trigger === trigger && item.target === target;
|
|
3347
|
-
}); // Initiate popover variable
|
|
3423
|
+
popover.config = getConfig(popover.target, this.settings); // Enable popper event listeners and set placement/modifiers
|
|
3348
3424
|
|
|
3349
|
-
|
|
3425
|
+
popover.popper.setOptions({
|
|
3426
|
+
placement: popover.config['placement'],
|
|
3427
|
+
modifiers: [{
|
|
3428
|
+
name: 'eventListeners',
|
|
3429
|
+
enabled: true
|
|
3430
|
+
}].concat(getModifiers(popover.config))
|
|
3431
|
+
}); // Update popover position
|
|
3350
3432
|
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3433
|
+
popover.popper.update(); // Update popover state
|
|
3434
|
+
|
|
3435
|
+
popover.state = 'opened'; // Return the popover
|
|
3436
|
+
|
|
3437
|
+
return popover;
|
|
3438
|
+
}
|
|
3439
|
+
|
|
3440
|
+
function register(trigger, target) {
|
|
3441
|
+
// Deregister popover if it already exists in the collection
|
|
3442
|
+
this.deregister(target.id); // Create popper instance
|
|
3443
|
+
|
|
3444
|
+
var popperInstance = createPopper(trigger, target); // Save root this for use inside object & create methods API
|
|
3357
3445
|
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3446
|
+
var root = this;
|
|
3447
|
+
var methods = {
|
|
3448
|
+
open: function open$1() {
|
|
3449
|
+
open.call(root, this);
|
|
3450
|
+
},
|
|
3451
|
+
close: function close$1() {
|
|
3452
|
+
close.call(root, this);
|
|
3453
|
+
},
|
|
3454
|
+
deregister: function deregister() {
|
|
3455
|
+
_deregister.call(root, this);
|
|
3456
|
+
}
|
|
3457
|
+
}; // Build popover object and push to collection array
|
|
3365
3458
|
|
|
3366
|
-
|
|
3367
|
-
|
|
3459
|
+
var popover = _extends({
|
|
3460
|
+
id: target.id,
|
|
3461
|
+
state: 'closed',
|
|
3462
|
+
trigger: trigger,
|
|
3463
|
+
target: target,
|
|
3464
|
+
popper: popperInstance,
|
|
3465
|
+
config: getConfig(target, this.settings)
|
|
3466
|
+
}, methods); // Setup event listeners
|
|
3368
3467
|
|
|
3369
3468
|
|
|
3370
3469
|
registerEventListeners.call(this, popover); // Set initial state of popover
|
|
3371
3470
|
|
|
3372
3471
|
if (popover.target.classList.contains(this.settings.stateActive)) {
|
|
3373
|
-
|
|
3472
|
+
popover.open();
|
|
3374
3473
|
documentClick.call(this, popover);
|
|
3375
3474
|
} else {
|
|
3376
|
-
|
|
3377
|
-
} //
|
|
3475
|
+
popover.close();
|
|
3476
|
+
} // Add item to collection
|
|
3477
|
+
|
|
3378
3478
|
|
|
3479
|
+
this.collection.push(popover); // Return the popover object
|
|
3379
3480
|
|
|
3380
3481
|
return popover;
|
|
3381
3482
|
}
|
|
3382
|
-
|
|
3483
|
+
|
|
3484
|
+
function _deregister(popover) {
|
|
3383
3485
|
// Check if this item has been registered in the collection
|
|
3384
|
-
var index = this.collection.findIndex(function (
|
|
3385
|
-
return
|
|
3386
|
-
}); // If the
|
|
3486
|
+
var index = this.collection.findIndex(function (entry) {
|
|
3487
|
+
return entry.id === popover.id;
|
|
3488
|
+
}); // If the entry exists in the collection
|
|
3387
3489
|
|
|
3388
3490
|
if (index >= 0) {
|
|
3389
|
-
//
|
|
3390
|
-
|
|
3391
|
-
|
|
3491
|
+
// Get the collection entry
|
|
3492
|
+
var entry = this.collection[index]; // Close the collection entry if it's open
|
|
3493
|
+
|
|
3494
|
+
if (entry.state === 'opened') {
|
|
3495
|
+
entry.close();
|
|
3392
3496
|
} // Clean up the popper instance
|
|
3393
3497
|
|
|
3394
3498
|
|
|
3395
|
-
|
|
3499
|
+
entry.popper.destroy(); // Remove event listeners
|
|
3500
|
+
|
|
3501
|
+
deregisterEventListeners(entry); // Delete properties from collection entry
|
|
3396
3502
|
|
|
3397
|
-
|
|
3503
|
+
Object.getOwnPropertyNames(entry).forEach(function (prop) {
|
|
3504
|
+
delete entry[prop];
|
|
3505
|
+
}); // Remove entry from collection
|
|
3398
3506
|
|
|
3399
3507
|
this.collection.splice(index, 1);
|
|
3400
3508
|
} // Return the new collection
|
|
@@ -3406,7 +3514,7 @@ function registerEventListeners(popover) {
|
|
|
3406
3514
|
// If event listeners aren't already setup
|
|
3407
3515
|
if (!popover.__eventListeners) {
|
|
3408
3516
|
// Add event listeners based on event type
|
|
3409
|
-
var eventType =
|
|
3517
|
+
var eventType = popover.config['event'];
|
|
3410
3518
|
|
|
3411
3519
|
if (eventType === 'hover') {
|
|
3412
3520
|
// Setup event listeners object for hover
|
|
@@ -3467,38 +3575,23 @@ function deregisterEventListeners(popover) {
|
|
|
3467
3575
|
|
|
3468
3576
|
return popover;
|
|
3469
3577
|
}
|
|
3470
|
-
function registerCollection() {
|
|
3471
|
-
var _this = this;
|
|
3472
3578
|
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
triggers.forEach(function (trigger) {
|
|
3476
|
-
// Register the popover and save to collection array
|
|
3477
|
-
_this.register(trigger, false);
|
|
3478
|
-
}); // Return the popover collection
|
|
3579
|
+
var Popover = /*#__PURE__*/function (_Collection) {
|
|
3580
|
+
_inheritsLoose(Popover, _Collection);
|
|
3479
3581
|
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
function deregisterCollection() {
|
|
3483
|
-
// Loop through all items within the collection and pass them to deregister()
|
|
3484
|
-
while (this.collection.length > 0) {
|
|
3485
|
-
this.deregister(this.collection[0]);
|
|
3486
|
-
} // Return the popover collection
|
|
3582
|
+
function Popover(options) {
|
|
3583
|
+
var _this;
|
|
3487
3584
|
|
|
3585
|
+
_this = _Collection.call(this) || this;
|
|
3586
|
+
_this.defaults = defaults;
|
|
3587
|
+
_this.settings = _extends({}, _this.defaults, options); // this.collection = [];
|
|
3488
3588
|
|
|
3489
|
-
|
|
3490
|
-
}
|
|
3491
|
-
|
|
3492
|
-
var Popover = /*#__PURE__*/function () {
|
|
3493
|
-
function Popover(options) {
|
|
3494
|
-
this.defaults = defaults;
|
|
3495
|
-
this.settings = _extends({}, this.defaults, options);
|
|
3496
|
-
this.collection = [];
|
|
3497
|
-
this.memory = {
|
|
3589
|
+
_this.memory = {
|
|
3498
3590
|
trigger: null
|
|
3499
3591
|
};
|
|
3500
|
-
|
|
3501
|
-
if (
|
|
3592
|
+
_this.__handlerKeydown = handlerKeydown.bind(_assertThisInitialized(_this));
|
|
3593
|
+
if (_this.settings.autoInit) _this.init();
|
|
3594
|
+
return _this;
|
|
3502
3595
|
}
|
|
3503
3596
|
|
|
3504
3597
|
var _proto = Popover.prototype;
|
|
@@ -3509,9 +3602,11 @@ var Popover = /*#__PURE__*/function () {
|
|
|
3509
3602
|
}
|
|
3510
3603
|
|
|
3511
3604
|
// Update settings with passed options
|
|
3512
|
-
if (options) this.settings = _extends({}, this.settings, options); //
|
|
3605
|
+
if (options) this.settings = _extends({}, this.settings, options); // Get all the popovers
|
|
3606
|
+
|
|
3607
|
+
var popovers = document.querySelectorAll(this.settings.selectorPopover); // Build the collections array with popover instances
|
|
3513
3608
|
|
|
3514
|
-
this.registerCollection(); // If eventListeners is enabled
|
|
3609
|
+
this.registerCollection(popovers); // If eventListeners is enabled
|
|
3515
3610
|
|
|
3516
3611
|
if (this.settings.eventListeners) {
|
|
3517
3612
|
// Pass false to initEventListeners() since registerCollection()
|
|
@@ -3536,7 +3631,7 @@ var Popover = /*#__PURE__*/function () {
|
|
|
3536
3631
|
;
|
|
3537
3632
|
|
|
3538
3633
|
_proto.initEventListeners = function initEventListeners(processCollection) {
|
|
3539
|
-
var
|
|
3634
|
+
var _this2 = this;
|
|
3540
3635
|
|
|
3541
3636
|
if (processCollection === void 0) {
|
|
3542
3637
|
processCollection = true;
|
|
@@ -3545,7 +3640,7 @@ var Popover = /*#__PURE__*/function () {
|
|
|
3545
3640
|
if (processCollection) {
|
|
3546
3641
|
// Loop through collection and setup event listeners
|
|
3547
3642
|
this.collection.forEach(function (popover) {
|
|
3548
|
-
registerEventListeners.call(
|
|
3643
|
+
registerEventListeners.call(_this2, popover);
|
|
3549
3644
|
});
|
|
3550
3645
|
} // Add keydown global event listener
|
|
3551
3646
|
|
|
@@ -3573,44 +3668,40 @@ var Popover = /*#__PURE__*/function () {
|
|
|
3573
3668
|
*/
|
|
3574
3669
|
;
|
|
3575
3670
|
|
|
3576
|
-
_proto.register = function register$1(
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
return register.call(this, trigger, target);
|
|
3671
|
+
_proto.register = function register$1(query) {
|
|
3672
|
+
var els = getPopoverElements.call(this, query);
|
|
3673
|
+
if (!els) return false;
|
|
3674
|
+
return register.call(this, els.trigger, els.target);
|
|
3582
3675
|
};
|
|
3583
3676
|
|
|
3584
|
-
_proto.deregister = function deregister
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
_proto.registerCollection = function registerCollection$1() {
|
|
3589
|
-
return registerCollection.call(this);
|
|
3590
|
-
};
|
|
3591
|
-
|
|
3592
|
-
_proto.deregisterCollection = function deregisterCollection$1() {
|
|
3593
|
-
return deregisterCollection.call(this);
|
|
3677
|
+
_proto.deregister = function deregister(query) {
|
|
3678
|
+
var popover = this.get(getPopoverID(query));
|
|
3679
|
+
if (!popover) return false;
|
|
3680
|
+
return _deregister.call(this, popover);
|
|
3594
3681
|
}
|
|
3595
3682
|
/**
|
|
3596
3683
|
* Change state functionality
|
|
3597
3684
|
*/
|
|
3598
3685
|
;
|
|
3599
3686
|
|
|
3600
|
-
_proto.open = function open
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
_proto.close = function close$1(popover) {
|
|
3605
|
-
return close.call(this, popover);
|
|
3687
|
+
_proto.open = function open(id) {
|
|
3688
|
+
var popover = this.get(id);
|
|
3689
|
+
if (!popover) return false;
|
|
3690
|
+
return popover.open();
|
|
3606
3691
|
};
|
|
3607
3692
|
|
|
3608
|
-
_proto.
|
|
3609
|
-
|
|
3693
|
+
_proto.close = function close(id) {
|
|
3694
|
+
if (id) {
|
|
3695
|
+
var popover = this.get(id);
|
|
3696
|
+
if (!popover) return false;
|
|
3697
|
+
return popover.close();
|
|
3698
|
+
} else {
|
|
3699
|
+
return closeAll.call(this);
|
|
3700
|
+
}
|
|
3610
3701
|
};
|
|
3611
3702
|
|
|
3612
3703
|
return Popover;
|
|
3613
|
-
}();
|
|
3704
|
+
}(Collection);
|
|
3614
3705
|
|
|
3615
3706
|
export { Checkbox, Drawer, Modal, Popover, index as core };
|
|
3616
3707
|
//# sourceMappingURL=scripts.esm.js.map
|