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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432/**
* App Filters - Client-side filtering and search for the /apps page
*/
(function () {
"use strict";
// DOM element cache
let elements = {};
let totalApps = 0;
/**
* Initialize the filtering functionality
*/
function init() {
// Only run on apps page - select the apps-grid inside apps-page-content
const appsGrid = document.querySelector(".apps-page-content .apps-grid");
if (!appsGrid) return;
// Cache all DOM elements
elements = {
appsGrid: appsGrid,
cards: document.querySelectorAll(".app-card"),
searchInput: document.getElementById("app-search"),
platformCheckboxes: document.querySelectorAll('input[name="platform"]'),
apiCheckboxes: document.querySelectorAll('input[name="api"]'),
ossCheckbox: document.getElementById("filter-oss"),
freeCheckbox: document.getElementById("filter-free"),
sortSelect: document.getElementById("sort-select"),
clearButton: document.getElementById("clear-filters"),
resultsCount: document.getElementById("results-count"),
emptyState: document.getElementById("empty-state"),
filterToggle: document.getElementById("filter-toggle"),
filterPanel: document.getElementById("filter-panel"),
filterCount: document.querySelector(".filter-count"),
};
totalApps = elements.cards.length;
// Apply initial filters from URL
const urlState = parseURL();
applyURLState(urlState);
// Bind event listeners
bindEvents();
// Handle placeholder text for mobile
handlePlaceholderResize();
window.addEventListener("resize", handlePlaceholderResize);
}
/**
* Handle search placeholder text based on screen size
*/
function handlePlaceholderResize() {
if (!elements.searchInput) return;
const isMobile = window.innerWidth < 768;
const mobilePlaceholder = elements.searchInput.dataset.placeholderMobile;
const desktopPlaceholder = elements.searchInput.getAttribute("placeholder");
if (isMobile && mobilePlaceholder) {
// Store desktop placeholder if not already stored
if (!elements.searchInput.dataset.placeholderDesktop) {
elements.searchInput.dataset.placeholderDesktop = desktopPlaceholder;
}
elements.searchInput.setAttribute("placeholder", mobilePlaceholder);
} else if (!isMobile && elements.searchInput.dataset.placeholderDesktop) {
elements.searchInput.setAttribute(
"placeholder",
elements.searchInput.dataset.placeholderDesktop
);
}
}
/**
* Bind all event listeners
*/
function bindEvents() {
// Search input with debouncing
let searchTimeout;
elements.searchInput.addEventListener("input", function () {
clearTimeout(searchTimeout);
searchTimeout = setTimeout(() => {
applyFilters();
}, 300);
});
// Platform checkboxes
elements.platformCheckboxes.forEach((checkbox) => {
checkbox.addEventListener("change", applyFilters);
});
// API checkboxes
elements.apiCheckboxes.forEach((checkbox) => {
checkbox.addEventListener("change", applyFilters);
});
// OSS checkbox
if (elements.ossCheckbox) {
elements.ossCheckbox.addEventListener("change", applyFilters);
}
// Free checkbox
if (elements.freeCheckbox) {
elements.freeCheckbox.addEventListener("change", applyFilters);
}
// Sort select
if (elements.sortSelect) {
elements.sortSelect.addEventListener("change", function () {
sortCards(this.value);
updateURL();
});
}
// Clear all button
elements.clearButton.addEventListener("click", clearFilters);
// Mobile filter toggle
if (elements.filterToggle) {
elements.filterToggle.addEventListener("click", toggleFilterPanel);
}
// Keyboard: Escape to close mobile filter panel
document.addEventListener("keydown", function (e) {
if (e.key === "Escape" && window.innerWidth <= 768) {
if (elements.filterPanel.classList.contains("filter-panel--expanded")) {
toggleFilterPanel();
}
}
});
}
/**
* Apply all active filters to the app cards
*/
function applyFilters() {
// Get current filter state
const searchQuery = elements.searchInput.value.toLowerCase().trim();
const selectedPlatforms = getCheckedValues(elements.platformCheckboxes);
const selectedAPIs = getCheckedValues(elements.apiCheckboxes);
const ossOnly = elements.ossCheckbox ? elements.ossCheckbox.checked : false;
const freeOnly = elements.freeCheckbox
? elements.freeCheckbox.checked
: false;
let visibleCount = 0;
// Filter each app card
elements.cards.forEach((card) => {
let matches = true;
// Platform filter (OR logic within category)
if (selectedPlatforms.length > 0) {
const cardPlatforms = (card.dataset.platforms || "").split(" ");
const hasMatchingPlatform = selectedPlatforms.some((platform) =>
cardPlatforms.includes(platform)
);
matches = matches && hasMatchingPlatform;
}
// API filter (OR logic within category)
if (matches && selectedAPIs.length > 0) {
const cardAPIs = (card.dataset.apis || "").split(" ");
const hasMatchingAPI = selectedAPIs.some((api) =>
cardAPIs.includes(api)
);
matches = matches && hasMatchingAPI;
}
// OSS filter (AND logic)
if (matches && ossOnly) {
matches = card.dataset.oss === "true";
}
// Free filter (AND logic)
if (matches && freeOnly) {
matches = card.dataset.free === "true";
}
// Search filter (AND logic, substring match in searchable text)
if (matches && searchQuery) {
const searchable = card.dataset.searchable || "";
matches = searchable.includes(searchQuery);
}
// Toggle visibility
if (matches) {
card.classList.remove("app-card--hidden");
visibleCount++;
} else {
card.classList.add("app-card--hidden");
}
});
// Update UI feedback
updateResultsCount(visibleCount);
updateURL();
}
/**
* Get checked values from a checkbox group
*/
function getCheckedValues(checkboxes) {
return Array.from(checkboxes)
.filter((cb) => cb.checked)
.map((cb) => cb.value);
}
/**
* Sort app cards by the specified criteria
*/
function sortCards(sortBy) {
const cards = Array.from(elements.cards);
cards.sort((a, b) => {
if (sortBy === "updated") {
const dateA = a.dataset.lastUpdated || "";
const dateB = b.dataset.lastUpdated || "";
// Empty strings (N/A) sort to end
if (!dateA && dateB) return 1;
if (dateA && !dateB) return -1;
if (!dateA && !dateB) {
// Both N/A: sort alphabetically by name
return (a.dataset.name || "").localeCompare(b.dataset.name || "");
}
// Both have dates: sort descending (newest first)
return dateB.localeCompare(dateA);
}
// Default: alphabetical by name
return (a.dataset.name || "").localeCompare(b.dataset.name || "");
});
// Re-append cards in new order
cards.forEach((card) => elements.appsGrid.appendChild(card));
}
/**
* Update the results count display
*/
function updateResultsCount(visibleCount) {
if (visibleCount === 0) {
elements.resultsCount.parentElement.style.display = "none";
elements.emptyState.style.display = "block";
} else {
elements.resultsCount.parentElement.style.display = "block";
elements.emptyState.style.display = "none";
if (visibleCount === totalApps) {
elements.resultsCount.textContent = `Showing all ${totalApps} apps`;
} else {
elements.resultsCount.textContent = `Showing ${visibleCount} of ${totalApps} apps`;
}
}
// Update mobile toggle button count
if (elements.filterCount) {
elements.filterCount.textContent = visibleCount;
}
}
/**
* Clear all filters
*/
function clearFilters() {
// Clear search
elements.searchInput.value = "";
// Uncheck all checkboxes
elements.platformCheckboxes.forEach((cb) => (cb.checked = false));
elements.apiCheckboxes.forEach((cb) => (cb.checked = false));
if (elements.ossCheckbox) {
elements.ossCheckbox.checked = false;
}
if (elements.freeCheckbox) {
elements.freeCheckbox.checked = false;
}
// Reset sort to default
if (elements.sortSelect) {
elements.sortSelect.value = "updated";
sortCards("updated");
}
// Apply filters (will show all apps)
applyFilters();
// Focus search input for better UX
elements.searchInput.focus();
}
/**
* Toggle mobile filter panel visibility
*/
function toggleFilterPanel() {
const isExpanded = elements.filterPanel.classList.contains(
"filter-panel--expanded"
);
if (isExpanded) {
elements.filterPanel.classList.remove("filter-panel--expanded");
elements.filterToggle.setAttribute("aria-expanded", "false");
elements.filterToggle.innerHTML = `<i class="fas fa-filter"></i> Filter & Search (<span class="filter-count">${elements.filterCount.textContent}</span> apps)`;
} else {
elements.filterPanel.classList.add("filter-panel--expanded");
elements.filterToggle.setAttribute("aria-expanded", "true");
elements.filterToggle.innerHTML =
'<i class="fas fa-times"></i> Hide Filters';
}
}
/**
* Parse URL parameters into filter state
*/
function parseURL() {
const params = new URLSearchParams(window.location.search);
return {
platforms: params.has("platform")
? params.get("platform").split(",")
: [],
apis: params.has("api") ? params.get("api").split(",") : [],
oss: params.get("oss") === "true",
free: params.get("free") === "true",
search: params.get("q") || "",
sort: params.get("sort") || "updated",
};
}
/**
* Apply filter state from URL
*/
function applyURLState(state) {
// Set search input
if (state.search) {
elements.searchInput.value = state.search;
}
// Check platform checkboxes
state.platforms.forEach((platform) => {
const checkbox = Array.from(elements.platformCheckboxes).find(
(cb) => cb.value === platform
);
if (checkbox) checkbox.checked = true;
});
// Check API checkboxes
state.apis.forEach((api) => {
const checkbox = Array.from(elements.apiCheckboxes).find(
(cb) => cb.value === api
);
if (checkbox) checkbox.checked = true;
});
// Set OSS checkbox
if (elements.ossCheckbox && state.oss) {
elements.ossCheckbox.checked = true;
}
// Set Free checkbox
if (elements.freeCheckbox && state.free) {
elements.freeCheckbox.checked = true;
}
// Set sort select and apply sort
if (elements.sortSelect && state.sort) {
elements.sortSelect.value = state.sort;
sortCards(state.sort);
} else if (elements.sortSelect) {
// Apply default sort when no URL state
sortCards("updated");
}
// Apply filters immediately
applyFilters();
}
/**
* Update URL with current filter state
*/
function updateURL() {
const params = new URLSearchParams();
// Add platform params
const selectedPlatforms = getCheckedValues(elements.platformCheckboxes);
if (selectedPlatforms.length > 0) {
params.set("platform", selectedPlatforms.join(","));
}
// Add API params
const selectedAPIs = getCheckedValues(elements.apiCheckboxes);
if (selectedAPIs.length > 0) {
params.set("api", selectedAPIs.join(","));
}
// Add OSS param
if (elements.ossCheckbox && elements.ossCheckbox.checked) {
params.set("oss", "true");
}
// Add Free param
if (elements.freeCheckbox && elements.freeCheckbox.checked) {
params.set("free", "true");
}
// Add search param
const searchQuery = elements.searchInput.value.trim();
if (searchQuery) {
params.set("q", searchQuery);
}
// Add sort param (only if not default)
if (elements.sortSelect && elements.sortSelect.value !== "updated") {
params.set("sort", elements.sortSelect.value);
}
// Update URL without reload
const newURL = params.toString()
? `${window.location.pathname}?${params.toString()}`
: window.location.pathname;
window.history.pushState({}, "", newURL);
}
// Initialize when DOM is ready
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", init);
} else {
init();
}
})();