Skip to content

Commit d55a79e

Browse files
committed
Bumping to 3.1.9. Including a fix for the broken bower.json in 3.1.8 and
updates to the old delta handling code.
1 parent 0a7fe84 commit d55a79e

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

ChangeLog.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Mouse Wheel ChangeLog
22

3+
## 3.1.9
4+
5+
* Fix bower.json file
6+
* Updated how the deltas are adjusted for older mousewheel based events that have deltas that are factors of 120.
7+
* Add $.event.special.mousewheel.settings.adjustOldDeltas (defaults to true) to turn off adjusting of old deltas that are factors of 120. You'd turn this off if you want to be as close to native scrolling as possible.
8+
39
## 3.1.8
410

511
* Even better handling of older browsers that use a wheelDelta based on 120

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-mousewheel",
3-
"version": "3.1.8",
3+
"version": "3.1.9",
44
"main": "./jquery.mousewheel.js",
55
"ignore": [
66
"*.json",

jquery.mousewheel.js

+22-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*! Copyright (c) 2013 Brandon Aaron (http://brandon.aaron.sh)
22
* Licensed under the MIT License (LICENSE.txt).
33
*
4-
* Version: 3.1.8
4+
* Version: 3.1.9
55
*
66
* Requires: jQuery 1.2.2+
77
*/
@@ -23,7 +23,7 @@
2323
toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ?
2424
['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'],
2525
slice = Array.prototype.slice,
26-
oldMode, nullLowestDeltaTimeout, lowestDelta;
26+
nullLowestDeltaTimeout, lowestDelta;
2727

2828
if ( $.event.fixHooks ) {
2929
for ( var i = toFix.length; i; ) {
@@ -32,7 +32,7 @@
3232
}
3333

3434
var special = $.event.special.mousewheel = {
35-
version: '3.1.8',
35+
version: '3.1.9',
3636

3737
setup: function() {
3838
if ( this.addEventListener ) {
@@ -63,6 +63,10 @@
6363

6464
getPageHeight: function(elem) {
6565
return $(elem).height();
66+
},
67+
68+
settings: {
69+
adjustOldDeltas: true
6670
}
6771
};
6872

@@ -138,18 +142,14 @@
138142
if ( !lowestDelta || absDelta < lowestDelta ) {
139143
lowestDelta = absDelta;
140144

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) ) {
146147
lowestDelta /= 40;
147148
}
148149
}
149150

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) ) {
153153
// Divide all the things by 40!
154154
delta /= 40;
155155
deltaX /= 40;
@@ -185,7 +185,17 @@
185185

186186
function nullLowestDelta() {
187187
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;
189199
}
190200

191201
}));

mousewheel.jquery.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"mouse",
88
"event"
99
],
10-
"version": "3.1.8",
10+
"version": "3.1.9",
1111
"author": {
1212
"name": "Brandon Aaron",
1313
"url": "http://brandon.aaron.sh"

0 commit comments

Comments
 (0)