mirror of
https://github.com/ianramzy/decentralized-video-chat.git
synced 2024-11-27 20:49:21 +08:00
35 lines
1.1 KiB
JavaScript
Executable File
35 lines
1.1 KiB
JavaScript
Executable File
(function () {
|
|
"use strict";
|
|
const navToggle = document.getElementById("header-nav-toggle");
|
|
const mainNav = document.getElementById("header-nav");
|
|
|
|
if (navToggle) {
|
|
// Open menu
|
|
navToggle.addEventListener("click", function () {
|
|
document.body.classList.toggle("off-nav-is-active");
|
|
mainNav.classList.toggle("is-active");
|
|
if (mainNav.style.maxHeight) {
|
|
mainNav.style.maxHeight = null;
|
|
} else {
|
|
mainNav.style.maxHeight = mainNav.scrollHeight + "px";
|
|
}
|
|
this.getAttribute("aria-expanded") === "true"
|
|
? this.setAttribute("aria-expanded", "false")
|
|
: this.setAttribute("aria-expanded", "true");
|
|
});
|
|
// Close menu
|
|
document.addEventListener("click", function (e) {
|
|
if (
|
|
e.target !== mainNav &&
|
|
e.target !== navToggle &&
|
|
!mainNav.contains(e.target)
|
|
) {
|
|
document.body.classList.remove("off-nav-is-active");
|
|
mainNav.classList.remove("is-active");
|
|
mainNav.style.maxHeight = null;
|
|
navToggle.setAttribute("aria-expanded", "false");
|
|
}
|
|
});
|
|
}
|
|
})();
|