mirror of
https://github.com/dzeiocom/libs.git
synced 2025-04-22 10:52:11 +00:00
Made Functions more clear
Signed-off-by: Florian Bouillon <florian.bouillon@delta-wings.net>
This commit is contained in:
parent
e29eafd2d2
commit
916406560b
@ -12,15 +12,24 @@ export default class DOMElement<T extends HTMLElement = HTMLElement> {
|
|||||||
this.item = document.createElement(tagName, options) as any
|
this.item = document.createElement(tagName, options) as any
|
||||||
}
|
}
|
||||||
|
|
||||||
public static create<K extends Tags>(tagName: K, options?: ElementCreationOptions): DOMElement<HTMLElementTagNameMap[K]>;
|
public static create<K extends Tags>(
|
||||||
public static create(tagName: string, options?: ElementCreationOptions): DOMElement<HTMLElement> {
|
tagName: K,
|
||||||
|
options?: ElementCreationOptions
|
||||||
|
): DOMElement<HTMLElementTagNameMap[K]>
|
||||||
|
public static create(
|
||||||
|
tagName: string,
|
||||||
|
options?: ElementCreationOptions
|
||||||
|
): DOMElement<HTMLElement> {
|
||||||
return new DOMElement(tagName as Tags, options)
|
return new DOMElement(tagName as Tags, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static get<T extends HTMLElement = HTMLElement>(query: string | T, source?: HTMLElement | DOMElement): DOMElement<T> | undefined {
|
public static get<GT extends HTMLElement = HTMLElement>(
|
||||||
|
query: string | GT,
|
||||||
|
source?: HTMLElement | DOMElement
|
||||||
|
): DOMElement<GT> | undefined {
|
||||||
if (!(query instanceof HTMLElement)) {
|
if (!(query instanceof HTMLElement)) {
|
||||||
const tmp = (source instanceof DOMElement ? source.item : source || document).querySelector<T>(query)
|
const tmp = (source instanceof DOMElement ? source.item : source || document).querySelector<GT>(query)
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
@ -29,14 +38,29 @@ export default class DOMElement<T extends HTMLElement = HTMLElement> {
|
|||||||
return new DOMElement(query)
|
return new DOMElement(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
public on<K extends keyof HTMLElementEventMap>(type: K, listener: (this: T, ev: HTMLElementEventMap[K]) => void, options?: boolean | AddEventListenerOptions): this
|
public on<K extends keyof HTMLElementEventMap>(
|
||||||
public on(type: string, listener: (this: T, ev: Event) => void, options?: boolean | AddEventListenerOptions): this
|
type: K,
|
||||||
public on(type: string, listener: (this: T, ev: Event) => void, options?: boolean | AddEventListenerOptions) {
|
listener: (this: T, ev: HTMLElementEventMap[K]) => void,
|
||||||
|
options?: boolean | AddEventListenerOptions
|
||||||
|
): this
|
||||||
|
public on(
|
||||||
|
type: string,
|
||||||
|
listener: (this: T, ev: Event) => void,
|
||||||
|
options?: boolean | AddEventListenerOptions
|
||||||
|
): this
|
||||||
|
public on(
|
||||||
|
type: string,
|
||||||
|
listener: (this: T, ev: Event) => void,
|
||||||
|
options?: boolean | AddEventListenerOptions
|
||||||
|
) {
|
||||||
this.item.addEventListener(type, listener, options)
|
this.item.addEventListener(type, listener, options)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
public off<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => void) {
|
public off<K extends keyof HTMLElementEventMap>(
|
||||||
|
type: K,
|
||||||
|
listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => void
|
||||||
|
) {
|
||||||
this.item.removeEventListener(type, listener)
|
this.item.removeEventListener(type, listener)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user