Fixed scrollfix being applied more than once for search

This commit is contained in:
squidfunk 2020-02-29 16:26:28 +01:00
parent a1393fdbc3
commit a17c30c3ac

View File

@ -21,7 +21,7 @@
*/ */
import { Observable, fromEvent, merge } from "rxjs" 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" import { getElements } from "observables"
@ -54,9 +54,21 @@ interface MountOptions {
export function patchScrollfix( export function patchScrollfix(
{ document$ }: MountOptions { document$ }: MountOptions
): void { ): void {
document$ const els$ = document$
.pipe( .pipe(
map(() => getElements("[data-md-scrollfix]")), 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 => ( switchMap(els => merge(...els.map(el => (
fromEvent(el, "touchstart") fromEvent(el, "touchstart")
.pipe( .pipe(