2018-10-24 15:00:27 +02:00
|
|
|
$(document).ready(function(){
|
2019-05-19 18:37:00 +02:00
|
|
|
var recipes = $("#recipes a");
|
2018-10-24 15:00:27 +02:00
|
|
|
var headerLetters = $("#recipes h2");
|
2019-05-19 18:37:00 +02:00
|
|
|
$("#search-recipes").on("keyup", searchRecipe(recipes, headerLetters));
|
|
|
|
$("#clear-search-string").click(clearSearchString);
|
|
|
|
});
|
|
|
|
|
|
|
|
function searchRecipe(recipes, headerLetters) {
|
|
|
|
return function () {
|
|
|
|
var search = $("#search-recipes").val().toUpperCase();
|
2018-10-24 15:00:27 +02:00
|
|
|
for (var i = 0; i < recipes.length; i++) {
|
2019-05-19 18:37:00 +02:00
|
|
|
if (recipes[i].innerHTML.toUpperCase().indexOf(search) > -1) {
|
2018-10-24 15:00:27 +02:00
|
|
|
recipes[i].style.display = "";
|
|
|
|
}
|
2019-05-19 18:37:00 +02:00
|
|
|
else {
|
2018-10-24 15:00:27 +02:00
|
|
|
recipes[i].style.display = "none";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (var j = 0; j < headerLetters.length; j++) {
|
2019-05-19 18:37:00 +02:00
|
|
|
if (($("*[data-letter='" + headerLetters[j].innerHTML + "']:visible")).length > 0) {
|
2018-10-24 15:00:27 +02:00
|
|
|
headerLetters[j].style.display = "";
|
|
|
|
}
|
2019-05-19 18:37:00 +02:00
|
|
|
else {
|
2018-10-24 15:00:27 +02:00
|
|
|
headerLetters[j].style.display = "none";
|
|
|
|
}
|
|
|
|
}
|
2019-05-19 18:37:00 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function clearSearchString(){
|
|
|
|
$("#search-recipes").val("");
|
|
|
|
$("#search-recipes").focus();
|
|
|
|
$("#search-recipes").keyup();
|
|
|
|
}
|