forked from livebloggerofficial/Modern-AppDev-Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
52 lines (43 loc) · 1.43 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const menuIcon = document.querySelector(".menu-icon");
const closeIcon = document.querySelector(".close-icon");
const mobileMenuItems = document.querySelector(".mobile-menu-items");
const allMobileMenuLinks = document.querySelectorAll(".mobile-menu-items a");
const searchContainer = document.querySelector(".search-container");
const searchIcons = document.querySelectorAll(".search-icon");
const searchInput = document.querySelector(
".search-input-container input[type='text']"
);
const searchInputContainer = document.querySelector(".search-input-container");
menuIcon.addEventListener("click", () => {
mobileMenuItems.classList.add("active");
});
closeIcon.addEventListener("click", () => {
mobileMenuItems.classList.remove("active");
});
allMobileMenuLinks.forEach((l) => {
l.addEventListener("click", () => {
mobileMenuItems.classList.remove("active");
});
});
// Search icon
searchIcons.forEach((searchIcon) => {
searchIcon.addEventListener("click", () => {
searchContainer.classList.add("active");
searchInput.focus();
});
});
document.addEventListener("keydown", (e) => {
if (e.key === "Escape") {
searchContainer.classList.remove("active");
searchInput.value = "";
}
});
document.addEventListener("click", (e) => {
if (
e.target.closest(".search-input-container") ||
e.target.closest(".search-icon")
)
return;
searchContainer.classList.remove("active");
searchInput.value = "";
});