mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Added further utility functions
This commit is contained in:
parent
4e14ff285e
commit
5a90f92bb7
@ -97,7 +97,7 @@ export function unsetSidebarLock(sidebar: HTMLElement): void {
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Create a observable for a sidebar component
|
||||
* Create an observable for a sidebar component
|
||||
*
|
||||
* @param sidebar - Sidebar element
|
||||
* @param options - Options
|
||||
|
@ -23,6 +23,8 @@
|
||||
import { OperatorFunction, pipe } from "rxjs"
|
||||
import { filter, map } from "rxjs/operators"
|
||||
|
||||
import { toArray } from "../../utilities"
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Functions
|
||||
* ------------------------------------------------------------------------- */
|
||||
@ -42,6 +44,21 @@ export function getElement<T extends HTMLElement>(
|
||||
return document.querySelector<T>(selector) || undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all elements matching the query selector
|
||||
*
|
||||
* @template T - Element type
|
||||
*
|
||||
* @param selector - Query selector
|
||||
*
|
||||
* @return HTML elements
|
||||
*/
|
||||
export function getElements<T extends HTMLElement>(
|
||||
selector: string
|
||||
): T[] {
|
||||
return toArray(document.querySelectorAll<T>(selector))
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
|
@ -35,6 +35,6 @@
|
||||
*/
|
||||
export function toArray<
|
||||
T extends HTMLElement
|
||||
>(collection: HTMLCollection): T[] {
|
||||
>(collection: HTMLCollection | NodeListOf<T>): T[] {
|
||||
return Array.from(collection) as T[]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user