vrembem 1.40.3 → 1.42.1

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.
@@ -386,6 +386,30 @@
386
386
  return _extends.apply(this, arguments);
387
387
  }
388
388
 
389
+ function _inheritsLoose(subClass, superClass) {
390
+ subClass.prototype = Object.create(superClass.prototype);
391
+ subClass.prototype.constructor = subClass;
392
+
393
+ _setPrototypeOf(subClass, superClass);
394
+ }
395
+
396
+ function _setPrototypeOf(o, p) {
397
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
398
+ o.__proto__ = p;
399
+ return o;
400
+ };
401
+
402
+ return _setPrototypeOf(o, p);
403
+ }
404
+
405
+ function _assertThisInitialized(self) {
406
+ if (self === void 0) {
407
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
408
+ }
409
+
410
+ return self;
411
+ }
412
+
389
413
  var defaults$3 = {
390
414
  autoInit: false,
391
415
  stateAttr: 'aria-checked',
@@ -1003,6 +1027,7 @@
1003
1027
  dataClose: 'modal-close',
1004
1028
  dataFocus: 'modal-focus',
1005
1029
  dataRequired: 'modal-required',
1030
+ dataConfig: 'modal-config',
1006
1031
  // State classes
1007
1032
  stateOpened: 'is-opened',
1008
1033
  stateOpening: 'is-opening',
@@ -1022,6 +1047,36 @@
1022
1047
  transition: true
1023
1048
  };
1024
1049
 
