Repository navigation
Expand file tree
/
Copy pathshop.js
More file actions
134 lines (122 loc) · 3.77 KB
/
Copy pathshop.js
File metadata and controls
134 lines (122 loc) · 3.77 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
window.onload = function () {
var mobileMenu = document.querySelector(".mobile-menu");
var mobileMenuBtn = document.getElementById("mobile-menu-button");
var mobileCloseBtn = document.getElementById("mobile-close-button");
var overlay = document.getElementById("overlay");
var dropdownBtns = document.querySelectorAll("[data-dropdown]");
var mobileDropdownBtns = document.querySelectorAll(
"[data-mobile-dropdown]"
);
// Mobile menu toggle function
function toggleMobileMenu() {
if (mobileMenu.classList.contains("show")) {
mobileMenu.classList.remove("show");
overlay.classList.remove("show");
document.body.style.overflow = "";
} else {
mobileMenu.classList.add("show");
overlay.classList.add("show");
document.body.style.overflow = "hidden";
}
}
// Add click events for mobile menu
if (mobileMenuBtn) {
mobileMenuBtn.onclick = toggleMobileMenu;
}
if (mobileCloseBtn) {
mobileCloseBtn.onclick = toggleMobileMenu;
}
if (overlay) {
overlay.onclick = toggleMobileMenu;
}
// Handle desktop dropdowns
for (var i = 0; i < dropdownBtns.length; i++) {
(function (btn) {
var dropdownId = btn.getAttribute("data-dropdown");
var dropdown = document.getElementById(dropdownId + "-dropdown");
var icon = btn.querySelector(".fa-chevron-down");
btn.onclick = function (e) {
e = e || window.event;
if (e.stopPropagation) {
e.stopPropagation();
} else {
e.cancelBubble = true;
}
// Close all other dropdowns first
for (var j = 0; j < dropdownBtns.length; j++) {
var otherId = dropdownBtns[j].getAttribute("data-dropdown");
var otherDropdown = document.getElementById(
otherId + "-dropdown"
);
var otherIcon =
dropdownBtns[j].querySelector(".fa-chevron-down");
if (otherDropdown !== dropdown) {
otherDropdown.classList.remove("show");
if (otherIcon) {
otherIcon.style.transform = "";
}
}
}
// Toggle current dropdown
if (dropdown.classList.contains("show")) {
dropdown.classList.remove("show");
if (icon) {
icon.style.transform = "";
}
} else {
dropdown.classList.add("show");
if (icon) {
icon.style.transform = "rotate(180deg)";
}
}
};
})(dropdownBtns[i]);
}
// Handle mobile dropdowns
for (var i = 0; i < mobileDropdownBtns.length; i++) {
(function (btn) {
var dropdownId = btn.getAttribute("data-mobile-dropdown");
var dropdown = document.getElementById(dropdownId + "-dropdown");
var icon = btn.querySelector(".fa-chevron-down");
btn.onclick = function () {
if (dropdown.classList.contains("hidden")) {
dropdown.classList.remove("hidden");
if (icon) {
icon.style.transform = "rotate(180deg)";
}
} else {
dropdown.classList.add("hidden");
if (icon) {
icon.style.transform = "";
}
}
};
})(mobileDropdownBtns[i]);
}
// Close dropdowns when clicking outside
document.onclick = function () {
for (var i = 0; i < dropdownBtns.length; i++) {
var dropdownId = dropdownBtns[i].getAttribute("data-dropdown");
var dropdown = document.getElementById(dropdownId + "-dropdown");
var icon = dropdownBtns[i].querySelector(".fa-chevron-down");
if (dropdown.classList.contains("show")) {
dropdown.classList.remove("show");
if (icon) {
icon.style.transform = "";
}
}
}
};
// Handle window resize
var resizeTimer;
window.onresize = function () {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function () {
if (window.innerWidth >= 768) {
mobileMenu.classList.remove("show");
overlay.classList.remove("show");
document.body.style.overflow = "";
}
}, 250);
};
};