shopping-list/public_html/js/search.js

33 lines
881 B
JavaScript
Raw Permalink Normal View History

2019-05-24 09:41:25 +02:00
$(document).ready(function () {
$("#search-recipes").on("keyup", searchRecipe);
2019-05-19 18:37:00 +02:00
$("#clear-search-string").click(clearSearchString);
});
2019-05-24 09:41:25 +02:00
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(searchString) > -1) {
$(recipes[i]).show()
2018-10-24 15:00:27 +02:00
}
2019-05-24 09:41:25 +02:00
else {
$(recipes[i]).hide();
2018-10-24 15:00:27 +02:00
}
2019-05-24 09:41:25 +02:00
}
$("#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");
}
});
2019-05-19 18:37:00 +02:00
}
2019-05-24 09:41:25 +02:00
function clearSearchString() {
2019-05-19 18:37:00 +02:00
$("#search-recipes").val("");
$("#search-recipes").focus();
$("#search-recipes").keyup();
}