|  | 
| 1 | 1 | /*! Copyright (c) 2013 Brandon Aaron (http://brandon.aaron.sh) | 
| 2 | 2 |  * Licensed under the MIT License (LICENSE.txt). | 
| 3 | 3 |  * | 
| 4 |  | - * Version: 3.1.8 | 
|  | 4 | + * Version: 3.1.9 | 
| 5 | 5 |  * | 
| 6 | 6 |  * Requires: jQuery 1.2.2+ | 
| 7 | 7 |  */ | 
|  | 
| 23 | 23 |  toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ? | 
| 24 | 24 |  ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'], | 
| 25 | 25 |  slice = Array.prototype.slice, | 
| 26 |  | - oldMode, nullLowestDeltaTimeout, lowestDelta; | 
|  | 26 | + nullLowestDeltaTimeout, lowestDelta; | 
| 27 | 27 | 
 | 
| 28 | 28 |  if ( $.event.fixHooks ) { | 
| 29 | 29 |  for ( var i = toFix.length; i; ) { | 
|  | 
| 32 | 32 |  } | 
| 33 | 33 | 
 | 
| 34 | 34 |  var special = $.event.special.mousewheel = { | 
| 35 |  | - version: '3.1.8', | 
|  | 35 | + version: '3.1.9', | 
| 36 | 36 | 
 | 
| 37 | 37 |  setup: function() { | 
| 38 | 38 |  if ( this.addEventListener ) { | 
|  | 
| 63 | 63 | 
 | 
| 64 | 64 |  getPageHeight: function(elem) { | 
| 65 | 65 |  return $(elem).height(); | 
|  | 66 | + }, | 
|  | 67 | + | 
|  | 68 | + settings: { | 
|  | 69 | + adjustOldDeltas: true | 
| 66 | 70 |  } | 
| 67 | 71 |  }; | 
| 68 | 72 | 
 | 
|  | 
| 138 | 142 |  if ( !lowestDelta || absDelta < lowestDelta ) { | 
| 139 | 143 |  lowestDelta = absDelta; | 
| 140 | 144 | 
 | 
| 141 |  | - // Assuming that if the lowestDelta is 120, then that the browser | 
| 142 |  | - // is treating this as an older mouse wheel event. | 
| 143 |  | - // We'll divide it by 40 to try and get a more usable deltaFactor. | 
| 144 |  | - if ( lowestDelta === 120 ) { | 
| 145 |  | - oldMode = true; | 
|  | 145 | + // Adjust older deltas if necessary | 
|  | 146 | + if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) { | 
| 146 | 147 |  lowestDelta /= 40; | 
| 147 | 148 |  } | 
| 148 | 149 |  } | 
| 149 | 150 | 
 | 
| 150 |  | - // When in oldMode the delta is based on 120. | 
| 151 |  | - // Dividing by 40 to try and get a more usable deltaFactor. | 
| 152 |  | - if ( oldMode ) { | 
|  | 151 | + // Adjust older deltas if necessary | 
|  | 152 | + if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) { | 
| 153 | 153 |  // Divide all the things by 40! | 
| 154 | 154 |  delta /= 40; | 
| 155 | 155 |  deltaX /= 40; | 
|  | 
| 185 | 185 | 
 | 
| 186 | 186 |  function nullLowestDelta() { | 
| 187 | 187 |  lowestDelta = null; | 
| 188 |  | - oldMode = null; | 
|  | 188 | + } | 
|  | 189 | + | 
|  | 190 | + function shouldAdjustOldDeltas(orgEvent, absDelta) { | 
|  | 191 | + // If this is an older event and the delta is divisable by 120, | 
|  | 192 | + // then we are assuming that the browser is treating this as an | 
|  | 193 | + // older mouse wheel event and that we should divide the deltas | 
|  | 194 | + // by 40 to try and get a more usable deltaFactor. | 
|  | 195 | + // Side note, this actually impacts the reported scroll distance | 
|  | 196 | + // in older browsers and can cause scrolling to be slower than native. | 
|  | 197 | + // Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false. | 
|  | 198 | + return special.settings.adjustOldDeltas && orgEvent.type === 'mousewheel' && absDelta % 120 === 0; | 
| 189 | 199 |  } | 
| 190 | 200 | 
 | 
| 191 | 201 | })); | 
0 commit comments