mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Switched to addEventListener for media query
This commit is contained in:
parent
063071550c
commit
d45c378d60
@ -99,9 +99,9 @@ export function getElements<T extends HTMLElement>(
|
||||
*
|
||||
* @return Element
|
||||
*/
|
||||
export function createElement<
|
||||
T extends keyof HTMLElementTagNameMap
|
||||
>(tagName: T): HTMLElementTagNameMap[T] {
|
||||
export function createElement<T extends keyof HTMLElementTagNameMap>(
|
||||
tagName: T
|
||||
): HTMLElementTagNameMap[T] {
|
||||
return document.createElement(tagName)
|
||||
}
|
||||
|
||||
|
@ -20,8 +20,8 @@
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { Observable, fromEventPattern } from "rxjs"
|
||||
import { shareReplay, startWith } from "rxjs/operators"
|
||||
import { Observable, fromEvent } from "rxjs"
|
||||
import { map, shareReplay, startWith } from "rxjs/operators"
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Functions
|
||||
@ -36,10 +36,9 @@ import { shareReplay, startWith } from "rxjs/operators"
|
||||
*/
|
||||
export function watchMedia(query: string): Observable<boolean> {
|
||||
const media = matchMedia(query)
|
||||
return fromEventPattern<boolean>(next =>
|
||||
media.addListener(() => next(media.matches))
|
||||
)
|
||||
return fromEvent<MediaQueryListEvent>(media, "change")
|
||||
.pipe(
|
||||
map(ev => ev.matches),
|
||||
startWith(media.matches),
|
||||
shareReplay({ bufferSize: 1, refCount: true })
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user