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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"assets/javascripts/bundle.js": "assets/javascripts/bundle.d8c6976f.min.js",
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.d8c6976f.min.js.map",
"assets/javascripts/bundle.js": "assets/javascripts/bundle.6b6cf576.min.js",
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.6b6cf576.min.js.map",
"assets/javascripts/vendor.js": "assets/javascripts/vendor.e32ed4d0.min.js",
"assets/javascripts/vendor.js.map": "assets/javascripts/vendor.e32ed4d0.min.js.map",
"assets/javascripts/worker/search.js": "assets/javascripts/worker/search.b9424174.min.js",

View File

@ -217,7 +217,7 @@
{% endblock %}
{% block scripts %}
<script src="{{ 'assets/javascripts/vendor.e32ed4d0.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.d8c6976f.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.6b6cf576.min.js' | url }}"></script>
{% for path in config["extra_javascript"] %}
<script src="{{ path | url }}"></script>
{% endfor %}

View File

@ -51,7 +51,7 @@ theme:
# Default values, taken from mkdocs_theme.yml
language: en
features:
- navigation.instant
# - navigation.instant
- navigation.sections
- navigation.tabs
palette:

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
}
})
}