mirror of
https://github.com/LukeSmithxyz/based.cooking.git
synced 2025-01-21 08:11:59 +00:00
clean up again & just compute searchText.split(" ") once (#805)
This commit is contained in:
parent
23cc99feef
commit
0124077e9d
@ -28,15 +28,16 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
search.addEventListener("input", () => {
|
search.addEventListener("input", () => {
|
||||||
// grab search input value
|
// grab search input value
|
||||||
const searchText = search.value.toLowerCase().trim();
|
const searchText = search.value.toLowerCase().trim();
|
||||||
|
const searchTerms = searchText.split(" ");
|
||||||
const hasFilter = searchText.length > 0;
|
const hasFilter = searchText.length > 0;
|
||||||
|
|
||||||
artlist.classList.toggle("list-searched", hasFilter);
|
artlist.classList.toggle("list-searched", hasFilter);
|
||||||
|
|
||||||
// for each recipe hide all but matched
|
// for each recipe hide all but matched
|
||||||
let matchCount = 0;
|
|
||||||
recipes.forEach(recipe => {
|
recipes.forEach(recipe => {
|
||||||
const recipeName = recipe.textContent.toLowerCase();
|
const recipeName = recipe.textContent.toLowerCase();
|
||||||
const isMatch = searchText.split(' ').every(term => recipeName.includes(term));
|
const isMatch = searchTerms.every(term => recipeName.includes(term));
|
||||||
|
|
||||||
recipe.hidden = !isMatch;
|
recipe.hidden = !isMatch;
|
||||||
recipe.classList.toggle("matched-recipe", hasFilter && isMatch);
|
recipe.classList.toggle("matched-recipe", hasFilter && isMatch);
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user