From 5a90f92bb70cb3fe768d0f13dcb061ffa1dafca3 Mon Sep 17 00:00:00 2001 From: squidfunk Date: Mon, 28 Oct 2019 18:01:47 +0100 Subject: [PATCH] Added further utility functions --- .../javascripts/component/sidebar/index.ts | 2 +- src/assets/javascripts/ui/element/index.ts | 17 +++++++++++++++++ src/assets/javascripts/utilities/index.ts | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/assets/javascripts/component/sidebar/index.ts b/src/assets/javascripts/component/sidebar/index.ts index 1e86cf610..3373753e2 100644 --- a/src/assets/javascripts/component/sidebar/index.ts +++ b/src/assets/javascripts/component/sidebar/index.ts @@ -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 diff --git a/src/assets/javascripts/ui/element/index.ts b/src/assets/javascripts/ui/element/index.ts index 62377fb44..533ca5a46 100644 --- a/src/assets/javascripts/ui/element/index.ts +++ b/src/assets/javascripts/ui/element/index.ts @@ -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( return document.querySelector(selector) || undefined } +/** + * Retrieve all elements matching the query selector + * + * @template T - Element type + * + * @param selector - Query selector + * + * @return HTML elements + */ +export function getElements( + selector: string +): T[] { + return toArray(document.querySelectorAll(selector)) +} + /* ------------------------------------------------------------------------- */ /** diff --git a/src/assets/javascripts/utilities/index.ts b/src/assets/javascripts/utilities/index.ts index cb5cfb189..e6115964a 100644 --- a/src/assets/javascripts/utilities/index.ts +++ b/src/assets/javascripts/utilities/index.ts @@ -35,6 +35,6 @@ */ export function toArray< T extends HTMLElement ->(collection: HTMLCollection): T[] { +>(collection: HTMLCollection | NodeListOf): T[] { return Array.from(collection) as T[] }