Skip to content

Commit

Permalink
Merge pull request #1541 from FoamyGuy/fix_filter_null_search
Browse files Browse the repository at this point in the history
fix filtering for null search term
  • Loading branch information
dhalbert authored Nov 22, 2024
2 parents 983f493 + 143529c commit 196fe9a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions assets/javascript/downloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,29 +351,35 @@ function filterResults() {
download.style.display = 'block';
board_count++;
// exact tag match re-order
let searched = downloadsSearch.searchTerm.toLowerCase();
let tags = download.getAttribute("data-tags").split(",");
if (tags.indexOf(searched) >= 0 ){
if (downloadsSearch.searchTerm !== null && downloadsSearch.searchTerm !== undefined) {
let searched = downloadsSearch.searchTerm.toLowerCase();
let tags = download.getAttribute("data-tags").split(",");
if (searched !== "" && tags.indexOf(searched) >= 0) {
let parent = download.parentElement;
parent.removeChild(download);
parent.prepend(download);

}
}
}
});
document.getElementById("board_count").innerHTML = board_count;
}

function handleSortResults(event) {
let searched = downloadsSearch.searchTerm.toLowerCase();
let searched;
if (downloadsSearch.searchTerm !== null && downloadsSearch.searchTerm !== undefined) {
searched = downloadsSearch.searchTerm.toLowerCase();
}
var sortType = event.target.value;
setURL('sort-by', sortType);
var downloads = document.querySelector('.downloads-section');
Array.prototype.slice.call(downloads.children)
.map(function (download) { return downloads.removeChild(download); })
.sort(function (a, b) {
// exact tag match re-order
if (a.dataset.tags.split(",").indexOf(searched) >= 0){
if (searched !== undefined && searched !== "" &&
a.dataset.tags.split(",").indexOf(searched) >= 0){

return -2;
}
switch(sortType) {
Expand Down

0 comments on commit 196fe9a

Please sign in to comment.