@@ -59,15 +59,9 @@ var Events = {
59
59
internalEv . emit ( event , data ) ;
60
60
} ;
61
61
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 ) ;
71
65
72
66
return plotObj ;
73
67
} ,
@@ -140,4 +134,35 @@ var Events = {
140
134
141
135
} ;
142
136
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
+
143
168
module . exports = Events ;
0 commit comments