mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-11-24 07:30:12 +01:00
Fixed ignored repeated anchor link clicks when using instant loading
This commit is contained in:
parent
ef30cfea67
commit
7e6f15bb17
File diff suppressed because one or more lines are too long
29
material/templates/assets/javascripts/bundle.55099adf.min.js
vendored
Normal file
29
material/templates/assets/javascripts/bundle.55099adf.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -250,7 +250,7 @@
|
|||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script src="{{ 'assets/javascripts/bundle.18ee4812.min.js' | url }}"></script>
|
<script src="{{ 'assets/javascripts/bundle.55099adf.min.js' | url }}"></script>
|
||||||
{% for script in config.extra_javascript %}
|
{% for script in config.extra_javascript %}
|
||||||
{{ script | script_tag }}
|
{{ script | script_tag }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -30,10 +30,12 @@ import {
|
|||||||
debounceTime,
|
debounceTime,
|
||||||
distinctUntilKeyChanged,
|
distinctUntilKeyChanged,
|
||||||
endWith,
|
endWith,
|
||||||
|
filter,
|
||||||
fromEvent,
|
fromEvent,
|
||||||
ignoreElements,
|
ignoreElements,
|
||||||
map,
|
map,
|
||||||
of,
|
of,
|
||||||
|
sample,
|
||||||
share,
|
share,
|
||||||
skip,
|
skip,
|
||||||
startWith,
|
startWith,
|
||||||
@ -289,19 +291,17 @@ export function setupInstantLoading(
|
|||||||
popstate$.pipe(map(getLocation))
|
popstate$.pipe(map(getLocation))
|
||||||
.subscribe(location$)
|
.subscribe(location$)
|
||||||
|
|
||||||
// Intercept clicks on anchor links, and scroll document into position. As
|
// Intercept clicks on anchor links, and scroll document into position - as
|
||||||
// we disabled scroll restoration, we need to do this manually here.
|
// we disabled scroll restoration, we need to do this manually here
|
||||||
location$
|
location$
|
||||||
.pipe(
|
.pipe(
|
||||||
startWith(getLocation()),
|
startWith(getLocation()),
|
||||||
bufferCount(2, 1),
|
bufferCount(2, 1),
|
||||||
switchMap(([prev, next]) => (
|
filter(([prev, next]) => (
|
||||||
prev.pathname === next.pathname &&
|
prev.pathname === next.pathname &&
|
||||||
prev.hash !== next.hash
|
prev.hash !== next.hash
|
||||||
)
|
)),
|
||||||
? of(next)
|
map(([, next]) => next)
|
||||||
: EMPTY
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.subscribe(url => {
|
.subscribe(url => {
|
||||||
if (history.state !== null || !url.hash) {
|
if (history.state !== null || !url.hash) {
|
||||||
@ -313,6 +313,29 @@ export function setupInstantLoading(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Intercept clicks on the same anchor link - we must use a distinct pipeline
|
||||||
|
// for this, or we'd end up in a loop, setting the hash again and again
|
||||||
|
location$
|
||||||
|
.pipe(
|
||||||
|
sample(instant$),
|
||||||
|
startWith(getLocation()),
|
||||||
|
bufferCount(2, 1),
|
||||||
|
filter(([prev, next]) => (
|
||||||
|
prev.pathname === next.pathname &&
|
||||||
|
prev.hash === next.hash
|
||||||
|
)),
|
||||||
|
map(([, next]) => next)
|
||||||
|
)
|
||||||
|
.subscribe(url => {
|
||||||
|
history.scrollRestoration = "auto"
|
||||||
|
setLocationHash(url.hash)
|
||||||
|
history.scrollRestoration = "manual"
|
||||||
|
|
||||||
|
// Hack: we need to make sure that we don't end up with multiple history
|
||||||
|
// entries for the same anchor link, so we just remove the last entry
|
||||||
|
history.back()
|
||||||
|
})
|
||||||
|
|
||||||
// After parsing the document, check if the current history entry has a state.
|
// After parsing the document, check if the current history entry has a state.
|
||||||
// This may happen when users press the back or forward button to visit a page
|
// This may happen when users press the back or forward button to visit a page
|
||||||
// that was already seen. If there's no state, it means a new page was visited
|
// that was already seen. If there's no state, it means a new page was visited
|
||||||
@ -330,9 +353,8 @@ export function setupInstantLoading(
|
|||||||
// the current history state whenever the scroll position changes. This must
|
// the current history state whenever the scroll position changes. This must
|
||||||
// be debounced and cannot be done in popstate, as popstate has already
|
// be debounced and cannot be done in popstate, as popstate has already
|
||||||
// removed the entry from the history.
|
// removed the entry from the history.
|
||||||
document$
|
viewport$
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap(() => viewport$),
|
|
||||||
distinctUntilKeyChanged("offset"),
|
distinctUntilKeyChanged("offset"),
|
||||||
debounceTime(100)
|
debounceTime(100)
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user