receptty.org/templates/search.html

41 lines
952 B
HTML
Raw Normal View History

2021-02-02 21:46:24 +01:00
{% extends "index.html" %}
{% block content %}
<main>
2021-02-02 21:46:24 +01:00
<h2>Hledání a filtry</h2>
<div class="filters">
2021-02-02 23:39:29 +01:00
<input type="text" placeholder="Název" oninput="filter_name(this.value)">
2021-02-02 21:46:24 +01:00
</div>
<section class="list">
2021-02-02 22:01:42 +01:00
{% set section = get_section(path="_index.md") %}
{% for page in section.pages %}
{{ macro::print_recipe(recipe=page) }}
{% endfor %}
</section>
</main>
{% endblock content %}
2021-02-02 23:39:29 +01:00
{% block script %}
<script>
function filter_name(str) {
let articles = document.getElementsByTagName("article");
str = str.toLowerCase();
if (str.length==0) {
for (let i=0; i<articles.length; i++) {
articles[i].style.display = "flex";
}
} else {
for (let i=0; i<articles.length; i++) {
let name = articles[i].getElementsByTagName("h3")[0].innerHTML.toLowerCase();
if (!name.includes(str)) {
articles[i].style.display = "none";
} else {
articles[i].style.display = "flex";
}
}
}
}
</script>
{% endblock script %}