mirror of
https://github.com/dzeiocom/libs.git
synced 2025-06-07 16:49:56 +00:00
Updated Functions
Signed-off-by: Florian Bouillon <florian.bouillon@delta-wings.net>
This commit is contained in:
parent
611c5d5b47
commit
ea3b3e89ad
@ -18,9 +18,9 @@ export default class DOMElement<T extends HTMLElement = HTMLElement> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static get<T extends HTMLElement = HTMLElement>(query: string | T, source?: HTMLElement): DOMElement<T> | undefined {
|
public static get<T extends HTMLElement = HTMLElement>(query: string | T, source?: HTMLElement | DOMElement): DOMElement<T> | undefined {
|
||||||
if (!(query instanceof HTMLElement)) {
|
if (!(query instanceof HTMLElement)) {
|
||||||
const tmp = (source || document).querySelector<T>(query)
|
const tmp = (source instanceof DOMElement ? source.item : source || document).querySelector<T>(query)
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,15 @@ export default class DOMFleetManager<T extends HTMLElement = HTMLElement> {
|
|||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
private query: string,
|
private query: string,
|
||||||
private source?: HTMLElement
|
private source?: HTMLElement | DOMElement
|
||||||
) {
|
) {
|
||||||
this.refresh()
|
this.refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public last() {
|
||||||
|
return this.items[this.items.length - 1]
|
||||||
|
}
|
||||||
|
|
||||||
public each(fn: (item: DOMElement, index: number) => void) {
|
public each(fn: (item: DOMElement, index: number) => void) {
|
||||||
this.items.forEach((el, index) => fn(el, index))
|
this.items.forEach((el, index) => fn(el, index))
|
||||||
}
|
}
|
||||||
@ -24,7 +28,7 @@ export default class DOMFleetManager<T extends HTMLElement = HTMLElement> {
|
|||||||
|
|
||||||
public refresh() {
|
public refresh() {
|
||||||
this.items = []
|
this.items = []
|
||||||
;(this.source || document).querySelectorAll<T>(this.query).forEach((item) => {
|
;(this.source instanceof DOMElement ? this.source.item : this.source || document).querySelectorAll<T>(this.query).forEach((item) => {
|
||||||
const element = DOMElement.get<T>(item)
|
const element = DOMElement.get<T>(item)
|
||||||
if (!element) {
|
if (!element) {
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user