Skip to content

Commit

Permalink
Merge branch 'main' into gamepad-support
Browse files Browse the repository at this point in the history
  • Loading branch information
0neGal authored Jun 15, 2024
2 parents 5f3259f + 6538b81 commit 938362c
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/app/js/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Expand Down
4 changes: 2 additions & 2 deletions src/app/js/dom_events.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const popups = require("./popups");
const settings = require("./settings");

let drag_timer;
Expand Down Expand Up @@ -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();
}
})

Expand Down
56 changes: 56 additions & 0 deletions src/app/js/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
49 changes: 47 additions & 2 deletions src/app/js/popups.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down Expand Up @@ -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;

0 comments on commit 938362c

Please sign in to comment.