Merge pull request #1538 from FoamyGuy/search_exact_tags
exact match tags search
This commit is contained in:
commit
f8d24c1f3f
2 changed files with 16 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue