diff --git a/vrobbler/templates/scrobbles/scrobble_list.html b/vrobbler/templates/scrobbles/scrobble_list.html index 8254eb0..9d5582b 100644 --- a/vrobbler/templates/scrobbles/scrobble_list.html +++ b/vrobbler/templates/scrobbles/scrobble_list.html @@ -246,27 +246,37 @@ // Expand the accordion section matching the anchor before jumping to it. // Anchor links in the summary strip point to #home-, which lives // inside a collapsed Bootstrap collapse panel. If the panel is hidden the - // browser cannot scroll to the target, so open it first. - (function () { + // browser cannot scroll to the target, so open it first. Runs both on + // initial load and on every hash change, since the summary links are + // same-page anchors that do not reload the page. + function jumpToHomeAnchor() { var hash = window.location.hash if (!hash || hash.indexOf('#home-') !== 0) { return } var slug = hash.slice('#home-'.length) var collapse = document.getElementById('collapse-' + slug) - if (collapse && !collapse.classList.contains('show')) { - var instance = bootstrap.Collapse.getOrCreateInstance(collapse, { - toggle: false - }) - instance.show() - collapse.addEventListener('shown.bs.collapse', function () { - var target = document.getElementById(hash.slice(1)) - if (target && target.scrollIntoView) { - target.scrollIntoView() - } - }) + if (!collapse) { + return } - })() + function scrollToTarget() { + var target = document.getElementById(hash.slice(1)) + if (target && target.scrollIntoView) { + target.scrollIntoView() + } + } + if (collapse.classList.contains('show')) { + scrollToTarget() + return + } + var instance = bootstrap.Collapse.getOrCreateInstance(collapse, { + toggle: false + }) + instance.show() + collapse.addEventListener('shown.bs.collapse', scrollToTarget) + } + jumpToHomeAnchor() + window.addEventListener('hashchange', jumpToHomeAnchor) // Graphs var ctx = document.getElementById('myChart')