diff options
-rw-r--r-- | ext/mixed/js/display.js | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 2f7a694e..46016192 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -28,6 +28,7 @@ class Display { this.index = 0; this.audioCache = {}; this.optionsContext = {}; + this.eventListeners = []; this.dependencies = {}; @@ -283,6 +284,8 @@ class Display { async termsShow(definitions, options, context) { try { + this.clearEventListeners(); + if (!context || context.focus !== false) { window.focus(); } @@ -339,6 +342,8 @@ class Display { async kanjiShow(definitions, options, context) { try { + this.clearEventListeners(); + if (!context || context.focus !== false) { window.focus(); } @@ -610,8 +615,18 @@ class Display { return -1; } - addEventListeners(selector, ...args) { - this.container.querySelectorAll(selector).forEach((node) => node.addEventListener(...args)); + addEventListeners(selector, type, listener, options) { + this.container.querySelectorAll(selector).forEach((node) => { + node.addEventListener(type, listener, options); + this.eventListeners.push([node, type, listener, options]); + }); + } + + clearEventListeners() { + for (const [node, type, listener, options] of this.eventListeners) { + node.removeEventListener(type, listener, options); + } + this.eventListeners = []; } static getElementTop(element) { |