Merge pull request #1538 from FoamyGuy/search_exact_tags

exact match tags search
This commit is contained in:
Dan Halbert 2024-11-18 19:40:10 -05:00 committed by GitHub
commit f8d24c1f3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View file

@ -10,6 +10,8 @@ board_url:
board_image: "raspberry_pi_pico2.jpg"
date_added: 2024-08-08
family: raspberrypi
tags:
- pico 2
features:
- Breadboard-Friendly
- Castellated Pads

View file

@ -350,18 +350,32 @@ function filterResults() {
} else {
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 ){
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();
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){
return -2;
}
switch(sortType) {
case 'alpha-asc':
return a.dataset.name.localeCompare(b.dataset.name);