Fixed stealing of hash fragments when using navigation tracking

This commit is contained in:
squidfunk 2022-02-26 10:27:12 +01:00
parent e3c26215de
commit 8deb1c2425
6 changed files with 23 additions and 17 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

@ -213,7 +213,7 @@
</script> </script>
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<script src="{{ 'assets/javascripts/bundle.cd6d3f86.min.js' | url }}"></script> <script src="{{ 'assets/javascripts/bundle.9f3ca3d1.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 %}

View File

@ -229,7 +229,7 @@ const content$ = defer(() => merge(
/* Table of contents */ /* Table of contents */
...getComponentElements("toc") ...getComponentElements("toc")
.map(el => mountTableOfContents(el, { viewport$, header$ })), .map(el => mountTableOfContents(el, { viewport$, header$, target$ })),
/* Back-to-top button */ /* Back-to-top button */
...getComponentElements("top") ...getComponentElements("top")

View File

@ -32,7 +32,9 @@ import {
finalize, finalize,
map, map,
of, of,
repeat,
scan, scan,
skip,
startWith, startWith,
switchMap, switchMap,
takeLast, takeLast,
@ -83,6 +85,7 @@ interface WatchOptions {
interface MountOptions { interface MountOptions {
viewport$: Observable<Viewport> /* Viewport observable */ viewport$: Observable<Viewport> /* Viewport observable */
header$: Observable<Header> /* Header observable */ header$: Observable<Header> /* Header observable */
target$: Observable<HTMLElement> /* Location target observable */
} }
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
@ -247,7 +250,7 @@ export function watchTableOfContents(
* @returns Table of contents component observable * @returns Table of contents component observable
*/ */
export function mountTableOfContents( export function mountTableOfContents(
el: HTMLElement, { viewport$, header$ }: MountOptions el: HTMLElement, { viewport$, header$, target$ }: MountOptions
): Observable<Component<TableOfContents>> { ): Observable<Component<TableOfContents>> {
return defer(() => { return defer(() => {
const push$ = new Subject<TableOfContents>() const push$ = new Subject<TableOfContents>()
@ -278,6 +281,9 @@ export function mountTableOfContents(
takeUntil(push$.pipe(takeLast(1))), takeUntil(push$.pipe(takeLast(1))),
distinctUntilKeyChanged("offset"), distinctUntilKeyChanged("offset"),
debounceTime(250), debounceTime(250),
skip(1),
takeUntil(target$.pipe(skip(1))),
repeat({ delay: 250 }),
withLatestFrom(push$) withLatestFrom(push$)
) )
.subscribe(([, { prev }]) => { .subscribe(([, { prev }]) => {