Enable search on category listing
This commit is contained in:
parent
d090f61543
commit
5403e0e556
21
static/js/search.js
Normal file
21
static/js/search.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
function filter_name(str)
|
||||||
|
{
|
||||||
|
str = str.toLowerCase();
|
||||||
|
if (str.length == 0) {
|
||||||
|
for (let i = 0; i < articles.length; i++) {
|
||||||
|
articles[i].style.display = "block";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i < articles.length; i++) {
|
||||||
|
let name = articles[i].getElementsByTagName("h2")[0].innerHTML.toLowerCase();
|
||||||
|
if (!name.includes(str)) {
|
||||||
|
articles[i].style.display = "none";
|
||||||
|
} else {
|
||||||
|
articles[i].style.display = "block";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let articles = document.getElementsByTagName("article");
|
||||||
|
let search = document.getElementById("search");
|
||||||
|
search.style.display = "inline-block";
|
@ -2,5 +2,10 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{{ term.name }} category</h1>
|
<h1>{{ term.name }} category</h1>
|
||||||
|
<input id="search" class="search" type="text" placeholder="Search titles" oninput="filter_name(this.value)">
|
||||||
{{ macros::list_posts(section=term, taxonomy=true) }}
|
{{ macros::list_posts(section=term, taxonomy=true) }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block script %}
|
||||||
|
<script src="/js/search.js"></script>
|
||||||
|
{% endblock %}
|
||||||
|
@ -11,27 +11,5 @@
|
|||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
||||||
{% block script %}
|
{% block script %}
|
||||||
<script>
|
<script src="/js/search.js"></script>
|
||||||
function filter_name(str)
|
|
||||||
{
|
|
||||||
str = str.toLowerCase();
|
|
||||||
if (str.length == 0) {
|
|
||||||
for (let i = 0; i < articles.length; i++) {
|
|
||||||
articles[i].style.display = "block";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (let i = 0; i < articles.length; i++) {
|
|
||||||
let name = articles[i].getElementsByTagName("h2")[0].innerHTML.toLowerCase();
|
|
||||||
if (!name.includes(str)) {
|
|
||||||
articles[i].style.display = "none";
|
|
||||||
} else {
|
|
||||||
articles[i].style.display = "block";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let articles = document.getElementsByTagName("article");
|
|
||||||
let search = document.getElementById("search");
|
|
||||||
search.style.display = "inline-block";
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user