mirror of
https://github.com/privacyguides/privacyguides.org.git
synced 2024-09-16 22:43:23 +00:00
28 lines
691 B
JavaScript
28 lines
691 B
JavaScript
|
//
|
||
|
// Navbar dropdowns
|
||
|
//
|
||
|
|
||
|
const navSections = document.querySelectorAll(".nav-details");
|
||
|
|
||
|
navSections.forEach(navSection => {
|
||
|
navSection.addEventListener("toggle", navSectionsToggle);
|
||
|
});
|
||
|
document.addEventListener("click", navSectionsClose);
|
||
|
|
||
|
function navSectionsToggle() {
|
||
|
// When opening next dropdown, hide previous
|
||
|
if (this.open) {
|
||
|
navSections.forEach(navSection => {
|
||
|
if (navSection != this && navSection.open) navSection.open = !open;
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function navSectionsClose(event) {
|
||
|
// Hide all dropdowns when clicking in different place
|
||
|
if (event.target.matches(".nav-summary")) return;
|
||
|
navSections.forEach(navSection => {
|
||
|
navSection.open = !open;
|
||
|
});
|
||
|
}
|