mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 11:59:23 +00:00
Move navbar script to dedicated file
This commit is contained in:
36
core/static/bundled/core/navbar-index.ts
Normal file
36
core/static/bundled/core/navbar-index.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { exportToHtml } from "#core:utils/globals";
|
||||
|
||||
exportToHtml("showMenu", () => {
|
||||
const navbar = document.getElementById("navbar-content");
|
||||
const current = navbar.getAttribute("mobile-display");
|
||||
navbar.setAttribute("mobile-display", current === "hidden" ? "revealed" : "hidden");
|
||||
});
|
||||
|
||||
document.addEventListener("alpine:init", () => {
|
||||
const menuItems = document.querySelectorAll(".navbar details[name='navbar'].menu");
|
||||
const isDesktop = () => {
|
||||
return window.innerWidth >= 500;
|
||||
};
|
||||
for (const item of menuItems) {
|
||||
item.addEventListener("mouseover", () => {
|
||||
if (isDesktop()) {
|
||||
item.setAttribute("open", "");
|
||||
}
|
||||
});
|
||||
item.addEventListener("mouseout", () => {
|
||||
if (isDesktop()) {
|
||||
item.removeAttribute("open");
|
||||
}
|
||||
});
|
||||
item.addEventListener("click", (event: MouseEvent) => {
|
||||
// Don't close when clicking on desktop mode
|
||||
if ((event.target as HTMLElement).nodeName !== "SUMMARY" || event.detail === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isDesktop()) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user