-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified: comments for better readability
- Loading branch information
1 parent
c5d1346
commit da56379
Showing
1 changed file
with
10 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,31 @@ | ||
"use strict"; | ||
|
||
//$ Select HTML elements | ||
//? Select HTML elements | ||
const popup = document.querySelector(".popup__content"); | ||
const navContainer = document.querySelector(".navigation__list"); | ||
const navMenu = document.getElementById("navi-toggle"); | ||
const navLinks = document.querySelectorAll(".navigation__link"); //$ 0️⃣ | ||
const navLinks = document.querySelectorAll(".navigation__link"); // 0️⃣ | ||
|
||
//$ Event listener for clicking anywhere on the DOM | ||
//? Event listener for clicking anywhere on the DOM | ||
document.addEventListener("click", (event) => { | ||
//$ if clicked element is not a child of popup__content && when URL includes #popup | ||
// if clicked element is not a child of popup__content && when URL includes #popup | ||
if (!popup.contains(event.target) && window.location.href.includes("#popup")) { | ||
//$ close popup | ||
//$ closing animation still plays | ||
//$ since there is no #popup-closed in HTML | ||
// close popup | closing animation still plays since there is no #popup-closed in HTML | ||
window.location.href = "#closed"; | ||
} | ||
|
||
//$ if clicked target is not a child of navMenu | ||
// if clicked target is not a child of navMenu | ||
if (!navMenu.contains(event.target)) { | ||
navMenu.addEventListener("click", () => { | ||
navMenu.checked = !navMenu.checked; | ||
}); | ||
//$ extract links from navLinks array 0️⃣ | ||
|
||
// extract links from navLinks array 0️⃣ | ||
for (const link of navLinks) { | ||
//$ if clicked target is not any link | ||
// close navMenu if clicked target is not any link | ||
if (!link.contains(event.target)) { | ||
//$ close navMenu | ||
navMenu.checked = false; | ||
} | ||
} | ||
} | ||
}); | ||
}); |