|
22 | 22 | } )( function( $ ) { |
23 | 23 | "use strict"; |
24 | 24 |
|
25 | | - var toFix = [ "wheel", "mousewheel", "DOMMouseScroll", "MozMousePixelScroll" ], |
| 25 | + var nullLowestDeltaTimeout, lowestDelta, |
| 26 | + modernEvents = !!$.fn.on, |
| 27 | + toFix = [ "wheel", "mousewheel", "DOMMouseScroll", "MozMousePixelScroll" ], |
26 | 28 | toBind = ( "onwheel" in window.document || window.document.documentMode >= 9 ) ? |
27 | 29 | [ "wheel" ] : [ "mousewheel", "DomMouseScroll", "MozMousePixelScroll" ], |
28 | | - slice = Array.prototype.slice, |
29 | | - nullLowestDeltaTimeout, lowestDelta; |
| 30 | + slice = Array.prototype.slice; |
30 | 31 |
|
31 | 32 | if ( $.event.fixHooks ) { |
32 | 33 | for ( var i = toFix.length; i; ) { |
|
87 | 88 |
|
88 | 89 | $.fn.extend( { |
89 | 90 | mousewheel: function( fn ) { |
90 | | - return fn ? this.on( "mousewheel", fn ) : this.trigger( "mousewheel" ); |
| 91 | + return fn ? |
| 92 | + this[ modernEvents ? "on" : "bind" ]( "mousewheel", fn ) : |
| 93 | + this.trigger( "mousewheel" ); |
91 | 94 | }, |
92 | 95 |
|
93 | 96 | unmousewheel: function( fn ) { |
94 | | - return this.off( "mousewheel", fn ); |
| 97 | + return this[ modernEvents ? "off" : "unbind" ]( "mousewheel", fn ); |
95 | 98 | } |
96 | 99 | } ); |
97 | 100 |
|
|
126 | 129 | deltaY = 0; |
127 | 130 | } |
128 | 131 |
|
129 | | - // Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy |
| 132 | + // Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatability |
130 | 133 | delta = deltaY === 0 ? deltaX : deltaY; |
131 | 134 |
|
132 | 135 | // New school wheel delta (wheel event) |
|
209 | 212 | // Add event and delta to the front of the arguments |
210 | 213 | args.unshift( event, delta, deltaX, deltaY ); |
211 | 214 |
|
212 | | - // Clearout lowestDelta after sometime to better |
| 215 | + // Clear out lowestDelta after sometime to better |
213 | 216 | // handle multiple device types that give different |
214 | 217 | // a different lowestDelta |
215 | 218 | // Ex: trackpad = 3 and mouse wheel = 120 |
216 | 219 | if ( nullLowestDeltaTimeout ) { |
217 | 220 | window.clearTimeout( nullLowestDeltaTimeout ); |
218 | 221 | } |
219 | | - nullLowestDeltaTimeout = window.setTimeout( nullLowestDelta, 200 ); |
| 222 | + nullLowestDeltaTimeout = window.setTimeout( function() { |
| 223 | + lowestDelta = null; |
| 224 | + }, 200 ); |
220 | 225 |
|
221 | 226 | return ( $.event.dispatch || $.event.handle ).apply( this, args ); |
222 | 227 | } |
223 | 228 |
|
224 | | - function nullLowestDelta() { |
225 | | - lowestDelta = null; |
226 | | - } |
227 | | - |
228 | 229 | function shouldAdjustOldDeltas( orgEvent, absDelta ) { |
229 | 230 |
|
230 | | - // If this is an older event and the delta is divisable by 120, |
| 231 | + // If this is an older event and the delta is divisible by 120, |
231 | 232 | // then we are assuming that the browser is treating this as an |
232 | 233 | // older mouse wheel event and that we should divide the deltas |
233 | 234 | // by 40 to try and get a more usable deltaFactor. |
|
0 commit comments