From 1205d555835772da4e43e0dc8bd60ac449c74ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 15 Nov 2021 00:50:44 +0100 Subject: Add HTMLElement.getListeners. --- static/lib.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'static') diff --git a/static/lib.ts b/static/lib.ts index 1dfd83f4..8845f37b 100644 --- a/static/lib.ts +++ b/static/lib.ts @@ -18,7 +18,8 @@ declare global { interface HTMLElement { _addEventListener: (name: string, proc: (e: Event) => void) => void - listeners: Record void)[]> + listeners: Map void)[]> + getListeners: () => Map void)[]> } interface Date { @@ -43,11 +44,15 @@ declare global { HTMLElement.prototype._addEventListener = HTMLElement.prototype.addEventListener; HTMLElement.prototype.addEventListener = function(name: string, proc: (e: Event) => void) { - if (!this.listeners) this.listeners = {}; - if (!this.listeners[name]) this.listeners[name] = []; - this.listeners[name].push(proc); + if (!this.listeners) this.listeners = new Map + if (!this.listeners.get(name)) this.listeners.set(name, []); + /* Force since we ensure a value just above */ + this.listeners.get(name)!.push(proc); return this._addEventListener(name, proc); }; +HTMLElement.prototype.getListeners = function() { + return this.listeners; +} /* ----- Date Extensions ---------------------------- */ -- cgit v1.2.3