Skip to content

Commit

Permalink
add optional chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
bjohansebas committed Sep 10, 2024
1 parent 146c049 commit f3e40af
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions js/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const mobileScreen = window.matchMedia("(max-width: 1064px)");
let isSmallScreen = false;

mobileScreen.addEventListener("change", (event) => {
mobileScreen?.addEventListener("change", (event) => {
if (event.matches) {
isSmallScreen = true;
} else {
Expand Down Expand Up @@ -38,7 +38,6 @@ for (const el of $itemsMenu) {
// Mobile Menu

const $linkItemsMenu = document.querySelectorAll(".submenu > a");
const $linkItemsContentMenu = document.querySelectorAll(".submenu-content a");
const $menu = document.querySelector("#navmenu");
const $overlay = document.querySelector("#overlay");

Expand All @@ -54,20 +53,20 @@ for (const el of $linkItemsMenu) {
});
}

document.querySelector("#nav-button").addEventListener("click", () => {
$menu.classList.toggle("opens");
$overlay.classList.toggle("blurs");
document.querySelector("#nav-button")?.addEventListener("click", () => {
$menu?.classList.toggle("opens");
$overlay?.classList.toggle("blurs");
document.body.classList.toggle("no-scroll")
});

// close mobile menu
$overlay.addEventListener("click", () => {
$menu.classList.remove("opens");
$overlay.classList.remove("blurs");
$overlay?.addEventListener("click", () => {
$menu?.classList.remove("opens");
$overlay?.classList.remove("blurs");
document.body.classList.remove("no-scroll")
});

// hilight the menu item of the current page
document
.querySelector(`.submenu-content a[href="${document.location.pathname}"]`)
.classList.add("current");
?.classList.add("current");

0 comments on commit f3e40af

Please sign in to comment.