Skip to content

Commit

Permalink
Rename addEventListener and removeEventListener (chartjs#6046)
Browse files Browse the repository at this point in the history
Prevent conflict with `window.addEventListener` and `window.removeEventListener` (global scope).
  • Loading branch information
kurkle authored and simonbrunel committed Feb 6, 2019
1 parent acd389a commit 5b36b22
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/platforms/platform.dom.js
Expand Up @@ -124,11 +124,11 @@ var supportsEventListenerOptions = (function() {
// https://github.com/chartjs/Chart.js/issues/4287
var eventListenerOptions = supportsEventListenerOptions ? {passive: true} : false;

function addEventListener(node, type, listener) {
function addListener(node, type, listener) {
node.addEventListener(type, listener, eventListenerOptions);
}

function removeEventListener(node, type, listener) {
function removeListener(node, type, listener) {
node.removeEventListener(type, listener, eventListenerOptions);
}

Expand Down Expand Up @@ -223,8 +223,8 @@ function createResizer(handler) {
handler();
};

addEventListener(expand, 'scroll', onScroll.bind(expand, 'expand'));
addEventListener(shrink, 'scroll', onScroll.bind(shrink, 'shrink'));
addListener(expand, 'scroll', onScroll.bind(expand, 'expand'));
addListener(shrink, 'scroll', onScroll.bind(shrink, 'shrink'));

return resizer;
}
Expand All @@ -239,7 +239,7 @@ function watchForRender(node, handler) {
};

helpers.each(ANIMATION_START_EVENTS, function(type) {
addEventListener(node, type, proxy);
addListener(node, type, proxy);
});

// #4737: Chrome might skip the CSS animation when the CSS_RENDER_MONITOR class
Expand All @@ -258,7 +258,7 @@ function unwatchForRender(node) {

if (proxy) {
helpers.each(ANIMATION_START_EVENTS, function(type) {
removeEventListener(node, type, proxy);
removeListener(node, type, proxy);
});

delete expando.renderProxy;
Expand Down Expand Up @@ -429,7 +429,7 @@ module.exports = {
listener(fromNativeEvent(event, chart));
};

addEventListener(canvas, type, proxy);
addListener(canvas, type, proxy);
},

removeEventListener: function(chart, type, listener) {
Expand All @@ -447,7 +447,7 @@ module.exports = {
return;
}

removeEventListener(canvas, type, proxy);
removeListener(canvas, type, proxy);
}
};

Expand All @@ -462,7 +462,7 @@ module.exports = {
* @todo remove at version 3
* @private
*/
helpers.addEvent = addEventListener;
helpers.addEvent = addListener;

/**
* Provided for backward compatibility, use EventTarget.removeEventListener instead.
Expand All @@ -473,4 +473,4 @@ helpers.addEvent = addEventListener;
* @todo remove at version 3
* @private
*/
helpers.removeEvent = removeEventListener;
helpers.removeEvent = removeListener;

0 comments on commit 5b36b22

Please sign in to comment.