sidebar: add event delegation

This commit is contained in:
2026-06-03 04:37:05 +07:00
parent 42429b1509
commit 65f306523a
12 changed files with 192 additions and 7 deletions
@@ -55,3 +55,34 @@ document.addEventListener("DOMContentLoaded", function () {
document.getElementById("products").classList.add("active");
}
});
// SIDEBAR
document.addEventListener("click", function (e) {
const sidebar = document.getElementById("sidebar");
const overlay = document.getElementById("sidebarOverlay");
const floatingMenuBtn = document.getElementById("floatingMenuBtn");
if (!sidebar) return;
const isOpenTrigger =
e.target.closest("#floatingMenuBtn") ||
e.target.closest(".mobile-menu-btn");
const isCloseTrigger =
e.target.closest(".close-sidebar") ||
e.target.closest("#sidebarOverlay") ||
e.target.closest(".sidebar-nav .nav-link");
if (isOpenTrigger) {
sidebar.classList.add("open");
overlay.style.display = "block";
document.body.style.overflow = "hidden";
floatingMenuBtn.style.display = "none";
}
if (isCloseTrigger) {
sidebar.classList.remove("open");
overlay.style.display = "none";
document.body.style.overflow = "";
floatingMenuBtn.style.display = "flex";
}
});