mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Fixed jumping to anchor inside closed details
This commit is contained in:
parent
1c11a78f44
commit
c2bbb060dc
1
material/assets/javascripts/application-402b8c59c2.js
Normal file
1
material/assets/javascripts/application-402b8c59c2.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -162,7 +162,7 @@
|
||||
{% endblock %}
|
||||
</div>
|
||||
{% block scripts %}
|
||||
<script src="{{ base_url }}/assets/javascripts/application-84693e5e49.js"></script>
|
||||
<script src="{{ base_url }}/assets/javascripts/application-402b8c59c2.js"></script>
|
||||
{% if lang.t("search.language") != "en" %}
|
||||
{% set languages = lang.t("search.language").split(",") %}
|
||||
{% if languages | length and languages[0] != "" %}
|
||||
|
@ -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]")
|
||||
|
Loading…
Reference in New Issue
Block a user