diff options
author | 0neGal <mail@0negal.com> | 2024-06-15 23:34:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-15 23:34:53 +0200 |
commit | 938362cc27682f976cfbe16d7c4f898485e893c4 (patch) | |
tree | 1774a947415b34ffe06a033f6df15583361dd004 /src/app/js/popups.js | |
parent | 5f3259f5b62609e57468592dfaf7b1bd9b6f0bad (diff) | |
parent | 6538b818302829f917fa636aa4d5678466841705 (diff) | |
download | Viper-938362cc27682f976cfbe16d7c4f898485e893c4.tar.gz Viper-938362cc27682f976cfbe16d7c4f898485e893c4.zip |
Merge branch 'main' into gamepad-support
Diffstat (limited to 'src/app/js/popups.js')
-rw-r--r-- | src/app/js/popups.js | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/src/app/js/popups.js b/src/app/js/popups.js index 10c6995..62176a6 100644 --- a/src/app/js/popups.js +++ b/src/app/js/popups.js @@ -14,15 +14,19 @@ popups.set = (popup, state, auto_close_all = true) => { } if (! state && state !== false) { - state = ! popup_el.classList.contains("shown"); + state = ! open_list.includes(popup_el); } if (state) { + popups.open_list.add(popup_el); overlay.classList.add("shown"); popup_el.classList.add("shown"); } else if (! state) { - overlay.classList.remove("shown"); + popups.open_list.remove(popup_el); popup_el.classList.remove("shown"); + if (! open_list.length) { + overlay.classList.remove("shown"); + } } events.emit("popup-changed", { @@ -55,4 +59,45 @@ popups.set_all = (state = false, exclude_popup) => { } } +// attempts to hide just the last shown popup +popups.hide_last = () => { + if (open_list.length) { + popups.hide(open_list[open_list.length - 1], false); + } +} + +let open_list = []; +popups.open_list = () => { + return open_list; +} + +popups.open_list.remove = (el) => { + // no need to do anything if `el` isn't even in `open_list` + if (! open_list.includes(el)) { + return; + } + + // filtered list + let list = []; + + // run through open popups + for (let i = 0; i < open_list.length; i++) { + // add popup to `list` if it isn't `el` + if (open_list[i] != el && el.classList.contains("shown")) { + list.push(open_list[i]); + } + } + + // set `open_list` to the now filtered `list` + open_list = list; +} + +popups.open_list.add = (el) => { + // make sure the `el` isn't already in the list + popups.open_list.remove(el); + + // add `el` to the end of the list + open_list.push(el); +} + module.exports = popups; |