aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-15 18:52:26 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-27 21:41:00 -0400
commite358c94882ba4fea134ca0a21824055d09719143 (patch)
tree04b346150f8e4973a06bf7e0c8f3ec42f69502a8
parent1a7ad3011109dfb9cb51b5b89740fae1cb8a7035 (diff)
Clean up event listeners
-rw-r--r--ext/mixed/js/display.js19
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) {