Skip to content

Commit 55a80cb

Browse files
committed
Added tab indentation and passive event listeners!
Added `tab` indentation and updated code to add support for passive event listeners!
1 parent 82e44a7 commit 55a80cb

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

src/jquery.mousewheel.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* Released under the MIT license
77
* https://jquery.org/license
88
*/
9-
109
( function( factory ) {
1110
"use strict";
1211

@@ -37,15 +36,43 @@
3736
version: "@VERSION",
3837

3938
setup: function() {
40-
this.addEventListener( "wheel", handler, false );
39+
// Use passive event listeners if supported
40+
var passiveSupported = false;
41+
try {
42+
var opts = Object.defineProperty({}, "passive", {
43+
get: function() {
44+
passiveSupported = true;
45+
}
46+
});
47+
window.addEventListener("test", null, opts);
48+
} catch (e) {}
49+
this.addEventListener(
50+
"wheel",
51+
handler,
52+
passiveSupported ? { passive: true } : false
53+
);
4154

4255
// Store the line height and page height for this particular element
4356
$.data( this, "mousewheel-line-height", special.getLineHeight( this ) );
4457
$.data( this, "mousewheel-page-height", special.getPageHeight( this ) );
4558
},
4659

4760
teardown: function() {
48-
this.removeEventListener( "wheel", handler, false );
61+
// Use passive event listeners if supported
62+
var passiveSupported = false;
63+
try {
64+
var opts = Object.defineProperty({}, "passive", {
65+
get: function() {
66+
passiveSupported = true;
67+
}
68+
});
69+
window.addEventListener("test", null, opts);
70+
} catch (e) {}
71+
this.removeEventListener(
72+
"wheel",
73+
handler,
74+
passiveSupported ? { passive: true } : false
75+
);
4976

5077
// Clean up the data we added to the element
5178
$.removeData( this, "mousewheel-line-height" );
@@ -90,7 +117,7 @@
90117
deltaX = origEvent.deltaX;
91118
if ( deltaY === 0 ) {
92119
delta = deltaX * -1;
93-
}
120+
}
94121
}
95122

96123
// No change actually happened, no reason to go any further

0 commit comments

Comments
 (0)