Add "clear filters" button

This commit is contained in:
kez 2022-12-15 11:25:31 -08:00 committed by kezzle
parent 05b4fa1107
commit 806ba76922
2 changed files with 13 additions and 1 deletions

View File

@ -10,6 +10,7 @@ let resources = document.querySelectorAll('#resource-list > .resource-list-entry
let topic_dropdown_button = document.getElementById('topicDropdownMenuButton');
let lang_dropdown_button = document.getElementById('languageDropdownMenuButton');
let author_dropdown_button = document.getElementById('authorDropdownMenuButton');
let filterClearButton = document.getElementById('filterClearButton');
const translatedTopic = document.currentScript.getAttribute('topic');
const translatedTopicColon = document.currentScript.getAttribute('topic-colon');
@ -54,6 +55,14 @@ Array.from(document.getElementsByClassName('onclick-setAuthor'))
applyFilters(resourceFilters.topic, resourceFilters.lang, resourceFilters.author)
}));
filterClearButton.addEventListener('click', ev => {
ev.preventDefault();
setTopic('none', 'none');
setLang('none', 'none');
setAuthor('none', 'none');
applyFilters(null, null, null);
});
function setTopic(topic, topicReadable) {
let newText = `${translatedTopicColon} ${topicReadable}`;

View File

@ -63,7 +63,7 @@
{%- endif -%}
</button>
<div class="dropdown-menu" aria-labelledby="authorDropdownMenuButton">
<a class="d-block onclick-setAuthor" data-author="none" href="{{ get_new_link(this, new_author=none) }}">{{ _('None') }}</a>
<a class="d-block onclick-setAuthor" data-author="none" href="{{ get_new_link(this, new_author='none') }}">{{ _('None') }}</a>
{% for author in get_authors()|sort(case_sensitive=False) if author != 'none' %}
<a
class="d-block onclick-setAuthor"
@ -75,4 +75,7 @@
{% endfor %}
</div>
</div>
<div>
<a href="{{ get_new_link(this, new_topic='none', new_lang='none', new_author='none') }}" id="filterClearButton" class="btn btn-primary font-weight-600">{{ _('Clear filters') }}</a>
</div>
</div>