From 5ca3aaa44f98d612c66a2a01bf0ce9b52afb2b81 Mon Sep 17 00:00:00 2001 From: Effie Date: Mon, 26 Jun 2023 23:23:43 +1000 Subject: [PATCH] makes the song index behave properly --- static/script.js | 18 +++++++++++------- templates/songindex.html | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/static/script.js b/static/script.js index 066e7a9..2e36878 100644 --- a/static/script.js +++ b/static/script.js @@ -1,9 +1,6 @@ -function getAnchor() { - return (document.URL.split('#').length > 1) ? document.URL.split('#')[1] : null; -} - window.addEventListener('load', (event) => { - const preclicked = getAnchor(); + const preclicked = window.location.hash.slice(1); + console.log(preclicked); if (! preclicked) return; const radiobutton = document.getElementById(preclicked); if (radiobutton){ @@ -21,13 +18,20 @@ function albumselect(code){ label.scrollIntoView(); } document.getElementById('search-input').value = ''; + document.getElementById('search-results').innerHTML = ''; }; -function collapse(clickevent){ +function albumHeaderClick(clickevent){ const radiobutton = document.getElementById(clickevent.target.htmlFor); if (radiobutton.checked){ radiobutton.checked = false; clickevent.preventDefault(); + history.replaceState(null, document.title, `${window.location.origin}${window.location.pathname}${window.location.search}`); } -} + else{ + window.location.hash = radiobutton.id; + const label = clickevent.target; + label.scrollIntoView(); + } +}; diff --git a/templates/songindex.html b/templates/songindex.html index 3138e30..94456b8 100644 --- a/templates/songindex.html +++ b/templates/songindex.html @@ -11,7 +11,7 @@ {% for album_id, name, date, code in album_info %}
-