open filters on load if not empty or 'all'

This commit is contained in:
Rhiannon Morris 2020-08-04 18:46:17 +02:00
parent e19bbe554e
commit 5d5e3bacbb
2 changed files with 5 additions and 4 deletions

View file

@ -44,7 +44,7 @@ make' (GalleryInfo {title, prefix, filters, hidden}) infos = [b|@0
</header>
<nav id=filters>
<details>
<details id=filters-details>
<summary><h2>filters</h2></summary>
<div>
<h3>show only</h3>

View file

@ -86,7 +86,7 @@ function makeFragment() {
}
}
function useFragment() {
function useFragment(firstLoad) {
let frag = document.location.hash.replace(/^#/, '');
if (frag == 'all') {
@ -94,6 +94,7 @@ function useFragment() {
} else if (frag) {
let set = new Set(frag.split(';'));
allBoxes.forEach(b => b.checked = set.has(b.id));
if (firstLoad) document.getElementById('filters-details').open = true;
} else {
resetForm();
}
@ -108,8 +109,8 @@ function setup() {
document.getElementById('clear').addEventListener('click', clear);
document.getElementById('reset').addEventListener('click', reset);
window.addEventListener('popstate', useFragment);
useFragment();
window.addEventListener('popstate', () => useFragment(false));
useFragment(true);
}
window.addEventListener('load', setup);