2022-01-02 18:30:14 -08:00
|
|
|
export type OnCallbackFunction = (event: Event) => void;
|
2021-12-24 19:05:03 -08:00
|
|
|
|
|
|
|
export function on(type: string, selector: string, callback: OnCallbackFunction): void {
|
2021-12-24 18:31:30 -08:00
|
|
|
document.addEventListener(type, (event: Event) => {
|
|
|
|
if ((event.target as HTMLElement).matches(selector)) {
|
|
|
|
callback(event);
|
|
|
|
}
|
|
|
|
});
|
2021-12-24 19:05:03 -08:00
|
|
|
}
|