Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exact match tags search #1538

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions _board/raspberry_pi_pico2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions assets/javascript/downloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down