Skip to content

Commit f631006

Browse files
authored
Merge pull request #1057 from n-gist/fix-event-listener-violation
Fix event listener violation for touchstart, touchmove event
2 parents a07646e + 6e9a395 commit f631006

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/dygraph-utils.js

+17-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export var LN_TEN = Math.log(LOG_SCALE);
3636
*/
3737
export var log10 = function(x) {
3838
return Math.log(x) / LN_TEN;
39-
};
39+
}
4040

4141
/**
4242
* @private
@@ -69,7 +69,7 @@ export var logRangeFraction = function(r0, r1, pct) {
6969
var exponent = logr0 + (pct * (logr1 - logr0));
7070
var value = Math.pow(LOG_SCALE, exponent);
7171
return value;
72-
};
72+
}
7373

7474
/** A dotted line stroke pattern. */
7575
export var DOTTED_LINE = [2, 2];
@@ -95,7 +95,18 @@ export var VERTICAL = 2;
9595
*/
9696
export var getContext = function(canvas) {
9797
return /** @type{!CanvasRenderingContext2D}*/(canvas.getContext("2d"));
98-
};
98+
}
99+
100+
/**
101+
* EventListener options
102+
*/
103+
function _eventListenerOptions(type) {
104+
const options = { capture: false };
105+
if (type === 'touchstart' || type === 'touchmove') {
106+
options.passive = true;
107+
}
108+
return options;
109+
}
99110

100111
/**
101112
* Add an event handler.
@@ -106,8 +117,8 @@ export var getContext = function(canvas) {
106117
* @private
107118
*/
108119
export var addEvent = function addEvent(elem, type, fn) {
109-
elem.addEventListener(type, fn, false);
110-
};
120+
elem.addEventListener(type, fn, _eventListenerOptions(type));
121+
}
111122

112123
/**
113124
* Remove an event handler.
@@ -117,7 +128,7 @@ export var addEvent = function addEvent(elem, type, fn) {
117128
* on the event. The function takes one parameter: the event object.
118129
*/
119130
export function removeEvent(elem, type, fn) {
120-
elem.removeEventListener(type, fn, false);
131+
elem.removeEventListener(type, fn, _eventListenerOptions(type));
121132
}
122133

123134
/**

0 commit comments

Comments
 (0)