-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
34 lines (30 loc) · 1.01 KB
/
popup.js
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
// Todo: Make system more modular
let currentPopup;
const Popup = {
popups: new Map,
shade: null,
current() { return currentPopup; },
showPopup(name, state = true) {
if(state) Popup.hideAllPopups();
document.body.toggleAttribute("obscured", state);
let popup = Popup.popups.get(name);
popup.toggleAttribute("shown", state);
currentPopup = popup;
Popup.shade.toggleAttribute("shown", state);
},
hidePopup(name) {
Popup.showPopup(name, false)
currentPopup = null;
},
hideAllPopups() {
Popup.popups.forEach((key, value) => Popup.hidePopup(value));
}
}
document.addEventListener('DOMContentLoaded', function () {
Popup.shade = document.createElement("div");
Popup.shade.classList.add("shadeBehindPopup");
Popup.shade.toggleAttribute("shown", false);
Popup.shade.addEventListener("click", Popup.hideAllPopups);
document.body.appendChild(Popup.shade);
})
export default Popup;