mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-11-23 23:21:00 +01:00
Fixed invalid anchor offsets when using instant loading
This commit is contained in:
parent
51d4920a2e
commit
adafd844f9
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -223,7 +223,7 @@
|
||||
</script>
|
||||
{% endblock %}
|
||||
{% block scripts %}
|
||||
<script src="{{ 'assets/javascripts/bundle.806c4996.min.js' | url }}"></script>
|
||||
<script src="{{ 'assets/javascripts/bundle.8fb3741f.min.js' | url }}"></script>
|
||||
{% for path in config["extra_javascript"] %}
|
||||
<script src="{{ path | url }}"></script>
|
||||
{% endfor %}
|
||||
|
@ -186,11 +186,23 @@ export function setupInstantLoading(
|
||||
/* Handle HTML and SVG elements */
|
||||
if (ev.target instanceof Element) {
|
||||
const el = ev.target.closest("a")
|
||||
if (el && !el.target && urls.includes(el.href)) {
|
||||
ev.preventDefault()
|
||||
return of({
|
||||
url: new URL(el.href)
|
||||
})
|
||||
if (el && !el.target) {
|
||||
const url = new URL(el.href)
|
||||
|
||||
/* Canonicalize URL */
|
||||
url.search = ""
|
||||
url.hash = ""
|
||||
|
||||
/* Check if URL should be intercepted */
|
||||
if (
|
||||
url.pathname !== location.pathname &&
|
||||
urls.includes(url.toString())
|
||||
) {
|
||||
ev.preventDefault()
|
||||
return of({
|
||||
url: new URL(el.href)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return NEVER
|
||||
@ -252,18 +264,6 @@ export function setupInstantLoading(
|
||||
)
|
||||
.subscribe(document$)
|
||||
|
||||
/* Emit history state change */
|
||||
merge(push$, pop$)
|
||||
.pipe(
|
||||
sample(document$)
|
||||
)
|
||||
.subscribe(({ url, offset }) => {
|
||||
if (url.hash && !offset)
|
||||
setLocationHash(url.hash)
|
||||
else
|
||||
setViewportOffset(offset || { y: 0 })
|
||||
})
|
||||
|
||||
/* Replace meta tags and components */
|
||||
document$
|
||||
.pipe(
|
||||
@ -324,6 +324,19 @@ export function setupInstantLoading(
|
||||
)
|
||||
.subscribe()
|
||||
|
||||
/* Emit history state change */
|
||||
merge(push$, pop$)
|
||||
.pipe(
|
||||
sample(document$),
|
||||
)
|
||||
.subscribe(({ url, offset }) => {
|
||||
if (url.hash && !offset) {
|
||||
setLocationHash(url.hash)
|
||||
} else {
|
||||
setViewportOffset(offset || { y: 0 })
|
||||
}
|
||||
})
|
||||
|
||||
/* Debounce update of viewport offset */
|
||||
viewport$
|
||||
.pipe(
|
||||
|
Loading…
Reference in New Issue
Block a user