[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.
|
// Expand the accordion section matching the anchor before jumping to it.
|
||||||
// Anchor links in the summary strip point to #home-<type>, which lives
|
// Anchor links in the summary strip point to #home-<type>, which lives
|
||||||
// inside a collapsed Bootstrap collapse panel. If the panel is hidden the
|
// inside a collapsed Bootstrap collapse panel. If the panel is hidden the
|
||||||
// browser cannot scroll to the target, so open it first.
|
// browser cannot scroll to the target, so open it first. Runs both on
|
||||||
(function () {
|
// 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
|
var hash = window.location.hash
|
||||||
if (!hash || hash.indexOf('#home-') !== 0) {
|
if (!hash || hash.indexOf('#home-') !== 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var slug = hash.slice('#home-'.length)
|
var slug = hash.slice('#home-'.length)
|
||||||
var collapse = document.getElementById('collapse-' + slug)
|
var collapse = document.getElementById('collapse-' + slug)
|
||||||
if (collapse && !collapse.classList.contains('show')) {
|
if (!collapse) {
|
||||||
var instance = bootstrap.Collapse.getOrCreateInstance(collapse, {
|
return
|
||||||
toggle: false
|
|
||||||
})
|
|
||||||
instance.show()
|
|
||||||
collapse.addEventListener('shown.bs.collapse', function () {
|
|
||||||
var target = document.getElementById(hash.slice(1))
|
|
||||||
if (target && target.scrollIntoView) {
|
|
||||||
target.scrollIntoView()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})()
|
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
|
// Graphs
|
||||||
var ctx = document.getElementById('myChart')
|
var ctx = document.getElementById('myChart')
|
||||||
|
|||||||
Reference in New Issue
Block a user