aboutsummaryrefslogtreecommitdiff
path: root/src/app
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2024-06-15 23:34:23 +0200
committer0neGal <mail@0negal.com>2024-06-15 23:34:37 +0200
commit6538b818302829f917fa636aa4d5678466841705 (patch)
tree97e5407c02b6e9ad52fecd509950d575ed96dead /src/app
parent77ffc7ae5b80565a5b05c0ba316c77320fcddf55 (diff)
downloadViper-6538b818302829f917fa636aa4d5678466841705.tar.gz
Viper-6538b818302829f917fa636aa4d5678466841705.zip
added launcher.relative_section()
This will be particularly useful for #239
Diffstat (limited to 'src/app')
-rw-r--r--src/app/js/launcher.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/app/js/launcher.js b/src/app/js/launcher.js
index 913762b..dc99792 100644
--- a/src/app/js/launcher.js
+++ b/src/app/js/launcher.js
@@ -163,6 +163,62 @@ launcher.show_ns = (section) => {
}
}
+// changes the active section on the currently active
+// `.contentContainer` in the direction specified
+//
+// `direction` can be: left or right
+launcher.relative_section = (direction) => {
+ // the `.contentMenu` in the currently active tab
+ let active_menu = document.querySelector(
+ ".contentContainer:not(.hidden) .contentMenu"
+ )
+
+ // get the currently active section
+ let active_section = active_menu.querySelector("[active]");
+
+ // no need to do anything, if there's somehow no active section
+ if (! active_section) {return}
+
+ // these will be filled out
+ let prev_section, next_section;
+
+ // get list of all the sections
+ let sections = active_menu.querySelectorAll("li");
+
+ for (let i = 0; i < sections.length; i++) {
+ if (sections[i] != active_section) {
+ continue;
+ }
+
+ // make `next_section` be the next element in `sections`
+ next_section = sections[i + 1];
+
+ // if we're at the first iteration, use the last element in
+ // `sections` as the previous section, otherwise make it the
+ // element before this iteration
+ if (i == 0) {
+ prev_section = sections[sections.length - 1];
+ } else {
+ prev_section = sections[i - 1];
+ }
+ }
+
+ // if we're going left, and a previous section was found, click it
+ if (direction == "left" && prev_section) {
+ prev_section.click();
+ } else if (direction == "right") {
+ // click the next section, if one was found, otherwise just
+ // assume that the first section is the next section, as the
+ // active section is likely just the last section, so we wrap
+ // around instead
+ if (next_section) {
+ next_section.click();
+ } else if (sections[0]) {
+ sections[0].click();
+ }
+ }
+}
+
launcher.check_servers = async () => {
serverstatus.classList.add("checking");