From 3b5e963da5875e014006fc7355ffb4822d5ed45c Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sat, 25 Dec 2021 03:31:30 +0100 Subject: [PATCH] Add `$.on` vanilla JS substitute --- app/javascript/retrospring/utilities/on.ts | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 app/javascript/retrospring/utilities/on.ts diff --git a/app/javascript/retrospring/utilities/on.ts b/app/javascript/retrospring/utilities/on.ts new file mode 100644 index 00000000..1d7d5211 --- /dev/null +++ b/app/javascript/retrospring/utilities/on.ts @@ -0,0 +1,7 @@ +export function on(type: string, selector: string, callback: Function): void { + document.addEventListener(type, (event: Event) => { + if ((event.target as HTMLElement).matches(selector)) { + callback(event); + } + }); +}; \ No newline at end of file