Merge branch 'master' of https://github.com/Hrafven/based.cooking into Hrafven-master

This commit is contained in:
Luke Smith 2022-07-01 16:27:11 -04:00
commit 543658ab7a

View File

@ -27,16 +27,16 @@ document.addEventListener("DOMContentLoaded", () => {
search.addEventListener("input", () => { search.addEventListener("input", () => {
// grab search input value // grab search input value
const searchText = search.value.toLowerCase(); const searchText = search.value.toLowerCase().trim();
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 = recipeName.includes(searchText); const isMatch = searchText.split(' ').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);
}) })