Permalink
Browse files

update mousewheel plugin

  • Loading branch information...
1 parent 51bb32f commit 7e22906c5a55d742b70d415b6a5fdefefe6d451c @Mottie committed Mar 2, 2012
Showing with 75 additions and 72 deletions.
  1. +4 −0 README.markdown
  2. +70 −71 js/jquery.mousewheel.js
  3. +1 −1 package.json
View
4 README.markdown
@@ -72,6 +72,10 @@ Moved to the Wiki Pages: [Home](https://github.com/Mottie/Keyboard/wiki/Home) |
Only the latest changes will be shown below, see the wiki log to view older versions.
+### Version 1.9.12.1
+
+* Updated jquery.mousewheel.js, as the it was only scrolling in one direction.
+
### Version 1.9.12
* Fixed an issue with an internal caret positioning flag not being set correctly. This change also fixes [issue #57](https://github.com/Mottie/Keyboard/issues/57).
View
141 js/jquery.mousewheel.js
@@ -1,85 +1,84 @@
-/* Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
- * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
- * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
+/*! Copyright (c) 2011 Brandon Aaron (http://brandonaaron.net)
+ * Licensed under the MIT License (LICENSE.txt).
+ *
* Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
* Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
+ * Thanks to: Seamus Leahy for adding deltaX and deltaY
*
- * $LastChangedDate: 2007-12-14 23:57:10 -0600 (Fri, 14 Dec 2007) $
- * $Rev: 4163 $
- *
- * Version: @VERSION
+ * Version: 3.0.6
*
- * Requires: $ 1.2.2+
+ * Requires: 1.2.2+
*/
(function($) {
-$.event.special.mousewheel = {
- setup: function() {
- var handler = $.event.special.mousewheel.handler;
-
- // Fix pageX, pageY, clientX and clientY for mozilla
- if ( $.browser.mozilla )
- $(this).bind('mousemove.mousewheel', function(event) {
- $.data(this, 'mwcursorposdata', {
- pageX: event.pageX,
- pageY: event.pageY,
- clientX: event.clientX,
- clientY: event.clientY
- });
- });
-
- if ( this.addEventListener )
- this.addEventListener( ($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
- else
- this.onmousewheel = handler;
- },
-
- teardown: function() {
- var handler = $.event.special.mousewheel.handler;
-
- $(this).unbind('mousemove.mousewheel');
-
- if ( this.removeEventListener )
- this.removeEventListener( ($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
- else
- this.onmousewheel = function(){};
-
- $.removeData(this, 'mwcursorposdata');
- },
-
- handler: function(event) {
- var args = Array.prototype.slice.call( arguments, 1 );
-
- event = $.event.fix(event || window.event);
- // Get correct pageX, pageY, clientX and clientY for mozilla
- $.extend( event, $.data(this, 'mwcursorposdata') || {} );
- var delta = 0, returnValue = true;
-
- if ( event.wheelDelta ) delta = event.wheelDelta/120;
- if ( event.detail ) delta = -event.detail/3;
- if ( $.browser.opera ) delta = -event.wheelDelta;
-
- event.data = event.data || {};
- event.type = "mousewheel";
-
- // Add delta to the front of the arguments
- args.unshift(delta);
- // Add event to the front of the arguments
- args.unshift(event);
+var types = ['DOMMouseScroll', 'mousewheel'];
+
+if ($.event.fixHooks) {
+ for ( var i=types.length; i; ) {
+ $.event.fixHooks[ types[--i] ] = $.event.mouseHooks;
+ }
+}
- return $.event.handle.apply(this, args);
- }
+$.event.special.mousewheel = {
+ setup: function() {
+ if ( this.addEventListener ) {
+ for ( var i=types.length; i; ) {
+ this.addEventListener( types[--i], handler, false );
+ }
+ } else {
+ this.onmousewheel = handler;
+ }
+ },
+
+ teardown: function() {
+ if ( this.removeEventListener ) {
+ for ( var i=types.length; i; ) {
+ this.removeEventListener( types[--i], handler, false );
+ }
+ } else {
+ this.onmousewheel = null;
+ }
+ }
};
$.fn.extend({
- mousewheel: function(fn) {
- return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
- },
-
- unmousewheel: function(fn) {
- return this.unbind("mousewheel", fn);
- }
+ mousewheel: function(fn) {
+ return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
+ },
+
+ unmousewheel: function(fn) {
+ return this.unbind("mousewheel", fn);
+ }
});
-})(jQuery);
+
+function handler(event) {
+ var orgEvent = event || window.event, args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true, deltaX = 0, deltaY = 0;
+ event = $.event.fix(orgEvent);
+ event.type = "mousewheel";
+
+ // Old school scrollwheel delta
+ if ( orgEvent.wheelDelta ) { delta = orgEvent.wheelDelta/120; }
+ if ( orgEvent.detail ) { delta = -orgEvent.detail/3; }
+
+ // New school multidimensional scroll (touchpads) deltas
+ deltaY = delta;
+
+ // Gecko
+ if ( orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
+ deltaY = 0;
+ deltaX = -1*delta;
+ }
+
+ // Webkit
+ if ( orgEvent.wheelDeltaY !== undefined ) { deltaY = orgEvent.wheelDeltaY/120; }
+ if ( orgEvent.wheelDeltaX !== undefined ) { deltaX = -1*orgEvent.wheelDeltaX/120; }
+
+ // Add event and delta to the front of the arguments
+ args.unshift(event, delta, deltaX, deltaY);
+
+ return ($.event.dispatch || $.event.handle).apply(this, args);
+}
+
+})(jQuery);
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "Keyboard",
- "version": "1.9.12",
+ "version": "1.9.12.1",
"title": "Keyboard",
"author": {
"name": "Jeremy Satterfield",

0 comments on commit 7e22906

Please sign in to comment.