Browse Source
This file contains the code for the filtering feature in pages.html and archive.html -- a basic search feature which works by filtering the list of entries on the page. It was originally in main.js but I moved it here because it was producing errors on pages which didn't have the filer stuff on the HTML template. This change allows each template to call it when the template actually uses it.stable
Craig Oates
2 years ago
1 changed files with 18 additions and 0 deletions
@ -0,0 +1,18 @@
|
||||
window.addEventListener("load", () => { |
||||
// (A) GET HTML ELEMENTS
|
||||
var filter = document.getElementById("fe-search-filter"), // search box
|
||||
list = document.querySelectorAll("#fe-search-filter-list li"); // all list items
|
||||
|
||||
// (B) ATTACH KEY UP LISTENER TO SEARCH BOX
|
||||
filter.onkeyup = () => { |
||||
// (B1) GET CURRENT SEARCH TERM
|
||||
let search = filter.value.toLowerCase(); |
||||
|
||||
// (B2) LOOP THROUGH LIST ITEMS - ONLY SHOW THOSE THAT MATCH SEARCH
|
||||
for (let i of list) { |
||||
let item = i.innerHTML.toLowerCase(); |
||||
if (item.indexOf(search) == -1) { i.classList.add("hide"); } |
||||
else { i.classList.remove("hide"); } |
||||
} |
||||
}; |
||||
}); |
Loading…
Reference in new issue