diff --git a/ChangeLog.markdown b/ChangeLog.markdown index 8dd106beb..af82a30b9 100644 --- a/ChangeLog.markdown +++ b/ChangeLog.markdown @@ -1,6 +1,5 @@ # Mouse Wheel ChangeLog - # 3.0.2 * Fixed delta being opposite value in latest Opera diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 000000000..74c597096 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,20 @@ +Copyright 2010, 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 +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 +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.markdown b/README.markdown index 7ec6d039b..cd849886a 100644 --- a/README.markdown +++ b/README.markdown @@ -2,10 +2,23 @@ A jQuery plugin that adds cross-browser mouse wheel support. -The latest stable release can be downloaded from the [project page](http://plugins.jquery.com/project/mousewheel) +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 an extra argument which is the normalized "delta" 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) { + console.log(delta); + }); + + // using the event helper + $('#my_elem').mousewheel(function(event, delta) { + console.log(delta); + }); + ## License -The mousewheel plugin is dual licensed *(just like jQuery)* under the [MIT](http://www.opensource.org/licenses/mit-license.php) and [GPL](http://www.opensource.org/licenses/gpl-license.php) licenses. +The expandable plugin is licensed under the MIT License (LICENSE.txt). Copyright (c) 2009 [Brandon Aaron](http://brandonaaron.net) \ No newline at end of file diff --git a/jquery.mousewheel.js b/jquery.mousewheel.js index b6b89ba60..9a9865731 100644 --- a/jquery.mousewheel.js +++ b/jquery.mousewheel.js @@ -1,10 +1,10 @@ -/*! Copyright (c) 2009 Brandon Aaron (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) 2010 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. * - * Version: 3.0.2 + * Version: 3.0.3-pre * * Requires: 1.2.2+ */ @@ -14,47 +14,47 @@ var types = ['DOMMouseScroll', 'mousewheel']; $.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; - } + 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); + } }); function handler(event) { - var args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true; - - event = $.event.fix(event || window.event); - event.type = "mousewheel"; - - if ( event.wheelDelta ) delta = event.wheelDelta/120; - if ( event.detail ) delta = -event.detail/3; - - // Add events and delta to the front of the arguments - args.unshift(event, delta); + var args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true; + + event = $.event.fix(event || window.event); + event.type = "mousewheel"; + + if ( event.wheelDelta ) delta = event.wheelDelta/120; + if ( event.detail ) delta = -event.detail/3; + + // Add event and delta to the front of the arguments + args.unshift(event, delta); - return $.event.handle.apply(this, args); + return $.event.handle.apply(this, args); } })(jQuery); \ No newline at end of file