Fixed jumping to anchor inside closed details

This commit is contained in:
squidfunk 2017-11-05 15:17:23 +01:00 committed by Martin Donath
parent 1c11a78f44
commit c2bbb060dc
4 changed files with 28 additions and 2 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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] != "" %}

View File

@ -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]")