Dropdown fix
This commit is contained in:
parent
b1d97ad6b2
commit
6206dea011
1 changed files with 20 additions and 0 deletions
20
app.js
20
app.js
|
|
@ -35,6 +35,8 @@ form.addEventListener("submit", saveRoute);
|
|||
cancelEditButton.addEventListener("click", resetForm);
|
||||
clearAllButton?.addEventListener("click", removeAllRoutes);
|
||||
routesList.addEventListener("click", handleRouteAction);
|
||||
document.addEventListener("click", closeMenusOnOutsideClick);
|
||||
document.addEventListener("keydown", closeMenusOnEscape);
|
||||
|
||||
if (sessionStorage.getItem(AUTH_SESSION_KEY) === "yes") {
|
||||
unlockApp();
|
||||
|
|
@ -168,6 +170,24 @@ function renderRoutes() {
|
|||
}
|
||||
}
|
||||
|
||||
function closeMenusOnOutsideClick(event) {
|
||||
if (event.target.closest(".route-menu")) {
|
||||
return;
|
||||
}
|
||||
|
||||
closeRouteMenus();
|
||||
}
|
||||
|
||||
function closeMenusOnEscape(event) {
|
||||
if (event.key === "Escape") {
|
||||
closeRouteMenus();
|
||||
}
|
||||
}
|
||||
|
||||
function closeRouteMenus() {
|
||||
document.querySelectorAll(".route-menu[open]").forEach((menu) => menu.removeAttribute("open"));
|
||||
}
|
||||
|
||||
function handleRouteAction(event) {
|
||||
const button = event.target.closest("button");
|
||||
if (!button) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue