generated from AegisJSProject/template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.js
More file actions
34 lines (29 loc) · 1.12 KB
/
functions.js
File metadata and controls
34 lines (29 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const inertMap = new WeakMap();
const tabElsSelector = 'a[href]:not([inert]), input:not([inert]), select:not([inert]), textarea:not([inert]), button:not([inert]), iframe:not([inert]), audio:not([inert]), video:not([inert]), [tabindex]:not([inert]), [contenteditable="true"]:not([inert], [is]:defined:not([inert])';
const getCustomElements = () => Array.from(document.querySelectorAll(':defined'))
.filter(el => el.tagName.includes('-') || el.hasAttribute('is'));
function getOtherElements(modal) {
return [
...Array.from(document.body.querySelectorAll(tabElsSelector)),
...getCustomElements(modal),
].filter(el => ! (modal.isSameNode(el) || modal.contains(el) || el.contains(modal)));
}
export function toggleInert(modal, inert) {
if (inert) {
const els = getOtherElements(modal);
inertMap.set(modal, els);
els.forEach(el => el.inert = true);
} else if (inertMap.has(modal)) {
inertMap.get(modal).forEach(el => el.inert = false);
inertMap.delete(modal);
}
}
export function renable(modal) {
if (inertMap.has(modal)) {
toggleInert(modal, false);
inertMap.delete(modal);
return true;
} else {
return false;
}
}