aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/app/index.html3
-rw-r--r--src/app/js/browser.js22
-rw-r--r--src/app/js/popups.js51
-rw-r--r--src/app/js/settings.js17
4 files changed, 63 insertions, 30 deletions
diff --git a/src/app/index.html b/src/app/index.html
index 810c205..ffb8699 100644
--- a/src/app/index.html
+++ b/src/app/index.html
@@ -30,7 +30,7 @@
</div>
</div>
- <div id="overlay" onclick="Browser.toggle(false);Settings.toggle(false)"></div>
+ <div id="overlay" onclick="popups.set_all(false)"></div>
<div class="popup" id="options">
<div class="misc">
<div style="width:100%"></div>
@@ -321,6 +321,7 @@
<script src="js/misc.js"></script>
<script src="js/mods.js"></script>
<script src="js/toast.js"></script>
+ <script src="js/popups.js"></script>
<script src="js/tooltip.js"></script>
<script src="js/browser.js"></script>
<script src="js/settings.js"></script>
diff --git a/src/app/js/browser.js b/src/app/js/browser.js
index cd162e6..7ca2729 100644
--- a/src/app/js/browser.js
+++ b/src/app/js/browser.js
@@ -87,28 +87,16 @@ var Browser = {
},
},
toggle: (state) => {
- if (state) {
- browser.scrollTo(0, 0);
- overlay.classList.add("shown");
- browser.classList.add("shown");
+ browser.scrollTo(0, 0);
+ popups.set("#browser", state);
+ if (state) {
if (browserEntries.querySelectorAll(".el").length == 0) {
Browser.loadfront();
}
- return
- } else if (! state) {
- if (state != undefined) {
- Browser.filters.toggle(false);
- overlay.classList.remove("shown");
- browser.classList.remove("shown");
- preview.classList.remove("shown");
- return
- }
+ } else if (state === false) {
+ Browser.filters.toggle(false);
}
-
- browser.scrollTo(0, 0);
- overlay.classList.toggle("shown");
- browser.classList.toggle("shown");
},
install: (package_obj, clear_queue = false) => {
return installFromURL(
diff --git a/src/app/js/popups.js b/src/app/js/popups.js
new file mode 100644
index 0000000..553358a
--- /dev/null
+++ b/src/app/js/popups.js
@@ -0,0 +1,51 @@
+let popups = {};
+
+popups.set = (popup, state, auto_close_all = true) => {
+ let popup_el = popup;
+
+ if (typeof popup == "string") {
+ popup_el = document.querySelector(popup);
+ }
+
+ if (! popup_el) {return false}
+
+ if (auto_close_all && overlay.classList.contains("shown")) {
+ popups.set_all(false, popup_el);
+ }
+
+ if (! state && state !== false) {
+ state = ! popup_el.classList.contains("shown");
+ }
+
+ if (state) {
+ overlay.classList.add("shown");
+ popup_el.classList.add("shown");
+ } else if (! state) {
+ overlay.classList.remove("shown");
+ popup_el.classList.remove("shown");
+ }
+}
+
+popups.show = (popup, auto_close_all = true) => {
+ return popups.set(popup, true, auto_close_all);
+}
+
+popups.hide = (popup, auto_close_all = true) => {
+ return popups.set(popup, false, auto_close_all);
+}
+
+popups.list = () => {
+ return document.querySelectorAll(".popup");
+}
+
+popups.set_all = (state, exclude_popup) => {
+ let popups_list = document.querySelectorAll(".popup.shown");
+
+ for (let i = 0; i < popups_list.length; i++) {
+ if (popups_list[i] == exclude_popup) {
+ continue;
+ }
+
+ popups.set(popups_list[i], false, false);
+ }
+}
diff --git a/src/app/js/settings.js b/src/app/js/settings.js
index 8aeb2ca..a333e8b 100644
--- a/src/app/js/settings.js
+++ b/src/app/js/settings.js
@@ -1,28 +1,21 @@
var Settings = {
toggle: (state) => {
+ Settings.load();
+ options.scrollTo(0, 0);
+
+ popups.set("#options", state);
let settings_btn = document.getElementById("settings");
if (state) {
- Settings.load();
- options.scrollTo(0, 0);
- overlay.classList.add("shown");
- options.classList.add("shown");
settings_btn.classList.add("shown");
-
return;
- } else if (! state) {
+ } else if (state === false) {
if (state != undefined) {
- overlay.classList.remove("shown");
- options.classList.remove("shown");
settings_btn.classList.remove("shown");
return;
}
}
- Settings.load();
- options.scrollTo(0, 0);
- overlay.classList.toggle("shown");
- options.classList.toggle("shown");
settings_btn.classList.toggle("shown");
},
apply: () => {