From d55a79ef9ff60e4b49cde4598664a2ff682316f5 Mon Sep 17 00:00:00 2001 From: Brandon Aaron Date: Mon, 16 Dec 2013 09:24:00 -0500 Subject: [PATCH] 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. --- ChangeLog.md | 6 ++++++ bower.json | 2 +- jquery.mousewheel.js | 34 ++++++++++++++++++++++------------ mousewheel.jquery.json | 2 +- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 1e524d9b8..19bb7372e 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,11 @@ # Mouse Wheel ChangeLog +## 3.1.9 + +* Fix bower.json file +* Updated how the deltas are adjusted for older mousewheel based events that have deltas that are factors of 120. +* 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. + ## 3.1.8 * Even better handling of older browsers that use a wheelDelta based on 120 diff --git a/bower.json b/bower.json index fe233c709..3b5f803d5 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery-mousewheel", - "version": "3.1.8", + "version": "3.1.9", "main": "./jquery.mousewheel.js", "ignore": [ "*.json", diff --git a/jquery.mousewheel.js b/jquery.mousewheel.js index c41b7af37..63c968a84 100755 --- a/jquery.mousewheel.js +++ b/jquery.mousewheel.js @@ -1,7 +1,7 @@ /*! Copyright (c) 2013 Brandon Aaron (http://brandon.aaron.sh) * Licensed under the MIT License (LICENSE.txt). * - * Version: 3.1.8 + * Version: 3.1.9 * * Requires: jQuery 1.2.2+ */ @@ -23,7 +23,7 @@ toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ? ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'], slice = Array.prototype.slice, - oldMode, nullLowestDeltaTimeout, lowestDelta; + nullLowestDeltaTimeout, lowestDelta; if ( $.event.fixHooks ) { for ( var i = toFix.length; i; ) { @@ -32,7 +32,7 @@ } var special = $.event.special.mousewheel = { - version: '3.1.8', + version: '3.1.9', setup: function() { if ( this.addEventListener ) { @@ -63,6 +63,10 @@ getPageHeight: function(elem) { return $(elem).height(); + }, + + settings: { + adjustOldDeltas: true } }; @@ -138,18 +142,14 @@ if ( !lowestDelta || absDelta < lowestDelta ) { lowestDelta = absDelta; - // Assuming that if the lowestDelta is 120, then that the browser - // is treating this as an older mouse wheel event. - // We'll divide it by 40 to try and get a more usable deltaFactor. - if ( lowestDelta === 120 ) { - oldMode = true; + // Adjust older deltas if necessary + if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) { lowestDelta /= 40; } } - // When in oldMode the delta is based on 120. - // Dividing by 40 to try and get a more usable deltaFactor. - if ( oldMode ) { + // Adjust older deltas if necessary + if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) { // Divide all the things by 40! delta /= 40; deltaX /= 40; @@ -185,7 +185,17 @@ function nullLowestDelta() { lowestDelta = null; - oldMode = null; + } + + function shouldAdjustOldDeltas(orgEvent, absDelta) { + // If this is an older event and the delta is divisable by 120, + // then we are assuming that the browser is treating this as an + // older mouse wheel event and that we should divide the deltas + // by 40 to try and get a more usable deltaFactor. + // Side note, this actually impacts the reported scroll distance + // in older browsers and can cause scrolling to be slower than native. + // Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false. + return special.settings.adjustOldDeltas && orgEvent.type === 'mousewheel' && absDelta % 120 === 0; } })); diff --git a/mousewheel.jquery.json b/mousewheel.jquery.json index b0a211708..270109e6d 100644 --- a/mousewheel.jquery.json +++ b/mousewheel.jquery.json @@ -7,7 +7,7 @@ "mouse", "event" ], - "version": "3.1.8", + "version": "3.1.9", "author": { "name": "Brandon Aaron", "url": "http://brandon.aaron.sh"