Skip to content

Commit

Permalink
check for null value on target element before trying to remove events
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Holmes committed Nov 23, 2016
1 parent ea7b00b commit 1aeec16
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@
win = this.base.options.contentWindow,
doc = this.base.options.ownerDocument;

targets = MediumEditor.util.isElement(targets) || [win, doc].indexOf(targets) > -1 ? [targets] : targets;

Array.prototype.forEach.call(targets, function (target) {
index = this.indexOfListener(target, event, listener, useCapture);
if (index !== -1) {
e = this.events.splice(index, 1)[0];
e[0].removeEventListener(e[1], e[2], e[3]);
}
}.bind(this));
if (targets !== null) {
targets = MediumEditor.util.isElement(targets) || [win, doc].indexOf(targets) > -1 ? [targets] : targets;

Array.prototype.forEach.call(targets, function (target) {
index = this.indexOfListener(target, event, listener, useCapture);
if (index !== -1) {
e = this.events.splice(index, 1)[0];
e[0].removeEventListener(e[1], e[2], e[3]);
}
}.bind(this));
}
},

indexOfListener: function (target, event, listener, useCapture) {
Expand Down

0 comments on commit 1aeec16

Please sign in to comment.