[templates] Expand accordion on hash change for homepage anchors
This commit is contained in:
@ -246,27 +246,37 @@
|
||||
// Expand the accordion section matching the anchor before jumping to it.
|
||||
// Anchor links in the summary strip point to #home-<type>, 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 () {
|
||||
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')
|
||||
|
||||
Reference in New Issue
Block a user