Skip to content

Commit 196fe9a

Browse files
authored
Merge pull request adafruit#1541 from FoamyGuy/fix_filter_null_search
fix filtering for null search term
2 parents 983f493 + 143529c commit 196fe9a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

assets/javascript/downloads.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,29 +351,35 @@ function filterResults() {
351351
download.style.display = 'block';
352352
board_count++;
353353
// exact tag match re-order
354-
let searched = downloadsSearch.searchTerm.toLowerCase();
355-
let tags = download.getAttribute("data-tags").split(",");
356-
if (tags.indexOf(searched) >= 0 ){
354+
if (downloadsSearch.searchTerm !== null && downloadsSearch.searchTerm !== undefined) {
355+
let searched = downloadsSearch.searchTerm.toLowerCase();
356+
let tags = download.getAttribute("data-tags").split(",");
357+
if (searched !== "" && tags.indexOf(searched) >= 0) {
357358
let parent = download.parentElement;
358359
parent.removeChild(download);
359360
parent.prepend(download);
360-
361+
}
361362
}
362363
}
363364
});
364365
document.getElementById("board_count").innerHTML = board_count;
365366
}
366367

367368
function handleSortResults(event) {
368-
let searched = downloadsSearch.searchTerm.toLowerCase();
369+
let searched;
370+
if (downloadsSearch.searchTerm !== null && downloadsSearch.searchTerm !== undefined) {
371+
searched = downloadsSearch.searchTerm.toLowerCase();
372+
}
369373
var sortType = event.target.value;
370374
setURL('sort-by', sortType);
371375
var downloads = document.querySelector('.downloads-section');
372376
Array.prototype.slice.call(downloads.children)
373377
.map(function (download) { return downloads.removeChild(download); })
374378
.sort(function (a, b) {
375379
// exact tag match re-order
376-
if (a.dataset.tags.split(",").indexOf(searched) >= 0){
380+
if (searched !== undefined && searched !== "" &&
381+
a.dataset.tags.split(",").indexOf(searched) >= 0){
382+
377383
return -2;
378384
}
379385
switch(sortType) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy