From a17c30c3ac5fdae54b328fb8b7e2988b17d4209c Mon Sep 17 00:00:00 2001 From: squidfunk Date: Sat, 29 Feb 2020 16:26:28 +0100 Subject: [PATCH] Fixed scrollfix being applied more than once for search --- .../javascripts/patches/scrollfix/index.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/assets/javascripts/patches/scrollfix/index.ts b/src/assets/javascripts/patches/scrollfix/index.ts index 41aefc5b8..e1db9473e 100644 --- a/src/assets/javascripts/patches/scrollfix/index.ts +++ b/src/assets/javascripts/patches/scrollfix/index.ts @@ -21,7 +21,7 @@ */ import { Observable, fromEvent, merge } from "rxjs" -import { map, mapTo, switchMap } from "rxjs/operators" +import { map, mapTo, shareReplay, switchMap } from "rxjs/operators" import { getElements } from "observables" @@ -54,9 +54,21 @@ interface MountOptions { export function patchScrollfix( { document$ }: MountOptions ): void { - document$ + const els$ = document$ .pipe( map(() => getElements("[data-md-scrollfix]")), + shareReplay(1) + ) + + /* Remove marker attribute, so we'll only add the fix once */ + els$.subscribe(els => { + for (const el of els) + el.removeAttribute("data-md-scrollfix") + }) + + /* Patch overflow scrolling on touch start */ + els$ + .pipe( switchMap(els => merge(...els.map(el => ( fromEvent(el, "touchstart") .pipe(