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> </header>
<nav id=filters> <nav id=filters>
<details> <details id=filters-details>
<summary><h2>filters</h2></summary> <summary><h2>filters</h2></summary>
<div> <div>
<h3>show only</h3> <h3>show only</h3>

View file

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