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.
- package/dev/scripts.esm.js +309 -206
- package/dev/scripts.esm.js.map +1 -1
- package/dev/scripts.js +309 -206
- package/dev/scripts.js.map +1 -1
- package/dev/scripts.modern.js +258 -177
- package/dev/scripts.modern.js.map +1 -1
- package/dev/scripts.umd.js +309 -206
- 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.modern.js
CHANGED
|
@@ -891,6 +891,7 @@ var defaults$1 = {
|
|
|
891
891
|
dataClose: 'modal-close',
|
|
892
892
|
dataFocus: 'modal-focus',
|
|
893
893
|
dataRequired: 'modal-required',
|
|
894
|
+
dataConfig: 'modal-config',
|
|
894
895
|
// State classes
|
|
895
896
|
stateOpened: 'is-opened',
|
|
896
897
|
stateOpening: 'is-opening',
|
|
@@ -910,17 +911,40 @@ var defaults$1 = {
|
|
|
910
911
|
transition: true
|
|
911
912
|
};
|
|
912
913
|
|
|
914
|
+
function getModalConfig(modal) {
|
|
915
|
+
const json = modal.getAttribute(`data-${this.settings.dataConfig}`);
|
|
916
|
+
|
|
917
|
+
if (json) {
|
|
918
|
+
const config = JSON.parse(json);
|
|
919
|
+
return _extends({}, this.settings, config);
|
|
920
|
+
} else {
|
|
921
|
+
return this.settings;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
function getModal(modalKey) {
|
|
925
|
+
if (typeof modalKey !== 'string') return modalKey;
|
|
926
|
+
return document.querySelector(`[data-${this.settings.dataModal}="${modalKey}"]`);
|
|
927
|
+
}
|
|
928
|
+
function modalNotFound(key) {
|
|
929
|
+
return Promise.reject(new Error(`Did not find modal with key: "${key}"`));
|
|
930
|
+
}
|
|
931
|
+
function moveModals(type = this.settings.moveModals.type, ref = this.settings.moveModals.ref) {
|
|
932
|
+
const modals = document.querySelectorAll(`[data-${this.settings.dataModal}]`);
|
|
933
|
+
if (modals.length) moveElement(modals, type, ref);
|
|
934
|
+
}
|
|
935
|
+
|
|
913
936
|
async function close$1(returnFocus = true) {
|
|
914
937
|
const modal = document.querySelector(`[data-${this.settings.dataModal}].${this.settings.stateOpened}`);
|
|
915
938
|
|
|
916
939
|
if (modal) {
|
|
917
940
|
this.working = true;
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
941
|
+
const config = getModalConfig.call(this, modal);
|
|
942
|
+
setInert(false, config.selectorInert);
|
|
943
|
+
setOverflowHidden(false, config.selectorOverflow);
|
|
944
|
+
await closeTransition(modal, config);
|
|
921
945
|
if (returnFocus) focusTrigger(this);
|
|
922
946
|
this.focusTrap.destroy();
|
|
923
|
-
modal.dispatchEvent(new CustomEvent(
|
|
947
|
+
modal.dispatchEvent(new CustomEvent(config.customEventPrefix + 'closed', {
|
|
924
948
|
detail: this,
|
|
925
949
|
bubbles: true
|
|
926
950
|
}));
|
|
@@ -973,18 +997,6 @@ function handlerKeydown$1(event) {
|
|
|
973
997
|
}
|
|
974
998
|
}
|
|
975
999
|
|
|
976
|
-
function getModal(modalKey) {
|
|
977
|
-
if (typeof modalKey !== 'string') return modalKey;
|
|
978
|
-
return document.querySelector(`[data-${this.settings.dataModal}="${modalKey}"]`);
|
|
979
|
-
}
|
|
980
|
-
function modalNotFound(key) {
|
|
981
|
-
return Promise.reject(new Error(`Did not find modal with key: "${key}"`));
|
|
982
|
-
}
|
|
983
|
-
function moveModals(type = this.settings.moveModals.type, ref = this.settings.moveModals.ref) {
|
|
984
|
-
const modals = document.querySelectorAll(`[data-${this.settings.dataModal}]`);
|
|
985
|
-
if (modals.length) moveElement(modals, type, ref);
|
|
986
|
-
}
|
|
987
|
-
|
|
988
1000
|
function setInitialState() {
|
|
989
1001
|
const modals = document.querySelectorAll(`[data-${this.settings.dataModal}]`);
|
|
990
1002
|
modals.forEach(el => {
|
|
@@ -1005,15 +1017,16 @@ function setInitialState() {
|
|
|
1005
1017
|
async function open$1(modalKey) {
|
|
1006
1018
|
const modal = getModal.call(this, modalKey);
|
|
1007
1019
|
if (!modal) return modalNotFound(modalKey);
|
|
1020
|
+
const config = getModalConfig.call(this, modal);
|
|
1008
1021
|
|
|
1009
|
-
if (hasClass(modal,
|
|
1022
|
+
if (hasClass(modal, config.stateClosed)) {
|
|
1010
1023
|
this.working = true;
|
|
1011
|
-
setOverflowHidden(true,
|
|
1012
|
-
await openTransition(modal,
|
|
1024
|
+
setOverflowHidden(true, config.selectorOverflow);
|
|
1025
|
+
await openTransition(modal, config);
|
|
1013
1026
|
this.focusTrap.init(modal);
|
|
1014
|
-
focusTarget(modal,
|
|
1015
|
-
setInert(true,
|
|
1016
|
-
modal.dispatchEvent(new CustomEvent(
|
|
1027
|
+
focusTarget(modal, config);
|
|
1028
|
+
setInert(true, config.selectorInert);
|
|
1029
|
+
modal.dispatchEvent(new CustomEvent(config.customEventPrefix + 'opened', {
|
|
1017
1030
|
detail: this,
|
|
1018
1031
|
bubbles: true
|
|
1019
1032
|
}));
|
|
@@ -1111,39 +1124,87 @@ class Modal {
|
|
|
1111
1124
|
|
|
1112
1125
|
}
|
|
1113
1126
|
|
|
1127
|
+
class Collection {
|
|
1128
|
+
constructor() {
|
|
1129
|
+
this.collection = [];
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
register(item) {
|
|
1133
|
+
this.deregister(item);
|
|
1134
|
+
this.collection.push(item);
|
|
1135
|
+
return this.collection;
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
deregister(ref) {
|
|
1139
|
+
const index = this.collection.findIndex(entry => {
|
|
1140
|
+
return entry === ref;
|
|
1141
|
+
});
|
|
1142
|
+
|
|
1143
|
+
if (index >= 0) {
|
|
1144
|
+
const entry = this.collection[index];
|
|
1145
|
+
Object.getOwnPropertyNames(entry).forEach(prop => {
|
|
1146
|
+
delete entry[prop];
|
|
1147
|
+
});
|
|
1148
|
+
this.collection.splice(index, 1);
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
return this.collection;
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
registerCollection(items) {
|
|
1155
|
+
items.forEach(item => {
|
|
1156
|
+
this.register(item);
|
|
1157
|
+
});
|
|
1158
|
+
return this.collection;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
deregisterCollection() {
|
|
1162
|
+
while (this.collection.length > 0) {
|
|
1163
|
+
this.deregister(this.collection[0]);
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
return this.collection;
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
get(query, key = 'id') {
|
|
1170
|
+
const result = this.collection.find(item => {
|
|
1171
|
+
return item[key] === query;
|
|
1172
|
+
});
|
|
1173
|
+
return result || null;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1114
1178
|
var defaults = {
|
|
1115
1179
|
autoInit: false,
|
|
1116
|
-
//
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
dataArrow: 'popover-arrow',
|
|
1120
|
-
dataEventType: 'popover-event',
|
|
1121
|
-
dataPlacement: 'popover-placement',
|
|
1180
|
+
// Selectors
|
|
1181
|
+
selectorPopover: '.popover',
|
|
1182
|
+
selectorArrow: '.popover__arrow',
|
|
1122
1183
|
// State classes
|
|
1123
1184
|
stateActive: 'is-active',
|
|
1124
1185
|
// Feature toggles
|
|
1125
|
-
eventType: 'click',
|
|
1126
1186
|
eventListeners: true,
|
|
1127
|
-
|
|
1187
|
+
eventType: 'click',
|
|
1188
|
+
placement: 'bottom'
|
|
1128
1189
|
};
|
|
1129
1190
|
|
|
1130
1191
|
function close(popover) {
|
|
1131
1192
|
// Update state class
|
|
1132
1193
|
popover.target.classList.remove(this.settings.stateActive); // Update a11y attributes
|
|
1133
1194
|
|
|
1134
|
-
popover.trigger.
|
|
1195
|
+
if (popover.trigger.hasAttribute('aria-controls')) {
|
|
1196
|
+
popover.trigger.setAttribute('aria-expanded', 'false');
|
|
1197
|
+
} // Disable popper event listeners
|
|
1198
|
+
|
|
1135
1199
|
|
|
1136
1200
|
popover.popper.setOptions({
|
|
1137
1201
|
modifiers: [{
|
|
1138
1202
|
name: 'eventListeners',
|
|
1139
1203
|
enabled: false
|
|
1140
1204
|
}]
|
|
1141
|
-
}); // Update
|
|
1205
|
+
}); // Update popover state
|
|
1142
1206
|
|
|
1143
|
-
|
|
1144
|
-
return item.target === popover.target;
|
|
1145
|
-
});
|
|
1146
|
-
this.collection[index].state = 'closed'; // Clear the memory if popover trigger matches the ones saved in memory
|
|
1207
|
+
popover.state = 'closed'; // Clear memory if popover trigger matches the one saved in memory
|
|
1147
1208
|
|
|
1148
1209
|
if (popover.trigger === this.memory.trigger) {
|
|
1149
1210
|
this.memory.trigger = null;
|
|
@@ -1155,7 +1216,7 @@ function close(popover) {
|
|
|
1155
1216
|
function closeAll() {
|
|
1156
1217
|
this.collection.forEach(popover => {
|
|
1157
1218
|
if (popover.state === 'opened') {
|
|
1158
|
-
|
|
1219
|
+
popover.close();
|
|
1159
1220
|
}
|
|
1160
1221
|
}); // Return the collection
|
|
1161
1222
|
|
|
@@ -1169,10 +1230,10 @@ function closeCheck(popover) {
|
|
|
1169
1230
|
// Check if trigger or target are being hovered
|
|
1170
1231
|
const isHovered = popover.target.closest(':hover') === popover.target || popover.trigger.closest(':hover') === popover.trigger; // Check if trigger or target are being focused
|
|
1171
1232
|
|
|
1172
|
-
const isFocused = document.activeElement.closest(
|
|
1233
|
+
const isFocused = document.activeElement.closest(`#${popover.id}, [aria-controls="${popover.id}"]`); // Close if the trigger and target are not currently hovered or focused
|
|
1173
1234
|
|
|
1174
1235
|
if (!isHovered && !isFocused) {
|
|
1175
|
-
|
|
1236
|
+
popover.close();
|
|
1176
1237
|
} // Return the popover
|
|
1177
1238
|
|
|
1178
1239
|
|
|
@@ -1182,10 +1243,10 @@ function closeCheck(popover) {
|
|
|
1182
1243
|
|
|
1183
1244
|
function handlerClick(popover) {
|
|
1184
1245
|
if (popover.target.classList.contains(this.settings.stateActive)) {
|
|
1185
|
-
|
|
1246
|
+
popover.close();
|
|
1186
1247
|
} else {
|
|
1187
1248
|
this.memory.trigger = popover.trigger;
|
|
1188
|
-
|
|
1249
|
+
popover.open();
|
|
1189
1250
|
documentClick.call(this, popover);
|
|
1190
1251
|
}
|
|
1191
1252
|
}
|
|
@@ -1196,7 +1257,7 @@ function handlerKeydown(event) {
|
|
|
1196
1257
|
this.memory.trigger.focus();
|
|
1197
1258
|
}
|
|
1198
1259
|
|
|
1199
|
-
|
|
1260
|
+
closeAll.call(this);
|
|
1200
1261
|
return;
|
|
1201
1262
|
|
|
1202
1263
|
case 'Tab':
|
|
@@ -1210,19 +1271,21 @@ function handlerKeydown(event) {
|
|
|
1210
1271
|
}
|
|
1211
1272
|
}
|
|
1212
1273
|
function documentClick(popover) {
|
|
1213
|
-
const
|
|
1274
|
+
const root = this;
|
|
1214
1275
|
document.addEventListener('click', function _f(event) {
|
|
1215
|
-
|
|
1216
|
-
const
|
|
1276
|
+
// Check if a popover was clicked
|
|
1277
|
+
const result = event.target.closest(`#${popover.id}, [aria-controls="${popover.id}"]`);
|
|
1217
1278
|
|
|
1218
|
-
if (!
|
|
1219
|
-
|
|
1220
|
-
|
|
1279
|
+
if (!result) {
|
|
1280
|
+
// If it doesn't match and popover is open, close it and remove event listener
|
|
1281
|
+
if (popover.target && popover.target.classList.contains(root.settings.stateActive)) {
|
|
1282
|
+
popover.close();
|
|
1221
1283
|
}
|
|
1222
1284
|
|
|
1223
1285
|
this.removeEventListener('click', _f);
|
|
1224
1286
|
} else {
|
|
1225
|
-
|
|
1287
|
+
// If it does match and popover isn't currently active, remove event listener
|
|
1288
|
+
if (popover.target && !popover.target.classList.contains(root.settings.stateActive)) {
|
|
1226
1289
|
this.removeEventListener('click', _f);
|
|
1227
1290
|
}
|
|
1228
1291
|
}
|
|
@@ -1239,26 +1302,23 @@ function getConfig(el, settings) {
|
|
|
1239
1302
|
'offset': 0,
|
|
1240
1303
|
'overflow-padding': 0,
|
|
1241
1304
|
'flip-padding': 0,
|
|
1242
|
-
'arrow-element':
|
|
1305
|
+
'arrow-element': settings.selectorArrow,
|
|
1243
1306
|
'arrow-padding': 0
|
|
1244
1307
|
}; // Loop through config obj
|
|
1245
1308
|
|
|
1246
1309
|
for (const prop in config) {
|
|
1247
1310
|
// Get the CSS variable property values
|
|
1248
1311
|
const prefix = getComputedStyle(document.body).getPropertyValue('--vrembem-variable-prefix');
|
|
1249
|
-
const
|
|
1312
|
+
const value = styles.getPropertyValue(`--${prefix}popover-${prop}`).trim(); // If a value was found, replace the default in config obj
|
|
1250
1313
|
|
|
1251
|
-
if (
|
|
1252
|
-
config[prop] =
|
|
1314
|
+
if (value) {
|
|
1315
|
+
config[prop] = value;
|
|
1253
1316
|
}
|
|
1254
1317
|
} // Return the config obj
|
|
1255
1318
|
|
|
1256
1319
|
|
|
1257
1320
|
return config;
|
|
1258
1321
|
}
|
|
1259
|
-
function getData(el, attr, fallback = false) {
|
|
1260
|
-
return el.hasAttribute(`data-${attr}`) ? el.getAttribute(`data-${attr}`) : fallback;
|
|
1261
|
-
}
|
|
1262
1322
|
function getPadding(value) {
|
|
1263
1323
|
let padding; // Split the value by spaces if it's a string
|
|
1264
1324
|
|
|
@@ -1332,49 +1392,58 @@ function getModifiers(options) {
|
|
|
1332
1392
|
}
|
|
1333
1393
|
}];
|
|
1334
1394
|
}
|
|
1335
|
-
function
|
|
1336
|
-
//
|
|
1337
|
-
|
|
1395
|
+
function getPopoverID(obj) {
|
|
1396
|
+
// If it's a string
|
|
1397
|
+
if (typeof obj === 'string') {
|
|
1398
|
+
return obj;
|
|
1399
|
+
} // If it's an HTML element
|
|
1400
|
+
else if (typeof obj.hasAttribute === 'function') {
|
|
1401
|
+
// If it's a popover trigger
|
|
1402
|
+
if (obj.hasAttribute('aria-controls')) {
|
|
1403
|
+
return obj.getAttribute('aria-controls');
|
|
1404
|
+
} // If it's a popover tooltip trigger
|
|
1405
|
+
else if (obj.hasAttribute('aria-describedby')) {
|
|
1406
|
+
return obj.getAttribute('aria-describedby');
|
|
1407
|
+
} // If it's a popover target
|
|
1408
|
+
else if (obj.closest(this.settings.selectorPopover)) {
|
|
1409
|
+
return obj.id;
|
|
1410
|
+
} // Return false if no id was found
|
|
1411
|
+
else return false;
|
|
1412
|
+
} // If it has an ID property
|
|
1413
|
+
else if (obj.id) {
|
|
1414
|
+
return obj.id;
|
|
1415
|
+
} // Return false if no id was found
|
|
1416
|
+
else return false;
|
|
1417
|
+
}
|
|
1418
|
+
function getPopoverElements(query) {
|
|
1419
|
+
const id = getPopoverID.call(this, query);
|
|
1338
1420
|
|
|
1339
1421
|
if (id) {
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1422
|
+
const trigger = document.querySelector(`[aria-controls="${id}"]`) || document.querySelector(`[aria-describedby="${id}"]`);
|
|
1423
|
+
const target = document.querySelector(`#${id}`);
|
|
1424
|
+
|
|
1425
|
+
if (!trigger && !target) {
|
|
1426
|
+
console.error('No popover elements found using the provided ID:', id);
|
|
1427
|
+
} else if (!trigger) {
|
|
1428
|
+
console.error('No popover trigger associated with the provided popover:', target);
|
|
1429
|
+
} else if (!target) {
|
|
1430
|
+
console.error('No popover associated with the provided popover trigger:', trigger);
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
if (!trigger || !target) {
|
|
1434
|
+
return false;
|
|
1435
|
+
} else {
|
|
1436
|
+
return {
|
|
1437
|
+
trigger,
|
|
1438
|
+
target
|
|
1439
|
+
};
|
|
1440
|
+
}
|
|
1343
1441
|
} else {
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
// - And it has the popover data attribute.
|
|
1347
|
-
return trigger.nextElementSibling && trigger.nextElementSibling.hasAttribute(`data-${settings.dataPopover}`) ? // Return the element or false if the two checks fail
|
|
1348
|
-
trigger.nextElementSibling : false;
|
|
1442
|
+
console.error('Could not resolve the popover ID:', query);
|
|
1443
|
+
return false;
|
|
1349
1444
|
}
|
|
1350
1445
|
}
|
|
1351
1446
|
|
|
1352
|
-
function open(popover) {
|
|
1353
|
-
// Update state class
|
|
1354
|
-
popover.target.classList.add(this.settings.stateActive); // Update a11y attributes
|
|
1355
|
-
|
|
1356
|
-
popover.trigger.setAttribute('aria-expanded', 'true'); // Update popover config
|
|
1357
|
-
|
|
1358
|
-
popover.config = getConfig(popover.target, this.settings); // Enable popper event listeners and set placement/modifiers
|
|
1359
|
-
|
|
1360
|
-
popover.popper.setOptions({
|
|
1361
|
-
placement: getData(popover.target, this.settings.dataPlacement, popover.config['placement']),
|
|
1362
|
-
modifiers: [{
|
|
1363
|
-
name: 'eventListeners',
|
|
1364
|
-
enabled: true
|
|
1365
|
-
}, ...getModifiers(popover.config)]
|
|
1366
|
-
}); // Update popover's position
|
|
1367
|
-
|
|
1368
|
-
popover.popper.update(); // Update collection status with new state
|
|
1369
|
-
|
|
1370
|
-
const index = this.collection.findIndex(item => {
|
|
1371
|
-
return item.target === popover.target;
|
|
1372
|
-
});
|
|
1373
|
-
this.collection[index].state = 'opened'; // Return the popover
|
|
1374
|
-
|
|
1375
|
-
return popover;
|
|
1376
|
-
}
|
|
1377
|
-
|
|
1378
1447
|
var top = 'top';
|
|
1379
1448
|
var bottom = 'bottom';
|
|
1380
1449
|
var right = 'right';
|
|
@@ -3158,72 +3227,100 @@ var createPopper = /*#__PURE__*/popperGenerator({
|
|
|
3158
3227
|
defaultModifiers: defaultModifiers
|
|
3159
3228
|
}); // eslint-disable-next-line import/no-unused-modules
|
|
3160
3229
|
|
|
3161
|
-
function
|
|
3162
|
-
//
|
|
3163
|
-
|
|
3164
|
-
// Try and get the target
|
|
3165
|
-
target = getPopover(trigger, this.settings); // If still no target is returned, log an error and return false
|
|
3230
|
+
function open(popover) {
|
|
3231
|
+
// Update state class
|
|
3232
|
+
popover.target.classList.add(this.settings.stateActive); // Update a11y attribute
|
|
3166
3233
|
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
}
|
|
3171
|
-
} // Check if this item has already been registered in the collection
|
|
3234
|
+
if (popover.trigger.hasAttribute('aria-controls')) {
|
|
3235
|
+
popover.trigger.setAttribute('aria-expanded', 'true');
|
|
3236
|
+
} // Update popover config
|
|
3172
3237
|
|
|
3173
3238
|
|
|
3174
|
-
|
|
3175
|
-
return item.trigger === trigger && item.target === target;
|
|
3176
|
-
}); // Initiate popover variable
|
|
3239
|
+
popover.config = getConfig(popover.target, this.settings); // Enable popper event listeners and set placement/modifiers
|
|
3177
3240
|
|
|
3178
|
-
|
|
3241
|
+
popover.popper.setOptions({
|
|
3242
|
+
placement: popover.config['placement'],
|
|
3243
|
+
modifiers: [{
|
|
3244
|
+
name: 'eventListeners',
|
|
3245
|
+
enabled: true
|
|
3246
|
+
}, ...getModifiers(popover.config)]
|
|
3247
|
+
}); // Update popover position
|
|
3179
3248
|
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3249
|
+
popover.popper.update(); // Update popover state
|
|
3250
|
+
|
|
3251
|
+
popover.state = 'opened'; // Return the popover
|
|
3252
|
+
|
|
3253
|
+
return popover;
|
|
3254
|
+
}
|
|
3186
3255
|
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3256
|
+
function register(trigger, target) {
|
|
3257
|
+
// Deregister popover if it already exists in the collection
|
|
3258
|
+
this.deregister(target.id); // Create popper instance
|
|
3259
|
+
|
|
3260
|
+
const popperInstance = createPopper(trigger, target); // Save root this for use inside object & create methods API
|
|
3261
|
+
|
|
3262
|
+
const root = this;
|
|
3263
|
+
const methods = {
|
|
3264
|
+
open() {
|
|
3265
|
+
open.call(root, this);
|
|
3266
|
+
},
|
|
3267
|
+
|
|
3268
|
+
close() {
|
|
3269
|
+
close.call(root, this);
|
|
3270
|
+
},
|
|
3271
|
+
|
|
3272
|
+
deregister() {
|
|
3273
|
+
deregister.call(root, this);
|
|
3274
|
+
}
|
|
3275
|
+
|
|
3276
|
+
}; // Build popover object and push to collection array
|
|
3194
3277
|
|
|
3195
|
-
|
|
3196
|
-
|
|
3278
|
+
const popover = _extends({
|
|
3279
|
+
id: target.id,
|
|
3280
|
+
state: 'closed',
|
|
3281
|
+
trigger: trigger,
|
|
3282
|
+
target: target,
|
|
3283
|
+
popper: popperInstance,
|
|
3284
|
+
config: getConfig(target, this.settings)
|
|
3285
|
+
}, methods); // Setup event listeners
|
|
3197
3286
|
|
|
3198
3287
|
|
|
3199
3288
|
registerEventListeners.call(this, popover); // Set initial state of popover
|
|
3200
3289
|
|
|
3201
3290
|
if (popover.target.classList.contains(this.settings.stateActive)) {
|
|
3202
|
-
|
|
3291
|
+
popover.open();
|
|
3203
3292
|
documentClick.call(this, popover);
|
|
3204
3293
|
} else {
|
|
3205
|
-
|
|
3206
|
-
} //
|
|
3294
|
+
popover.close();
|
|
3295
|
+
} // Add item to collection
|
|
3296
|
+
|
|
3207
3297
|
|
|
3298
|
+
this.collection.push(popover); // Return the popover object
|
|
3208
3299
|
|
|
3209
3300
|
return popover;
|
|
3210
3301
|
}
|
|
3211
3302
|
function deregister(popover) {
|
|
3212
3303
|
// Check if this item has been registered in the collection
|
|
3213
|
-
const index = this.collection.findIndex(
|
|
3214
|
-
return
|
|
3215
|
-
}); // If the
|
|
3304
|
+
const index = this.collection.findIndex(entry => {
|
|
3305
|
+
return entry.id === popover.id;
|
|
3306
|
+
}); // If the entry exists in the collection
|
|
3216
3307
|
|
|
3217
3308
|
if (index >= 0) {
|
|
3218
|
-
//
|
|
3219
|
-
|
|
3220
|
-
|
|
3309
|
+
// Get the collection entry
|
|
3310
|
+
const entry = this.collection[index]; // Close the collection entry if it's open
|
|
3311
|
+
|
|
3312
|
+
if (entry.state === 'opened') {
|
|
3313
|
+
entry.close();
|
|
3221
3314
|
} // Clean up the popper instance
|
|
3222
3315
|
|
|
3223
3316
|
|
|
3224
|
-
|
|
3317
|
+
entry.popper.destroy(); // Remove event listeners
|
|
3225
3318
|
|
|
3226
|
-
deregisterEventListeners(
|
|
3319
|
+
deregisterEventListeners(entry); // Delete properties from collection entry
|
|
3320
|
+
|
|
3321
|
+
Object.getOwnPropertyNames(entry).forEach(prop => {
|
|
3322
|
+
delete entry[prop];
|
|
3323
|
+
}); // Remove entry from collection
|
|
3227
3324
|
|
|
3228
3325
|
this.collection.splice(index, 1);
|
|
3229
3326
|
} // Return the new collection
|
|
@@ -3235,7 +3332,7 @@ function registerEventListeners(popover) {
|
|
|
3235
3332
|
// If event listeners aren't already setup
|
|
3236
3333
|
if (!popover.__eventListeners) {
|
|
3237
3334
|
// Add event listeners based on event type
|
|
3238
|
-
const eventType =
|
|
3335
|
+
const eventType = popover.config['event'];
|
|
3239
3336
|
|
|
3240
3337
|
if (eventType === 'hover') {
|
|
3241
3338
|
// Setup event listeners object for hover
|
|
@@ -3296,31 +3393,13 @@ function deregisterEventListeners(popover) {
|
|
|
3296
3393
|
|
|
3297
3394
|
return popover;
|
|
3298
3395
|
}
|
|
3299
|
-
function registerCollection() {
|
|
3300
|
-
// Get all the triggers
|
|
3301
|
-
const triggers = document.querySelectorAll(`[data-${this.settings.dataTrigger}]`);
|
|
3302
|
-
triggers.forEach(trigger => {
|
|
3303
|
-
// Register the popover and save to collection array
|
|
3304
|
-
this.register(trigger, false);
|
|
3305
|
-
}); // Return the popover collection
|
|
3306
|
-
|
|
3307
|
-
return this.collection;
|
|
3308
|
-
}
|
|
3309
|
-
function deregisterCollection() {
|
|
3310
|
-
// Loop through all items within the collection and pass them to deregister()
|
|
3311
|
-
while (this.collection.length > 0) {
|
|
3312
|
-
this.deregister(this.collection[0]);
|
|
3313
|
-
} // Return the popover collection
|
|
3314
3396
|
|
|
3315
|
-
|
|
3316
|
-
return this.collection;
|
|
3317
|
-
}
|
|
3318
|
-
|
|
3319
|
-
class Popover {
|
|
3397
|
+
class Popover extends Collection {
|
|
3320
3398
|
constructor(options) {
|
|
3399
|
+
super();
|
|
3321
3400
|
this.defaults = defaults;
|
|
3322
|
-
this.settings = _extends({}, this.defaults, options);
|
|
3323
|
-
|
|
3401
|
+
this.settings = _extends({}, this.defaults, options); // this.collection = [];
|
|
3402
|
+
|
|
3324
3403
|
this.memory = {
|
|
3325
3404
|
trigger: null
|
|
3326
3405
|
};
|
|
@@ -3330,9 +3409,11 @@ class Popover {
|
|
|
3330
3409
|
|
|
3331
3410
|
init(options = null) {
|
|
3332
3411
|
// Update settings with passed options
|
|
3333
|
-
if (options) this.settings = _extends({}, this.settings, options); //
|
|
3412
|
+
if (options) this.settings = _extends({}, this.settings, options); // Get all the popovers
|
|
3334
3413
|
|
|
3335
|
-
this.
|
|
3414
|
+
const popovers = document.querySelectorAll(this.settings.selectorPopover); // Build the collections array with popover instances
|
|
3415
|
+
|
|
3416
|
+
this.registerCollection(popovers); // If eventListeners is enabled
|
|
3336
3417
|
|
|
3337
3418
|
if (this.settings.eventListeners) {
|
|
3338
3419
|
// Pass false to initEventListeners() since registerCollection()
|
|
@@ -3384,36 +3465,36 @@ class Popover {
|
|
|
3384
3465
|
*/
|
|
3385
3466
|
|
|
3386
3467
|
|
|
3387
|
-
register(
|
|
3388
|
-
|
|
3468
|
+
register(query) {
|
|
3469
|
+
const els = getPopoverElements.call(this, query);
|
|
3470
|
+
if (!els) return false;
|
|
3471
|
+
return register.call(this, els.trigger, els.target);
|
|
3389
3472
|
}
|
|
3390
3473
|
|
|
3391
|
-
deregister(
|
|
3474
|
+
deregister(query) {
|
|
3475
|
+
const popover = this.get(getPopoverID(query));
|
|
3476
|
+
if (!popover) return false;
|
|
3392
3477
|
return deregister.call(this, popover);
|
|
3393
3478
|
}
|
|
3394
|
-
|
|
3395
|
-
registerCollection() {
|
|
3396
|
-
return registerCollection.call(this);
|
|
3397
|
-
}
|
|
3398
|
-
|
|
3399
|
-
deregisterCollection() {
|
|
3400
|
-
return deregisterCollection.call(this);
|
|
3401
|
-
}
|
|
3402
3479
|
/**
|
|
3403
3480
|
* Change state functionality
|
|
3404
3481
|
*/
|
|
3405
3482
|
|
|
3406
3483
|
|
|
3407
|
-
open(
|
|
3408
|
-
|
|
3484
|
+
open(id) {
|
|
3485
|
+
const popover = this.get(id);
|
|
3486
|
+
if (!popover) return false;
|
|
3487
|
+
return popover.open();
|
|
3409
3488
|
}
|
|
3410
3489
|
|
|
3411
|
-
close(
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3490
|
+
close(id) {
|
|
3491
|
+
if (id) {
|
|
3492
|
+
const popover = this.get(id);
|
|
3493
|
+
if (!popover) return false;
|
|
3494
|
+
return popover.close();
|
|
3495
|
+
} else {
|
|
3496
|
+
return closeAll.call(this);
|
|
3497
|
+
}
|
|
3417
3498
|
}
|
|
3418
3499
|
|
|
3419
3500
|
}
|