Always close drawer on navigation

This commit is contained in:
squidfunk
2021-02-12 17:08:58 +01:00
parent e7850ca184
commit ed61f60970
8 changed files with 38 additions and 28 deletions

View File

@@ -36,6 +36,7 @@ import {
getElement,
getElementOrThrow,
getElements,
setToggle,
watchDocument,
watchKeyboard,
watchLocation,
@@ -94,6 +95,10 @@ setupClipboardJS({ alert$ })
if (feature("navigation.instant"))
setupInstantLoading({ document$, location$, viewport$ })
/* Always close drawer on navigation */
merge(location$, target$)
.subscribe(() => setToggle("drawer", false))
/* Set up global keyboard handlers */
keyboard$
.pipe(

View File

@@ -21,7 +21,13 @@
*/
import { Observable, fromEvent, of } from "rxjs"
import { mapTo, mergeMap, switchMap, tap } from "rxjs/operators"
import {
filter,
mapTo,
mergeMap,
switchMap,
tap
} from "rxjs/operators"
import { getElements } from "~/browser"
@@ -67,28 +73,27 @@ function isAppleDevice(): boolean {
export function patchScrollfix(
{ document$ }: PatchOptions
): void {
if (isAppleDevice()) {
document$
.pipe(
switchMap(() => of(...getElements("[data-md-scrollfix]"))),
tap(el => el.removeAttribute("data-md-scrollfix")),
mergeMap(el => fromEvent(el, "touchstart")
.pipe(
mapTo(el)
)
document$
.pipe(
switchMap(() => of(...getElements("[data-md-scrollfix]"))),
tap(el => el.removeAttribute("data-md-scrollfix")),
filter(isAppleDevice),
mergeMap(el => fromEvent(el, "touchstart")
.pipe(
mapTo(el)
)
)
.subscribe(el => {
const top = el.scrollTop
)
.subscribe(el => {
const top = el.scrollTop
/* We're at the top of the container */
if (top === 0) {
el.scrollTop = 1
/* We're at the top of the container */
if (top === 0) {
el.scrollTop = 1
/* We're at the bottom of the container */
} else if (top + el.offsetHeight === el.scrollHeight) {
el.scrollTop = top - 1
}
})
}
/* We're at the bottom of the container */
} else if (top + el.offsetHeight === el.scrollHeight) {
el.scrollTop = top - 1
}
})
}