Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2f65ccd

Browse files
committed
fix wheel event handler Violation in Chromium by setting passive: true
1 parent 9ae845a commit 2f65ccd

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

‎src/lib/events.js

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,9 @@ var Events = {
5959
internalEv.emit(event, data);
6060
};
6161

62-
/*
63-
* Add a dummy event handler for 'wheel' event for Safari
64-
* to enable mouse wheel zoom.
65-
* https://github.com/d3/d3/issues/3035
66-
* https://github.com/plotly/plotly.js/issues/7452
67-
*/
68-
if(typeof plotObj.addEventListener === 'function') {
69-
plotObj.addEventListener("wheel", () => {});
70-
}
62+
// Add a dummy event handler for 'wheel' event for Safari
63+
// to enable mouse wheel zoom.
64+
addDummyScrollEventListener(plotObj);
7165

7266
return plotObj;
7367
},
@@ -140,4 +134,35 @@ var Events = {
140134

141135
};
142136

137+
function addDummyScrollEventListener(plotObj) {
138+
/*
139+
* Add a dummy event handler for 'wheel' event for Safari
140+
* to enable mouse wheel zoom.
141+
* https://github.com/d3/d3/issues/3035
142+
* https://github.com/plotly/plotly.js/issues/7452
143+
*
144+
* We set {passive: true} for better performance
145+
* and to avoid a Violation warning in Chromium.
146+
* https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
147+
* https://github.com/plotly/plotly.js/issues/7516
148+
*/
149+
150+
// Test whether the passive property is accessed (for compatibility with older browsers)
151+
var supportsPassive = false;
152+
try {
153+
var opts = Object.defineProperty({}, 'passive', {
154+
get: function() {
155+
supportsPassive = true;
156+
}
157+
});
158+
window.addEventListener("testPassive", null, opts);
159+
window.removeEventListener("testPassive", null, opts);
160+
} catch (e) {}
161+
162+
if(typeof plotObj.addEventListener === 'function') {
163+
plotObj.addEventListener("wheel", () => {}, supportsPassive ? { passive: true } : false);
164+
}
165+
166+
}
167+
143168
module.exports = Events;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /