mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2026-07-23 06:13:38 -04:00
Fixed jumping to anchor inside closed details
This commit is contained in:
@@ -145,6 +145,32 @@ function initialize(config) { // eslint-disable-line func-style
|
||||
})
|
||||
}
|
||||
|
||||
/* Open details after anchor jump */
|
||||
const details = () => {
|
||||
if (document.location.hash) {
|
||||
const el = document.querySelector(document.location.hash)
|
||||
if (!el)
|
||||
return
|
||||
|
||||
/* Walk up as long as we're not in a details tag */
|
||||
let parent = el.parentNode
|
||||
while (parent && !(parent instanceof HTMLDetailsElement))
|
||||
parent = parent.parentNode
|
||||
|
||||
/* If there's a details tag, open it */
|
||||
if (parent && !parent.open) {
|
||||
parent.open = true
|
||||
|
||||
/* Force reload, so the viewport repositions */
|
||||
const loc = location.hash
|
||||
location.hash = " "
|
||||
location.hash = loc
|
||||
}
|
||||
}
|
||||
}
|
||||
window.addEventListener("hashchange", details)
|
||||
details()
|
||||
|
||||
/* Force 1px scroll offset to trigger overflow scrolling */
|
||||
if (Modernizr.ios) {
|
||||
const scrollable = document.querySelectorAll("[data-md-scrollfix]")
|
||||
|
||||
Reference in New Issue
Block a user