diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..ab49093a6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/npm-debug.log diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 000000000..4a68afd94 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,19 @@ +{ + "bitwise": true, + "browser" : true, + "camelcase": true, + "curly": true, + "eqeqeq": true, + "indent": 4, + "jquery" : true, + "latedef": true, + "maxerr": 50, + "noarg": true, + "node" : true, + "noempty": true, + "plusplus": false, + "regexp": true, + "strict": false, + "trailing": true, + "unused": true +} \ No newline at end of file diff --git a/ChangeLog.markdown b/ChangeLog.markdown index abee92e07..49029a802 100644 --- a/ChangeLog.markdown +++ b/ChangeLog.markdown @@ -1,11 +1,11 @@ # Mouse Wheel ChangeLog -# 3.1.1 +## 3.1.1 * Fix rounding issue with deltas less than zero -# 3.1.0 +## 3.1.0 * Fix Firefox 17+ issues by using new wheel event * Normalize delta values @@ -13,68 +13,68 @@ * Support AMD loaders -# 3.0.6 +## 3.0.6 * Fix issue with delta being 0 in Firefox -# 3.0.5 +## 3.0.5 * jQuery 1.7 compatibility -# 3.0.4 +## 3.0.4 * Fix IE issue -# 3.0.3 +## 3.0.3 * Added deltaX and deltaY for horizontal scrolling support (Thanks to Seamus Leahy) -# 3.0.2 +## 3.0.2 * Fixed delta being opposite value in latest Opera -* No longer fix pageX, pageY for older mozilla browsers +* No longer fix `pageX`, `pageY` for older Mozilla browsers * Removed browser detection * Cleaned up the code -# 3.0.1 +## 3.0.1 * Bad release... creating a new release due to plugins.jquery.com issue :( -# 3.0 +## 3.0 * Uses new special events API in jQuery 1.2.2+ -* You can now treat "mousewheel" as a normal event and use .bind, .unbind and .trigger +* You can now treat `mousewheel` as a normal event and use `.bind`, `.unbind` and `.trigger` * Using jQuery.data API for expandos -# 2.2 +## 2.2 -* Fixed pageX, pageY, clientX and clientY event properties for Mozilla based browsers +* Fixed `pageX`, `pageY`, `clientX` and `clientY` event properties for Mozilla based browsers -# 2.1.1 +## 2.1.1 * Updated to work with jQuery 1.1.3 * Used one instead of bind to do unload event for clean up. -# 2.1 +## 2.1 * Fixed an issue with the unload handler -# 2.0 +## 2.0 * Major reduction in code size and complexity (internals have change a whole lot) -# 1.0 +## 1.0 * Fixed Opera issue * Fixed an issue with children elements that also have a mousewheel handler diff --git a/LICENSE.txt b/LICENSE.txt index d3d21c42b..d64b7076b 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,5 +1,5 @@ -Copyright 2011, Brandon Aaron (http://brandonaaron.net/) - +Copyright (c) 2013, Brandon Aaron (http://brandonaaron.net/) + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including @@ -7,10 +7,10 @@ without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND diff --git a/README.markdown b/README.markdown index a450bb231..75e3cdec1 100644 --- a/README.markdown +++ b/README.markdown @@ -2,25 +2,30 @@ A jQuery plugin that adds cross-browser mouse wheel support. -In order to use the plugin, simply bind the "mousewheel" event to an element. It also provides two helper methods called `mousewheel` and `unmousewheel` that act just like other event helper methods in jQuery. The event callback receives three extra arguments which are the normalized "deltas" of the mouse wheel. +In order to use the plugin, simply bind the `mousewheel` event to an element. +It also provides two helper methods called `mousewheel` and `unmousewheel` +that act just like other event helper methods in jQuery. The event callback +receives three extra arguments which are the normalized "deltas" of the mouse wheel. Here is an example of using both the bind and helper method syntax. - // using bind - $('#my_elem').bind('mousewheel', function(event, delta, deltaX, deltaY) { - console.log(delta, deltaX, deltaY); - }); +```js +// using bind +$('#my_elem').bind('mousewheel', function(event, delta, deltaX, deltaY) { + console.log(delta, deltaX, deltaY); +}); - // using the event helper - $('#my_elem').mousewheel(function(event, delta, deltaX, deltaY) { - console.log(delta, deltaX, deltaY); - }); +// using the event helper +$('#my_elem').mousewheel(function(event, delta, deltaX, deltaY) { + console.log(delta, deltaX, deltaY); +}); +``` ## See it in action [See the tests on Github](http://brandonaaron.github.com/jquery-mousewheel/test) or navigate to `test/index.html` in your browser. ## License -This plugin is licensed under the MIT License (LICENSE.txt). +This plugin is licensed under the [MIT License](LICENSE.txt). Copyright (c) 2013 [Brandon Aaron](http://brandonaaron.net) diff --git a/jquery.mousewheel.js b/jquery.mousewheel.js index 7c398d76b..2da06a6cf 100755 --- a/jquery.mousewheel.js +++ b/jquery.mousewheel.js @@ -11,7 +11,7 @@ */ (function (factory) { - if (typeof define === 'function' && define.amd) { + if ( typeof define === 'function' && define.amd ) { // AMD. Register as an anonymous module. define(['jquery'], factory); } else { @@ -24,8 +24,8 @@ var toBind = 'onwheel' in document || document.documentMode >= 9 ? ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll']; var lowestDelta, lowestDeltaXY; - if ($.event.fixHooks) { - for ( var i=toFix.length; i; ) { + if ( $.event.fixHooks ) { + for ( var i = toFix.length; i; ) { $.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks; } } @@ -33,7 +33,7 @@ $.event.special.mousewheel = { setup: function() { if ( this.addEventListener ) { - for ( var i=toBind.length; i; ) { + for ( var i = toBind.length; i; ) { this.addEventListener( toBind[--i], handler, false ); } } else { @@ -43,7 +43,7 @@ teardown: function() { if ( this.removeEventListener ) { - for ( var i=toBind.length; i; ) { + for ( var i = toBind.length; i; ) { this.removeEventListener( toBind[--i], handler, false ); } } else { @@ -64,13 +64,20 @@ function handler(event) { - var orgEvent = event || window.event, args = [].slice.call( arguments, 1 ), delta = 0, deltaX = 0, deltaY = 0, absDelta = 0, absDeltaXY = 0, fn; + var orgEvent = event || window.event, + args = [].slice.call(arguments, 1), + delta = 0, + deltaX = 0, + deltaY = 0, + absDelta = 0, + absDeltaXY = 0, + fn; event = $.event.fix(orgEvent); event.type = "mousewheel"; // Old school scrollwheel delta - if ( orgEvent.wheelDelta ) { delta = orgEvent.wheelDelta; } - if ( orgEvent.detail ) { delta = orgEvent.detail * -1; } + if ( orgEvent.wheelDelta ) { delta = orgEvent.wheelDelta; } + if ( orgEvent.detail ) { delta = orgEvent.detail * -1; } // New school wheel delta (wheel event) if ( orgEvent.deltaY ) { @@ -83,20 +90,20 @@ } // Webkit - if ( orgEvent.wheelDeltaY !== undefined ) { deltaY = orgEvent.wheelDeltaY; } + if ( orgEvent.wheelDeltaY !== undefined ) { deltaY = orgEvent.wheelDeltaY; } if ( orgEvent.wheelDeltaX !== undefined ) { deltaX = orgEvent.wheelDeltaX * -1; } // Look for lowest delta to normalize the delta values absDelta = Math.abs(delta); if ( !lowestDelta || absDelta < lowestDelta ) { lowestDelta = absDelta; } - absDeltaXY = Math.max( Math.abs(deltaY), Math.abs(deltaX) ); + absDeltaXY = Math.max(Math.abs(deltaY), Math.abs(deltaX)); if ( !lowestDeltaXY || absDeltaXY < lowestDeltaXY ) { lowestDeltaXY = absDeltaXY; } // Get a whole value for the deltas fn = delta > 0 ? 'floor' : 'ceil'; - delta = Math[fn](delta/lowestDelta); - deltaX = Math[fn](deltaX/lowestDeltaXY); - deltaY = Math[fn](deltaY/lowestDeltaXY); + delta = Math[fn](delta / lowestDelta); + deltaX = Math[fn](deltaX / lowestDeltaXY); + deltaY = Math[fn](deltaY / lowestDeltaXY); // Add event and delta to the front of the arguments args.unshift(event, delta, deltaX, deltaY); diff --git a/package.json b/package.json new file mode 100644 index 000000000..7943b1224 --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ + "scripts": { + "check": "jshint .", + "lint": "jshint ." + } +} \ No newline at end of file diff --git a/test/index.html b/test/index.html index 33191f53c..a7992c1fd 100644 --- a/test/index.html +++ b/test/index.html @@ -1,6 +1,7 @@ - - + +
+