Retrospring/app/javascript/retrospring/utilities/on.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

9 lines
296 B
TypeScript
Raw Normal View History

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
}