-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
161 lines (135 loc) · 3.98 KB
/
Copy pathscript.js
File metadata and controls
161 lines (135 loc) · 3.98 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// DOM Elements
const selectTrigger = document.querySelector(".select-trigger");
const dropdown = document.querySelector(".dropdown");
const selectedOption = document.querySelector(".selected-option");
const searchInput = document.getElementById("searchInput");
const optionsContainer = document.querySelector(".options-container");
const options = document.querySelectorAll(".option");
const noResults = document.querySelector(".no-results");
// Toggle Dropdown
selectTrigger.addEventListener("click", function (e) {
toggleDropdown();
});
function toggleDropdown() {
selectTrigger.classList.toggle("active");
dropdown.classList.toggle("active");
if (dropdown.classList.contains("active")) {
searchInput.focus();
resetAnimations();
} else {
searchInput.value = "";
filterOptions("");
}
}
// Reset animations when dropdown opens
function resetAnimations() {
return;
}
// Option Selection
options.forEach((option) => {
option.addEventListener("click", function (e) {
e.stopPropagation();
const href = this.getAttribute("data-href");
if (href) {
const resolvedHref = new URL(href, window.location.href).toString();
window.location.assign(resolvedHref);
return;
}
// Remove selected class from all options
options.forEach((opt) => opt.classList.remove("selected"));
// Add selected class to clicked option
this.classList.add("selected");
// Update selected option display
const icon = this.getAttribute("data-icon");
const text = this.querySelector("span").textContent;
const iconColor = this.querySelector("i").style.color;
selectedOption.innerHTML = `
<i class="fas ${icon}" style="color: ${iconColor};"></i>
<span>${text}</span>
`;
// Close dropdown
setTimeout(() => {
toggleDropdown();
}, 300);
});
});
// Live Search Functionality
searchInput.addEventListener("input", function (e) {
const searchTerm = e.target.value.toLowerCase();
filterOptions(searchTerm);
});
function filterOptions(searchTerm) {
let visibleCount = 0;
options.forEach((option) => {
const text = option.querySelector("span").textContent.toLowerCase();
if (text.includes(searchTerm)) {
option.classList.remove("hidden");
visibleCount++;
} else {
option.classList.add("hidden");
}
});
// Show/hide no results message
if (visibleCount === 0) {
noResults.classList.add("show");
optionsContainer.style.display = "none";
} else {
noResults.classList.remove("show");
optionsContainer.style.display = "block";
}
}
// Click Outside to Close
document.addEventListener("click", function (e) {
if (!e.target.closest(".custom-select")) {
selectTrigger.classList.remove("active");
dropdown.classList.remove("active");
searchInput.value = "";
filterOptions("");
}
});
// Keyboard Support (ESC to close)
document.addEventListener("keydown", function (e) {
if (e.key === "Escape" && dropdown.classList.contains("active")) {
toggleDropdown();
}
});
// Prevent dropdown close on search input click
searchInput.addEventListener("click", function (e) {
e.stopPropagation();
});
// Touch Support for Mobile
let touchStartY = 0;
let touchEndY = 0;
dropdown.addEventListener(
"touchstart",
function (e) {
touchStartY = e.changedTouches[0].screenY;
},
{ passive: true }
);
dropdown.addEventListener(
"touchend",
function (e) {
touchEndY = e.changedTouches[0].screenY;
handleSwipe();
},
{ passive: true }
);
function handleSwipe() {
if (touchEndY > touchStartY + 50) {
toggleDropdown();
}
}
// Initial setup
window.addEventListener("load", function () {
document.querySelector(".hero-shell").style.animation = "fadeIn 0.4s ease";
});
// Console Easter Egg
console.log(
"%c Custom Select Menu",
"font-size: 20px; font-weight: bold; color: #667eea;"
);
console.log(
"%cFeatures: Glassmorphism | Live Search | Ripple Effects | Responsive Design",
"font-size: 12px; color: #888;"
);