mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03: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>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block scripts %}
|
{% 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"] %}
|
{% for path in config["extra_javascript"] %}
|
||||||
<script src="{{ path | url }}"></script>
|
<script src="{{ path | url }}"></script>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -186,11 +186,23 @@ export function setupInstantLoading(
|
|||||||
/* Handle HTML and SVG elements */
|
/* Handle HTML and SVG elements */
|
||||||
if (ev.target instanceof Element) {
|
if (ev.target instanceof Element) {
|
||||||
const el = ev.target.closest("a")
|
const el = ev.target.closest("a")
|
||||||
if (el && !el.target && urls.includes(el.href)) {
|
if (el && !el.target) {
|
||||||
ev.preventDefault()
|
const url = new URL(el.href)
|
||||||
return of({
|
|
||||||
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
|
return NEVER
|
||||||
@ -252,18 +264,6 @@ export function setupInstantLoading(
|
|||||||
)
|
)
|
||||||
.subscribe(document$)
|
.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 */
|
/* Replace meta tags and components */
|
||||||
document$
|
document$
|
||||||
.pipe(
|
.pipe(
|
||||||
@ -324,6 +324,19 @@ export function setupInstantLoading(
|
|||||||
)
|
)
|
||||||
.subscribe()
|
.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 */
|
/* Debounce update of viewport offset */
|
||||||
viewport$
|
viewport$
|
||||||
.pipe(
|
.pipe(
|
||||||
|
Loading…
Reference in New Issue
Block a user