mirror of
https://github.com/tim-krehan/shopping-list.git
synced 2024-11-23 22:30:41 +01:00
fixed the search thingy
This commit is contained in:
parent
358d97826d
commit
086970c4da
1 changed files with 22 additions and 23 deletions
45
js/search.js
45
js/search.js
|
@ -1,33 +1,32 @@
|
||||||
$(document).ready(function(){
|
$(document).ready(function () {
|
||||||
var recipes = $("#recipes a");
|
$("#search-recipes").on("keyup", searchRecipe);
|
||||||
var headerLetters = $("#recipes h2");
|
|
||||||
$("#search-recipes").on("keyup", searchRecipe(recipes, headerLetters));
|
|
||||||
$("#clear-search-string").click(clearSearchString);
|
$("#clear-search-string").click(clearSearchString);
|
||||||
});
|
});
|
||||||
|
|
||||||
function searchRecipe(recipes, headerLetters) {
|
function searchRecipe() {
|
||||||
return function () {
|
var searchString = $("#search-recipes").val().toUpperCase();
|
||||||
var search = $("#search-recipes").val().toUpperCase();
|
var recipes = $("#recipes a");
|
||||||
for (var i = 0; i < recipes.length; i++) {
|
|
||||||
if (recipes[i].innerHTML.toUpperCase().indexOf(search) > -1) {
|
for (var i = 0; i < recipes.length; i++) {
|
||||||
recipes[i].style.display = "";
|
if (recipes[i].innerHTML.toUpperCase().indexOf(searchString) > -1) {
|
||||||
}
|
$(recipes[i]).show()
|
||||||
else {
|
|
||||||
recipes[i].style.display = "none";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (var j = 0; j < headerLetters.length; j++) {
|
else {
|
||||||
if (($("*[data-letter='" + headerLetters[j].innerHTML + "']:visible")).length > 0) {
|
$(recipes[i]).hide();
|
||||||
headerLetters[j].style.display = "";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
headerLetters[j].style.display = "none";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
$("#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");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearSearchString(){
|
function clearSearchString() {
|
||||||
$("#search-recipes").val("");
|
$("#search-recipes").val("");
|
||||||
$("#search-recipes").focus();
|
$("#search-recipes").focus();
|
||||||
$("#search-recipes").keyup();
|
$("#search-recipes").keyup();
|
||||||
|
|
Loading…
Reference in a new issue