-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.js
More file actions
50 lines (39 loc) · 1.46 KB
/
Copy pathscript.js
File metadata and controls
50 lines (39 loc) · 1.46 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
/**
* PulseForge — homepage script.
* Handles the mobile nav toggle and the live tool search/filter.
*/
(function () {
pfInitMobileNav();
// --- Tool search -------------------------------------------------------
const searchInput = document.getElementById("toolSearch");
const toolGrid = document.querySelector("[data-tool-grid]");
const emptyState = document.querySelector("[data-empty-state]");
const searchMeta = document.querySelector("[data-search-meta]");
if (!searchInput || !toolGrid) return;
const cards = Array.from(toolGrid.querySelectorAll(".tool-card"));
function updateMeta(count) {
if (!searchMeta) return;
searchMeta.textContent = count === 1 ? "1 tool available" : `${count} tools available`;
}
function filterTools(rawQuery) {
const query = rawQuery.trim().toLowerCase();
let visibleCount = 0;
cards.forEach((card) => {
const haystack = [
card.dataset.title || "",
card.dataset.description || "",
card.dataset.tags || "",
]
.join(" ")
.toLowerCase();
const matches = query === "" || haystack.includes(query);
card.hidden = !matches;
if (matches) visibleCount += 1;
});
if (emptyState) emptyState.classList.toggle("is-visible", visibleCount === 0);
updateMeta(visibleCount);
}
searchInput.addEventListener("input", pfDebounce((e) => filterTools(e.target.value), 120));
// Initial count on load.
updateMeta(cards.length);
})();