Permalink
Browse files

Fixing jQuery mouse wheel problems

Fixing broken mouse wheel when using jQuery 1.7+, and added missing
Mozilla Firefox 3+ mouse wheel support by reusing normalisation code
taken from the non-jQuery events.js file. Fix successfully tested using
jQuery 1.6.3-1.8.2.
  • Loading branch information...
1 parent 9d4cbe9 commit a8f23e448140a31107550e5d021c2bd889d780c3 @thorstein5 thorstein5 committed Oct 11, 2012
Showing with 25 additions and 4 deletions.
  1. +25 −4 src/lib/code.util-1.0.6/src/events.jquery.js
@@ -15,6 +15,10 @@
*/
add: function(obj, type, handler){
+ if (type === 'mousewheel'){
+ type = this._normaliseMouseWheelType();
+ }
+
$(obj).bind(type, handler);
},
@@ -27,6 +31,10 @@
*/
remove: function(obj, type, handler){
+ if (type === 'mousewheel'){
+ type = this._normaliseMouseWheelType();
+ }
+
$(obj).unbind(type, handler);
},
@@ -42,6 +50,10 @@
event,
args = Array.prototype.slice.call(arguments).splice(2);
+ if (type === 'mousewheel'){
+ type = this._normaliseMouseWheelType();
+ }
+
if (typeof type === "string"){
event = { type: type };
}
@@ -87,11 +99,11 @@
var delta = 0;
- if (!Util.isNothing(event.wheelDelta)){
- delta = event.wheelDelta / 120;
+ if (!Util.isNothing(event.originalEvent.wheelDelta)){
+ delta = event.originalEvent.wheelDelta / 120;
}
- else if (!Util.isNothing(event.detail)){
- delta = -event.detail / 3;
+ else if (!Util.isNothing(event.originalEvent.detail)){
+ delta = -event.originalEvent.detail / 3;
}
return delta;
@@ -106,6 +118,15 @@
$(document).ready(handler);
+ },
+
+ _normaliseMouseWheelType: function(){
+
+ if (Util.Browser.isEventSupported('mousewheel')){
+ return 'mousewheel';
+ }
+ return 'DOMMouseScroll';
+
}

0 comments on commit a8f23e4

Please sign in to comment.