1050
+ function getModalConfig(modal) {
1051
+ var json = modal.getAttribute("data-" + this.settings.dataConfig);
1052
+
1053
+ if (json) {
1054
+ var config = JSON.parse(json);
1055
+ return _extends({}, this.settings, config);
1056
+ } else {
1057
+ return this.settings;
1058
+ }
1059
+ }
1060
+ function getModal(modalKey) {
1061
+ if (typeof modalKey !== 'string') return modalKey;
1062
+ return document.querySelector("[data-" + this.settings.dataModal + "=\"" + modalKey + "\"]");
1063
+ }
1064
+ function modalNotFound(key) {
1065
+ return Promise.reject(new Error("Did not find modal with key: \"" + key + "\""));
1066
+ }
1067
+ function moveModals(type, ref) {
1068
+ if (type === void 0) {
1069
+ type = this.settings.moveModals.type;
1070
+ }
1071
+
1072
+ if (ref === void 0) {
1073
+ ref = this.settings.moveModals.ref;
1074
+ }
1075
+
1076
+ var modals = document.querySelectorAll("[data-" + this.settings.dataModal + "]");
1077
+ if (modals.length) moveElement(modals, type, ref);
1078
+ }
1079
+
1025
1080
  var close$1 = function close(returnFocus) {
1026
1081
  if (returnFocus === void 0) {
1027
1082
  returnFocus = true;
@@ -1034,14 +1089,15 @@
1034
1089
 
1035
1090
  if (modal) {
1036
1091
  _this2.working = true;
1037
- setInert(false, _this2.settings.selectorInert);
1038
- setOverflowHidden(false, _this2.settings.selectorOverflow);
1039
- return Promise.resolve(closeTransition(modal, _this2.settings)).then(function () {
1092
+ var config = getModalConfig.call(_this2, modal);
1093
+ setInert(false, config.selectorInert);
1094
+ setOverflowHidden(false, config.selectorOverflow);
1095
+ return Promise.resolve(closeTransition(modal, config)).then(function () {
1040
1096
  if (returnFocus) focusTrigger(_this2);
1041
1097
 
1042
1098
  _this2.focusTrap.destroy();
1043
1099
 
1044
- modal.dispatchEvent(new CustomEvent(_this2.settings.customEventPrefix + 'closed', {
1100
+ modal.dispatchEvent(new CustomEvent(config.customEventPrefix + 'closed', {
1045
1101
  detail: _this2,
1046
1102
  bubbles: true
1047
1103
  }));
@@ -1117,26 +1173,6 @@
1117
1173
  }
1118
1174
  }
1119
1175
 
1120
- function getModal(modalKey) {
1121
- if (typeof modalKey !== 'string') return modalKey;
1122
- return document.querySelector("[data-" + this.settings.dataModal + "=\"" + modalKey + "\"]");
1123
- }
1124
- function modalNotFound(key) {
1125
- return Promise.reject(new Error("Did not find modal with key: \"" + key + "\""));
1126
- }
1127
- function moveModals(type, ref) {
1128
- if (type === void 0) {
1129
- type = this.settings.moveModals.type;
1130
- }
1131
-
1132
- if (ref === void 0) {
1133
- ref = this.settings.moveModals.ref;
1134
- }
1135
-
1136
- var modals = document.querySelectorAll("[data-" + this.settings.dataModal + "]");
1137
- if (modals.length) moveElement(modals, type, ref);
1138
- }
1139
-
1140
1176
  function setInitialState() {
1141
1177
  var _this = this;
1142
1178
 
@@ -1163,16 +1199,17 @@
1163
1199
 
1164
1200
  var modal = getModal.call(_this2, modalKey);
1165
1201
  if (!modal) return Promise.resolve(modalNotFound(modalKey));
1202
+ var config = getModalConfig.call(_this2, modal);
1166
1203
 
1167
- if (hasClass(modal, _this2.settings.stateClosed)) {
1204
+ if (hasClass(modal, config.stateClosed)) {
1168
1205
  _this2.working = true;
1169
- setOverflowHidden(true, _this2.settings.selectorOverflow);
1170
- return Promise.resolve(openTransition(modal, _this2.settings)).then(function () {
1206
+ setOverflowHidden(true, config.selectorOverflow);
1207
+ return Promise.resolve(openTransition(modal, config)).then(function () {
1171
1208
  _this2.focusTrap.init(modal);
1172
1209
 
1173
- focusTarget(modal, _this2.settings);
1174
- setInert(true, _this2.settings.selectorInert);
1175
- modal.dispatchEvent(new CustomEvent(_this2.settings.customEventPrefix + 'opened', {
1210
+ focusTarget(modal, config);
1211
+ setInert(true, config.selectorInert);
1212
+ modal.dispatchEvent(new CustomEvent(config.customEventPrefix + 'opened', {
1176
1213
  detail: _this2,
1177
1214
  bubbles: true
1178
1215
  }));
@@ -1278,39 +1315,96 @@
1278
1315
  return Modal;
1279
1316
  }();
1280
1317
 
1318
+ var Collection = /*#__PURE__*/function () {
1319
+ function Collection() {
1320
+ this.collection = [];
1321
+ }
1322
+
1323
+ var _proto = Collection.prototype;
1324
+
1325
+ _proto.register = function register(item) {
1326
+ this.deregister(item);
1327
+ this.collection.push(item);
1328
+ return this.collection;
1329
+ };
1330
+
1331
+ _proto.deregister = function deregister(ref) {
1332
+ var index = this.collection.findIndex(function (entry) {
1333
+ return entry === ref;
1334
+ });
1335
+
1336
+ if (index >= 0) {
1337
+ var entry = this.collection[index];
1338
+ Object.getOwnPropertyNames(entry).forEach(function (prop) {
1339
+ delete entry[prop];
1340
+ });
1341
+ this.collection.splice(index, 1);
1342
+ }
1343
+
1344
+ return this.collection;
1345
+ };
1346
+
1347
+ _proto.registerCollection = function registerCollection(items) {
1348
+ var _this = this;
1349
+
1350
+ items.forEach(function (item) {
1351
+ _this.register(item);
1352
+ });
1353
+ return this.collection;
1354
+ };
1355
+
1356
+ _proto.deregisterCollection = function deregisterCollection() {
1357
+ while (this.collection.length > 0) {
1358
+ this.deregister(this.collection[0]);
1359
+ }
1360
+
1361
+ return this.collection;
1362
+ };
1363
+
1364
+ _proto.get = function get(query, key) {
1365
+ if (key === void 0) {
1366
+ key = 'id';
1367
+ }
1368
+
1369
+ var result = this.collection.find(function (item) {
1370
+ return item[key] === query;
1371
+ });
1372
+ return result || null;
1373
+ };
1374
+
1375
+ return Collection;
1376
+ }();
1377
+
1281
1378
  var defaults = {
1282
1379
  autoInit: false,
1283
- // Data attributes
1284
- dataPopover: 'popover',
1285
- dataTrigger: 'popover-trigger',
1286
- dataArrow: 'popover-arrow',
1287
- dataEventType: 'popover-event',
1288
- dataPlacement: 'popover-placement',
1380
+ // Selectors
1381
+ selectorPopover: '.popover',
1382
+ selectorArrow: '.popover__arrow',
1289
1383
  // State classes
1290
1384
  stateActive: 'is-active',
1291
1385
  // Feature toggles
1292
- eventType: 'click',
1293
1386
  eventListeners: true,
1294
- placement: 'bottom-start'
1387
+ eventType: 'click',
1388
+ placement: 'bottom'
1295
1389
  };
1296
1390
 
1297
1391
  function close(popover) {
1298
1392
  // Update state class
1299
1393
  popover.target.classList.remove(this.settings.stateActive); // Update a11y attributes
1300
1394
 
1301
- popover.trigger.setAttribute('aria-expanded', 'false'); // Disable popper event listeners
1395
+ if (popover.trigger.hasAttribute('aria-controls')) {
1396
+ popover.trigger.setAttribute('aria-expanded', 'false');
1397
+ } // Disable popper event listeners
1398
+
1302
1399
 
1303
1400
  popover.popper.setOptions({
1304
1401
  modifiers: [{
1305
1402
  name: 'eventListeners',
1306
1403
  enabled: false
1307
1404
  }]
1308
- }); // Update collection status with new state
1405
+ }); // Update popover state
1309
1406
 
1310
- var index = this.collection.findIndex(function (item) {
1311
- return item.target === popover.target;
1312
- });
1313
- this.collection[index].state = 'closed'; // Clear the memory if popover trigger matches the ones saved in memory
1407
+ popover.state = 'closed'; // Clear memory if popover trigger matches the one saved in memory
1314
1408
 
1315
1409
  if (popover.trigger === this.memory.trigger) {
1316
1410
  this.memory.trigger = null;
@@ -1320,19 +1414,15 @@
1320
1414
  return popover;
1321
1415
  }
1322
1416
  function closeAll() {
1323
- var _this = this;
1324
-
1325
1417
  this.collection.forEach(function (popover) {
1326
1418
  if (popover.state === 'opened') {
1327
- _this.close(popover);
1419
+ popover.close();
1328
1420
  }
1329
1421
  }); // Return the collection
1330
1422
 
1331
1423
  return this.collection;
1332
1424
  }
1333
1425
  function closeCheck(popover) {
1334
- var _this2 = this;
1335
-
1336
1426
  // Only run closeCheck if provided popover is currently open
1337
1427
  if (popover.state != 'opened') return; // Needed to correctly check which element is currently being focused
1338
1428
 
@@ -1340,10 +1430,10 @@
1340
1430
  // Check if trigger or target are being hovered
1341
1431
  var isHovered = popover.target.closest(':hover') === popover.target || popover.trigger.closest(':hover') === popover.trigger; // Check if trigger or target are being focused
1342
1432
 
1343
- var isFocused = document.activeElement.closest("[data-" + _this2.settings.dataPopover + "]") === popover.target || document.activeElement.closest("[data-" + _this2.settings.dataTrigger + "]") === popover.trigger; // Close if the trigger and target are not currently hovered or focused
1433
+ var isFocused = document.activeElement.closest("#" + popover.id + ", [aria-controls=\"" + popover.id + "\"]"); // Close if the trigger and target are not currently hovered or focused
1344
1434
 
1345
1435
  if (!isHovered && !isFocused) {
1346
- _this2.close(popover);
1436
+ popover.close();
1347
1437
  } // Return the popover
1348
1438
 
1349
1439
 
@@ -1353,10 +1443,10 @@
1353
1443
 
1354
1444
  function handlerClick(popover) {
1355
1445
  if (popover.target.classList.contains(this.settings.stateActive)) {
1356
- this.close(popover);
1446
+ popover.close();
1357
1447
  } else {
1358
1448
  this.memory.trigger = popover.trigger;
1359
- this.open(popover);
1449
+ popover.open();
1360
1450
  documentClick.call(this, popover);
1361
1451
  }
1362
1452
  }
@@ -1369,7 +1459,7 @@
1369
1459
  this.memory.trigger.focus();
1370
1460
  }
1371
1461
 
1372
- this.closeAll();
1462
+ closeAll.call(this);
1373
1463
  return;
1374
1464
 
1375
1465
  case 'Tab':
@@ -1383,19 +1473,21 @@
1383
1473
  }
1384
1474
  }
1385
1475
  function documentClick(popover) {
1386
- var obj = this;
1476
+ var root = this;
1387
1477
  document.addEventListener('click', function _f(event) {
1388
- var result = event.target.closest("[data-" + obj.settings.dataPopover + "], [data-" + obj.settings.dataTrigger + "]");
1389
- var match = result === popover.target || result === popover.trigger;
1478
+ // Check if a popover was clicked
1479
+ var result = event.target.closest("#" + popover.id + ", [aria-controls=\"" + popover.id + "\"]");
1390
1480
 
1391
- if (!match) {
1392
- if (popover.target.classList.contains(obj.settings.stateActive)) {
1393
- obj.close(popover);
1481
+ if (!result) {
1482
+ // If it doesn't match and popover is open, close it and remove event listener
1483
+ if (popover.target && popover.target.classList.contains(root.settings.stateActive)) {
1484
+ popover.close();
1394
1485
  }
1395
1486
 
1396
1487
  this.removeEventListener('click', _f);
1397
1488
  } else {
1398
- if (!popover.target.classList.contains(obj.settings.stateActive)) {
1489
+ // If it does match and popover isn't currently active, remove event listener
1490
+ if (popover.target && !popover.target.classList.contains(root.settings.stateActive)) {
1399
1491
  this.removeEventListener('click', _f);
1400
1492
  }
1401
1493
  }
@@ -1412,30 +1504,23 @@
1412
1504
  'offset': 0,
1413
1505
  'overflow-padding': 0,
1414
1506
  'flip-padding': 0,
1415
- 'arrow-element': "[data-" + settings.dataArrow + "]",
1507
+ 'arrow-element': settings.selectorArrow,
1416
1508
  'arrow-padding': 0
1417
1509
  }; // Loop through config obj
1418
1510
 
1419
1511
  for (var prop in config) {
1420
1512
  // Get the CSS variable property values
1421
1513
  var prefix = getComputedStyle(document.body).getPropertyValue('--vrembem-variable-prefix');
1422
- var val = styles.getPropertyValue("--" + prefix + "popover-" + prop).trim(); // If a value was found, replace the default in config obj
1514
+ var value = styles.getPropertyValue("--" + prefix + "popover-" + prop).trim(); // If a value was found, replace the default in config obj
1423
1515
 
1424
- if (val) {
1425
- config[prop] = val;
1516
+ if (value) {
1517
+ config[prop] = value;
1426
1518
  }
1427
1519
  } // Return the config obj
1428
1520
 
1429
1521
 
1430
1522
  return config;
1431
1523
  }
1432
- function getData(el, attr, fallback) {
1433
- if (fallback === void 0) {
1434
- fallback = false;
1435
- }
1436
-
1437
- return el.hasAttribute("data-" + attr) ? el.getAttribute("data-" + attr) : fallback;
1438
- }
1439
1524
  function getPadding(value) {
1440
1525
  var padding; // Split the value by spaces if it's a string
1441
1526
 
@@ -1509,47 +1594,56 @@
1509
1594
  }
1510
1595
  }];
1511
1596
  }
1512
- function getPopover(trigger, settings) {
1513
- // Get the value of the popover trigger attribute
1514
- var id = trigger.getAttribute("data-" + settings.dataTrigger).trim();
1597
+ function getPopoverID(obj) {
1598
+ // If it's a string
1599
+ if (typeof obj === 'string') {
1600
+ return obj;
1601
+ } // If it's an HTML element
1602
+ else if (typeof obj.hasAttribute === 'function') {
1603
+ // If it's a popover trigger
1604
+ if (obj.hasAttribute('aria-controls')) {
1605
+ return obj.getAttribute('aria-controls');
1606
+ } // If it's a popover tooltip trigger
1607
+ else if (obj.hasAttribute('aria-describedby')) {
1608
+ return obj.getAttribute('aria-describedby');
1609
+ } // If it's a popover target
1610
+ else if (obj.closest(this.settings.selectorPopover)) {
1611
+ return obj.id;
1612
+ } // Return false if no id was found
1613
+ else return false;
1614
+ } // If it has an ID property
1615
+ else if (obj.id) {
1616
+ return obj.id;
1617
+ } // Return false if no id was found
1618
+ else return false;
1619
+ }
1620
+ function getPopoverElements(query) {
1621
+ var id = getPopoverID.call(this, query);
1515
1622
 
1516
1623
  if (id) {
1517
- // If trigger attribute value exists, return the querySelector element using
1518
- // the provided popover trigger attribute's value
1519
- return document.querySelector("[data-" + settings.dataPopover + "=\"" + id + "\"]");
1520
- } else {
1521
- // If trigger attribute value doesn't exist, check if
1522
- // - There is a nextElementSibling relative to the trigger
1523
- // - And it has the popover data attribute.
1524
- return trigger.nextElementSibling && trigger.nextElementSibling.hasAttribute("data-" + settings.dataPopover) ? // Return the element or false if the two checks fail
1525
- trigger.nextElementSibling : false;
1526
- }
1527
- }
1528
-
1529
- function open(popover) {
1530
- // Update state class
1531
- popover.target.classList.add(this.settings.stateActive); // Update a11y attributes
1532
-
1533
- popover.trigger.setAttribute('aria-expanded', 'true'); // Update popover config
1534
-
1535
- popover.config = getConfig(popover.target, this.settings); // Enable popper event listeners and set placement/modifiers
1536
-
1537
- popover.popper.setOptions({
1538
- placement: getData(popover.target, this.settings.dataPlacement, popover.config['placement']),
1539
- modifiers: [{
1540
- name: 'eventListeners',
1541
- enabled: true
1542
- }].concat(getModifiers(popover.config))
1543
- }); // Update popover's position
1624
+ var trigger = document.querySelector("[aria-controls=\"" + id + "\"]") || document.querySelector("[aria-describedby=\"" + id + "\"]");
1625
+ var target = document.querySelector("#" + id);
1544
1626
 
1545
- popover.popper.update(); // Update collection status with new state
1546
-
1547
- var index = this.collection.findIndex(function (item) {
1548
- return item.target === popover.target;
1549
- });
1550
- this.collection[index].state = 'opened'; // Return the popover
1627
+ if (!trigger && !target) {
1628
+ console.error('No popover elements found using the provided ID:', id);
1629
+ } else if (!trigger) {
1630
+ console.error('No popover trigger associated with the provided popover:', target);
1631
+ } else if (!target) {
1632
+ console.error('No popover associated with the provided popover trigger:', trigger);
1633
+ }
1551
1634
 
1552
- return popover;
1635
+ if (!trigger || !target) {
1636
+ return false;
1637
+ } else {
1638
+ return {
1639
+ trigger: trigger,
1640
+ target: target
1641
+ };
1642
+ }
1643
+ } else {
1644
+ console.error('Could not resolve the popover ID:', query);
1645
+ return false;
1646
+ }
1553
1647
  }
1554
1648
 
1555
1649
  var top = 'top';
@@ -3335,72 +3429,98 @@
3335
3429
  defaultModifiers: defaultModifiers
3336
3430
  }); // eslint-disable-next-line import/no-unused-modules
3337
3431
 
3338
- function register(trigger, target) {
3339
- // If no target is passed
3340
- if (!target) {
3341
- // Try and get the target
3342
- target = getPopover(trigger, this.settings); // If still no target is returned, log an error and return false
3432
+ function open(popover) {
3433
+ // Update state class
3434
+ popover.target.classList.add(this.settings.stateActive); // Update a11y attribute
3343
3435
 
3344
- if (!target) {
3345
- console.error('No popover associated with the provided trigger:', trigger);
3346
- return false;
3347
- }
3348
- } // Check if this item has already been registered in the collection
3436
+ if (popover.trigger.hasAttribute('aria-controls')) {
3437
+ popover.trigger.setAttribute('aria-expanded', 'true');
3438
+ } // Update popover config
3439
+
3440
+
3441
+ popover.config = getConfig(popover.target, this.settings); // Enable popper event listeners and set placement/modifiers
3442
+
3443
+ popover.popper.setOptions({
3444
+ placement: popover.config['placement'],
3445
+ modifiers: [{
3446
+ name: 'eventListeners',
3447
+ enabled: true
3448
+ }].concat(getModifiers(popover.config))
3449
+ }); // Update popover position
3349
3450
 
3451
+ popover.popper.update(); // Update popover state
3350
3452
 
3351
- var index = this.collection.findIndex(function (item) {
3352
- return item.trigger === trigger && item.target === target;
3353
- }); // Initiate popover variable
3453
+ popover.state = 'opened'; // Return the popover
3354
3454
 
3355
- var popover; // Check if it already exists in collection
3455
+ return popover;
3456
+ }
3356
3457
 
3357
- if (index >= 0) {
3358
- // Set popover as item from collection
3359
- popover = this.collection[index];
3360
- } else {
3361
- // Create popper instance
3362
- var popperInstance = createPopper(trigger, target); // Build popover object and push to collection array
3458
+ function register(trigger, target) {
3459
+ // Deregister popover if it already exists in the collection
3460
+ this.deregister(target.id); // Create popper instance
3461
+
3462
+ var popperInstance = createPopper(trigger, target); // Save root this for use inside object & create methods API
3363
3463
 
3364
- popover = {
3365
- state: 'closed',
3366
- trigger: trigger,
3367
- target: target,
3368
- popper: popperInstance,
3369
- config: getConfig(target, this.settings)
3370
- }; // Add item to collection
3464
+ var root = this;
3465
+ var methods = {
3466
+ open: function open$1() {
3467
+ open.call(root, this);
3468
+ },
3469
+ close: function close$1() {
3470
+ close.call(root, this);
3471
+ },
3472
+ deregister: function deregister() {
3473
+ _deregister.call(root, this);
3474
+ }
3475
+ }; // Build popover object and push to collection array
3371
3476
 
3372
- this.collection.push(popover);
3373
- } // Setup event listeners
3477
+ var popover = _extends({
3478
+ id: target.id,
3479
+ state: 'closed',
3480
+ trigger: trigger,
3481
+ target: target,
3482
+ popper: popperInstance,
3483
+ config: getConfig(target, this.settings)
3484
+ }, methods); // Setup event listeners
3374
3485
 
3375
3486
 
3376
3487
  registerEventListeners.call(this, popover); // Set initial state of popover
3377
3488
 
3378
3489
  if (popover.target.classList.contains(this.settings.stateActive)) {
3379
- this.open(popover);
3490
+ popover.open();
3380
3491
  documentClick.call(this, popover);
3381
3492
  } else {
3382
- this.close(popover);
3383
- } // Return the popover object
3493
+ popover.close();
3494
+ } // Add item to collection
3495
+
3384
3496
 
3497
+ this.collection.push(popover); // Return the popover object
3385
3498
 
3386
3499
  return popover;
3387
3500
  }
3388
- function deregister(popover) {
3501
+
3502
+ function _deregister(popover) {
3389
3503
  // Check if this item has been registered in the collection
3390
- var index = this.collection.findIndex(function (item) {
3391
- return item.trigger === popover.trigger && item.target === popover.target;
3392
- }); // If the item exists in the collection
3504
+ var index = this.collection.findIndex(function (entry) {
3505
+ return entry.id === popover.id;
3506
+ }); // If the entry exists in the collection
3393
3507
 
3394
3508
  if (index >= 0) {
3395
- // Close the popover
3396
- if (popover.state === 'opened') {
3397
- this.close(popover);
3509
+ // Get the collection entry
3510
+ var entry = this.collection[index]; // Close the collection entry if it's open
3511
+
3512
+ if (entry.state === 'opened') {
3513
+ entry.close();
3398
3514
  } // Clean up the popper instance
3399
3515
 
3400
3516
 
3401
- popover.popper.destroy(); // Remove event listeners
3517
+ entry.popper.destroy(); // Remove event listeners
3402
3518
 
3403
- deregisterEventListeners(popover); // Remove item from collection
3519
+ deregisterEventListeners(entry); // Delete properties from collection entry
3520
+
3521
+ Object.getOwnPropertyNames(entry).forEach(function (prop) {
3522
+ delete entry[prop];
3523
+ }); // Remove entry from collection
3404
3524
 
3405
3525
  this.collection.splice(index, 1);
3406
3526
  } // Return the new collection
@@ -3412,7 +3532,7 @@
3412
3532
  // If event listeners aren't already setup
3413
3533
  if (!popover.__eventListeners) {
3414
3534
  // Add event listeners based on event type
3415
- var eventType = getData(popover.target, this.settings.dataEventType, popover.config['event']);
3535
+ var eventType = popover.config['event'];
3416
3536
 
3417
3537
  if (eventType === 'hover') {
3418
3538
  // Setup event listeners object for hover
@@ -3473,38 +3593,23 @@
3473
3593
 
3474
3594
  return popover;
3475
3595
  }
3476
- function registerCollection() {
3477
- var _this = this;
3478
-
3479
- // Get all the triggers
3480
- var triggers = document.querySelectorAll("[data-" + this.settings.dataTrigger + "]");
3481
- triggers.forEach(function (trigger) {
3482
- // Register the popover and save to collection array
3483
- _this.register(trigger, false);
3484
- }); // Return the popover collection
3485
3596
 
3486
- return this.collection;
3487
- }
3488
- function deregisterCollection() {
3489
- // Loop through all items within the collection and pass them to deregister()
3490
- while (this.collection.length > 0) {
3491
- this.deregister(this.collection[0]);
3492
- } // Return the popover collection
3597
+ var Popover = /*#__PURE__*/function (_Collection) {
3598
+ _inheritsLoose(Popover, _Collection);
3493
3599
 
3600
+ function Popover(options) {
3601
+ var _this;
3494
3602
 
3495
- return this.collection;
3496
- }
3603
+ _this = _Collection.call(this) || this;
3604
+ _this.defaults = defaults;
3605
+ _this.settings = _extends({}, _this.defaults, options); // this.collection = [];
3497
3606
 
3498
- var Popover = /*#__PURE__*/function () {
3499
- function Popover(options) {
3500
- this.defaults = defaults;
3501
- this.settings = _extends({}, this.defaults, options);
3502
- this.collection = [];
3503
- this.memory = {
3607
+ _this.memory = {
3504
3608
  trigger: null
3505
3609
  };
3506
- this.__handlerKeydown = handlerKeydown.bind(this);
3507
- if (this.settings.autoInit) this.init();
3610
+ _this.__handlerKeydown = handlerKeydown.bind(_assertThisInitialized(_this));
3611
+ if (_this.settings.autoInit) _this.init();
3612
+ return _this;
3508
3613
  }
3509
3614
 
3510
3615
  var _proto = Popover.prototype;
@@ -3515,9 +3620,11 @@
3515
3620
  }
3516
3621
 
3517
3622
  // Update settings with passed options
3518
- if (options) this.settings = _extends({}, this.settings, options); // Build the collections array with popover instances
3623
+ if (options) this.settings = _extends({}, this.settings, options); // Get all the popovers
3624
+
3625
+ var popovers = document.querySelectorAll(this.settings.selectorPopover); // Build the collections array with popover instances
3519
3626
 
3520
- this.registerCollection(); // If eventListeners is enabled
3627
+ this.registerCollection(popovers); // If eventListeners is enabled
3521
3628
 
3522
3629
  if (this.settings.eventListeners) {
3523
3630
  // Pass false to initEventListeners() since registerCollection()
@@ -3542,7 +3649,7 @@
3542
3649
  ;
3543
3650
 
3544
3651
  _proto.initEventListeners = function initEventListeners(processCollection) {
3545
- var _this = this;
3652
+ var _this2 = this;
3546
3653
 
3547
3654
  if (processCollection === void 0) {
3548
3655
  processCollection = true;
@@ -3551,7 +3658,7 @@
3551
3658
  if (processCollection) {
3552
3659
  // Loop through collection and setup event listeners
3553
3660
  this.collection.forEach(function (popover) {
3554
- registerEventListeners.call(_this, popover);
3661
+ registerEventListeners.call(_this2, popover);
3555
3662
  });
3556
3663
  } // Add keydown global event listener
3557
3664
 
@@ -3579,44 +3686,40 @@
3579
3686
  */
3580
3687
  ;
3581
3688
 
3582
- _proto.register = function register$1(trigger, target) {
3583
- if (target === void 0) {
3584
- target = false;
3585
- }
3586
-
3587
- return register.call(this, trigger, target);
3588
- };
3589
-
3590
- _proto.deregister = function deregister$1(popover) {
3591
- return deregister.call(this, popover);
3592
- };
3593
-
3594
- _proto.registerCollection = function registerCollection$1() {
3595
- return registerCollection.call(this);
3689
+ _proto.register = function register$1(query) {
3690
+ var els = getPopoverElements.call(this, query);
3691
+ if (!els) return false;
3692
+ return register.call(this, els.trigger, els.target);
3596
3693
  };
3597
3694
 
3598
- _proto.deregisterCollection = function deregisterCollection$1() {
3599
- return deregisterCollection.call(this);
3695
+ _proto.deregister = function deregister(query) {
3696
+ var popover = this.get(getPopoverID(query));
3697
+ if (!popover) return false;
3698
+ return _deregister.call(this, popover);
3600
3699
  }
3601
3700
  /**
3602
3701
  * Change state functionality
3603
3702
  */
3604
3703
  ;
3605
3704
 
3606
- _proto.open = function open$1(popover) {
3607
- return open.call(this, popover);
3705
+ _proto.open = function open(id) {
3706
+ var popover = this.get(id);
3707
+ if (!popover) return false;
3708
+ return popover.open();
3608
3709
  };
3609
3710
 
3610
- _proto.close = function close$1(popover) {
3611
- return close.call(this, popover);
3612
- };
3613
-
3614
- _proto.closeAll = function closeAll$1() {
3615
- return closeAll.call(this);
3711
+ _proto.close = function close(id) {
3712
+ if (id) {
3713
+ var popover = this.get(id);
3714
+ if (!popover) return false;
3715
+ return popover.close();
3716
+ } else {
3717
+ return closeAll.call(this);
3718
+ }
3616
3719
  };
3617
3720
 
3618
3721
  return Popover;
3619
- }();
3722
+ }(Collection);
3620
3723
 
3621
3724
  exports.Checkbox = Checkbox;
3622
3725
  exports.Drawer = Drawer;