fixed the search thingy

This commit is contained in:
Tim Krehan 2019-05-24 09:41:25 +02:00
parent 358d97826d
commit 086970c4da

View file

@ -1,30 +1,29 @@
$(document).ready(function () {
var recipes = $("#recipes a");
var headerLetters = $("#recipes h2");
$("#search-recipes").on("keyup", searchRecipe(recipes, headerLetters));
$("#search-recipes").on("keyup", searchRecipe);
$("#clear-search-string").click(clearSearchString);
});
function searchRecipe(recipes, headerLetters) {
return function () {
var search = $("#search-recipes").val().toUpperCase();
function searchRecipe() {
var searchString = $("#search-recipes").val().toUpperCase();
var recipes = $("#recipes a");
for (var i = 0; i < recipes.length; i++) {
if (recipes[i].innerHTML.toUpperCase().indexOf(search) > -1) {
recipes[i].style.display = "";
if (recipes[i].innerHTML.toUpperCase().indexOf(searchString) > -1) {
$(recipes[i]).show()
}
else {
recipes[i].style.display = "none";
$(recipes[i]).hide();
}
}
for (var j = 0; j < headerLetters.length; j++) {
if (($("*[data-letter='" + headerLetters[j].innerHTML + "']:visible")).length > 0) {
headerLetters[j].style.display = "";
$("#recipes").children().each(index => {
var container = ($("#recipes").children())[index];
$(container).removeClass("d-none").addClass("d-flex");
if(($(container).find("a:visible")).length==0){
$(container).removeClass("d-flex").addClass("d-none");
}
else {
headerLetters[j].style.display = "none";
}
}
};
});
}
function clearSearchString() {