heroweb/poc/in/assets/js/dropdown.js

34 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-09-02 05:28:06 +00:00
// Navbar notifications dropdown
if(document.querySelector("[dropdown-trigger]")){
var dropdown_triggers = document.querySelectorAll("[dropdown-trigger]");
dropdown_triggers.forEach((dropdown_trigger) => {
let dropdown_menu = dropdown_trigger.parentElement.querySelector("[dropdown-menu]");
dropdown_trigger.addEventListener("click", function () {
dropdown_menu.classList.toggle("opacity-0");
dropdown_menu.classList.toggle("pointer-events-none");
dropdown_menu.classList.toggle("before:-top-5");
dropdown_menu.classList.toggle("before:top-0");
if (dropdown_trigger.getAttribute("aria-expanded") == "false") {
dropdown_trigger.setAttribute("aria-expanded", "true");
dropdown_menu.classList.remove("transform-dropdown");
dropdown_menu.classList.add("transform-dropdown-show");
} else {
dropdown_trigger.setAttribute("aria-expanded", "false");
dropdown_menu.classList.remove("transform-dropdown-show");
dropdown_menu.classList.add("transform-dropdown");
}
});
window.addEventListener("click", function (e) {
if (!dropdown_menu.contains(e.target) && !dropdown_trigger.contains(e.target)) {
if (dropdown_trigger.getAttribute("aria-expanded") == "true") {
dropdown_trigger.click();
}
}
});
});
}