Added further utility functions

This commit is contained in:
squidfunk 2019-10-28 18:01:47 +01:00
parent 4e14ff285e
commit 5a90f92bb7
3 changed files with 19 additions and 2 deletions

View File

@ -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 sidebar - Sidebar element
* @param options - Options * @param options - Options

View File

@ -23,6 +23,8 @@
import { OperatorFunction, pipe } from "rxjs" import { OperatorFunction, pipe } from "rxjs"
import { filter, map } from "rxjs/operators" import { filter, map } from "rxjs/operators"
import { toArray } from "../../utilities"
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* Functions * Functions
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
@ -42,6 +44,21 @@ export function getElement<T extends HTMLElement>(
return document.querySelector<T>(selector) || undefined 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))
}
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
/** /**

View File

@ -35,6 +35,6 @@
*/ */
export function toArray< export function toArray<
T extends HTMLElement T extends HTMLElement
>(collection: HTMLCollection): T[] { >(collection: HTMLCollection | NodeListOf<T>): T[] {
return Array.from(collection) as T[] return Array.from(collection) as T[]
} }