Skip to content

Commit

Permalink
Modified: comments for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
devCKVargas committed Jun 21, 2023
1 parent c5d1346 commit da56379
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions Projects/Natours/src/js/script.js
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;
}
}
}
});
});

0 comments on commit da56379

Please sign in to comment.