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

9 lines
289 B
TypeScript
Raw Normal View History

2021-12-24 19:05:03 -08:00
type OnCallbackFunction = (event: Event) => void;
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
}