aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2024-06-15 23:18:00 +0200
committer0neGal <mail@0negal.com>2024-06-15 23:18:00 +0200
commit77ffc7ae5b80565a5b05c0ba316c77320fcddf55 (patch)
treef2fbbc83369da6659913f2f68987ce1bfbc55f43
parent384977de2f89cdd26e15adc1f274bf46b3c7a03e (diff)
downloadViper-77ffc7ae5b80565a5b05c0ba316c77320fcddf55.tar.gz
Viper-77ffc7ae5b80565a5b05c0ba316c77320fcddf55.zip
added popups.hide_last() and popups.open_list
This will be particularly useful for #239
-rw-r--r--src/app/js/browser.js4
-rw-r--r--src/app/js/dom_events.js4
-rw-r--r--src/app/js/popups.js49
3 files changed, 51 insertions, 6 deletions
diff --git a/src/app/js/browser.js b/src/app/js/browser.js
index 21bdf3f..7dc84d9 100644
--- a/src/app/js/browser.js
+++ b/src/app/js/browser.js
@@ -358,10 +358,10 @@ if (navigator.onLine) {
var view = document.querySelector(".popup#preview webview");
browser.preview = {
show: () => {
- preview.classList.add("shown");
+ popups.show(preview, false);
},
hide: () => {
- preview.classList.remove("shown");
+ popups.hide(preview, false);
},
set: (url, autoshow) => {
if (autoshow != false) {browser.preview.show()}
diff --git a/src/app/js/dom_events.js b/src/app/js/dom_events.js
index c16a838..ab79c57 100644
--- a/src/app/js/dom_events.js
+++ b/src/app/js/dom_events.js
@@ -1,3 +1,4 @@
+const popups = require("./popups");
const settings = require("./settings");
let drag_timer;
@@ -27,8 +28,7 @@ document.addEventListener("drop", (e) => {
document.body.addEventListener("keyup", (e) => {
if (e.key == "Escape") {
- browser.toggle(false);
- settings.popup.toggle(false);
+ popups.hide_last();
}
})
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;