From be7cdf06dc683d0c81320474649c666281e8358c Mon Sep 17 00:00:00 2001 From: Brandon Aaron Date: Fri, 22 Feb 2013 10:03:48 -0600 Subject: [PATCH 01/10] setup gh-pages --- ChangeLog.markdown | 76 ++++++++++ LICENSE.txt | 20 +++ README.markdown | 24 +++ jquery.mousewheel.js | 101 +++++++++++++ mousewheel.jquery.json | 27 ++++ test/index.html | 330 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 578 insertions(+) create mode 100644 ChangeLog.markdown create mode 100644 LICENSE.txt create mode 100644 README.markdown create mode 100755 jquery.mousewheel.js create mode 100644 mousewheel.jquery.json create mode 100644 test/index.html diff --git a/ChangeLog.markdown b/ChangeLog.markdown new file mode 100644 index 000000000..c7185d113 --- /dev/null +++ b/ChangeLog.markdown @@ -0,0 +1,76 @@ +# Mouse Wheel ChangeLog + +# 3.1.0 + +* Fix Firefox 17+ issues by using new wheel event +* Normalize delta values +* Adds horizontal support for IE 9+ by using new wheel event +* Support AMD loaders + + +# 3.0.6 + +* Fix issue with delta being 0 in Firefox + + +# 3.0.5 + +* jQuery 1.7 compatibility + + +# 3.0.4 + +* Fix IE issue + + +# 3.0.3 + +* Added deltaX and deltaY for horizontal scrolling support (Thanks to Seamus Leahy) + + +# 3.0.2 + +* Fixed delta being opposite value in latest Opera +* No longer fix pageX, pageY for older mozilla browsers +* Removed browser detection +* Cleaned up the code + + +# 3.0.1 + +* Bad release... creating a new release due to plugins.jquery.com issue :( + + +# 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 +* Using jQuery.data API for expandos + + +# 2.2 + +* Fixed pageX, pageY, clientX and clientY event properties for Mozilla based browsers + + +# 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 + +* Fixed an issue with the unload handler + + +# 2.0 + +* Major reduction in code size and complexity (internals have change a whole lot) + + +# 1.0 + +* Fixed Opera issue +* Fixed an issue with children elements that also have a mousewheel handler +* Added ability to handle multiple handlers diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 000000000..d3d21c42b --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,20 @@ +Copyright 2011, 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. diff --git a/README.markdown b/README.markdown new file mode 100644 index 000000000..453ed6701 --- /dev/null +++ b/README.markdown @@ -0,0 +1,24 @@ +# jQuery Mouse Wheel Plugin + +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. + +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); + }); + + // using the event helper + $('#my_elem').mousewheel(function(event, delta, deltaX, deltaY) { + console.log(delta, deltaX, deltaY); + }); + + +## License + +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 new file mode 100755 index 000000000..8c603041b --- /dev/null +++ b/jquery.mousewheel.js @@ -0,0 +1,101 @@ +/*! Copyright (c) 2013 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 + * + * Version: 3.1.0 + * + * Requires: 1.2.2+ + */ + +(function (factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['jquery'], factory); + } else { + // Browser globals + factory(jQuery); + } +}(function ($) { + + var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll']; + var toBind = 'onwheel' in document || document.documentMode >= 9 ? ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll']; + var lowestDelta, lowestDeltaXY; + + if ($.event.fixHooks) { + for ( var i=toFix.length; i; ) { + $.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks; + } + } + + $.event.special.mousewheel = { + setup: function() { + if ( this.addEventListener ) { + for ( var i=toBind.length; i; ) { + this.addEventListener( toBind[--i], handler, false ); + } + } else { + this.onmousewheel = handler; + } + }, + + teardown: function() { + if ( this.removeEventListener ) { + for ( var i=toBind.length; i; ) { + this.removeEventListener( toBind[--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); + } + }); + + + function handler(event) { + var orgEvent = event || window.event, args = [].slice.call( arguments, 1 ), delta = 0, deltaX = 0, deltaY = 0, absDelta = 0, absDeltaXY = 0; + event = $.event.fix(orgEvent); + event.type = "mousewheel"; + + // Old school scrollwheel delta + if ( orgEvent.wheelDelta ) { delta = orgEvent.wheelDelta; } + if ( orgEvent.detail ) { delta = orgEvent.detail * -1; } + + // New school wheel delta (wheel event) + if ( orgEvent.deltaY ) { + deltaY = orgEvent.deltaY * -1; + delta = deltaY; + } + if ( orgEvent.deltaX ) { + deltaX = orgEvent.deltaX; + delta = deltaX * -1; + } + + // Webkit + if ( orgEvent.wheelDeltaY !== undefined ) { deltaY = orgEvent.wheelDeltaY; } + if ( orgEvent.wheelDeltaX !== undefined ) { deltaX = orgEvent.wheelDeltaX * -1; } + + absDelta = Math.abs(delta); + if ( !lowestDelta || absDelta < lowestDelta ) { lowestDelta = absDelta; } + + absDeltaXY = Math.max( Math.abs(deltaY), Math.abs(deltaX) ); + if ( !lowestDeltaXY || absDeltaXY < lowestDeltaXY ) { lowestDeltaXY = absDeltaXY; } + + // Add event and delta to the front of the arguments + args.unshift(event, Math.floor(delta/lowestDelta), Math.floor(deltaX/lowestDeltaXY), Math.floor(deltaY/lowestDeltaXY)); + + return ($.event.dispatch || $.event.handle).apply(this, args); + } + +})); diff --git a/mousewheel.jquery.json b/mousewheel.jquery.json new file mode 100644 index 000000000..4b52f1d7b --- /dev/null +++ b/mousewheel.jquery.json @@ -0,0 +1,27 @@ +{ + "name": "mousewheel", + "title": "jQuery Mousewheel", + "description": "A jQuery plugin that adds cross-browser mouse wheel support.", + "keywords": [ + "mousewheel", + "mouse", + "event" + ], + "version": "3.1.0", + "author": { + "name": "Brandon Aaron", + "url": "http://brandonaaron.net" + }, + "licenses": [ + { + "type": "MIT", + "url": "https://raw.github.com/brandonaaron/jquery-mousewheel/master/LICENSE.txt" + } + ], + "bugs": "https://github.com/brandonaaron/jquery-mousewheel/issues", + "homepage": "https://github.com/brandonaaron/jquery-mousewheel", + "download": "https://github.com/brandonaaron/jquery-mousewheel/tags", + "dependencies": { + "jquery": ">=1.2.2" + } +} diff --git a/test/index.html b/test/index.html new file mode 100644 index 000000000..33191f53c --- /dev/null +++ b/test/index.html @@ -0,0 +1,330 @@ + + + + Testing mousewheel plugin + + + + + + + + +

jQuery mousewheel.js - Test

+

+ + + + +

Test1

+

Test2

+

Test3

+

Test4

+
+

Test5

+
+

Test6

+

Test7

+
+
+ +
+ +
+ + From 12f93fd3dd40dc83331492eeb7ad598234c27909 Mon Sep 17 00:00:00 2001 From: Brandon Aaron Date: Tue, 12 Mar 2013 09:33:37 -0500 Subject: [PATCH 02/10] update pages to latest version and point to root to test/index --- ChangeLog.markdown | 76 ------------------------------------------ LICENSE.txt | 8 ++--- README.markdown | 24 ------------- index.html | 1 + jquery.mousewheel.js | 42 +++++++++++++++-------- mousewheel.jquery.json | 27 --------------- test/index.html | 9 ++--- 7 files changed, 39 insertions(+), 148 deletions(-) delete mode 100644 ChangeLog.markdown delete mode 100644 README.markdown create mode 100644 index.html delete mode 100644 mousewheel.jquery.json diff --git a/ChangeLog.markdown b/ChangeLog.markdown deleted file mode 100644 index c7185d113..000000000 --- a/ChangeLog.markdown +++ /dev/null @@ -1,76 +0,0 @@ -# Mouse Wheel ChangeLog - -# 3.1.0 - -* Fix Firefox 17+ issues by using new wheel event -* Normalize delta values -* Adds horizontal support for IE 9+ by using new wheel event -* Support AMD loaders - - -# 3.0.6 - -* Fix issue with delta being 0 in Firefox - - -# 3.0.5 - -* jQuery 1.7 compatibility - - -# 3.0.4 - -* Fix IE issue - - -# 3.0.3 - -* Added deltaX and deltaY for horizontal scrolling support (Thanks to Seamus Leahy) - - -# 3.0.2 - -* Fixed delta being opposite value in latest Opera -* No longer fix pageX, pageY for older mozilla browsers -* Removed browser detection -* Cleaned up the code - - -# 3.0.1 - -* Bad release... creating a new release due to plugins.jquery.com issue :( - - -# 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 -* Using jQuery.data API for expandos - - -# 2.2 - -* Fixed pageX, pageY, clientX and clientY event properties for Mozilla based browsers - - -# 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 - -* Fixed an issue with the unload handler - - -# 2.0 - -* Major reduction in code size and complexity (internals have change a whole lot) - - -# 1.0 - -* Fixed Opera issue -* Fixed an issue with children elements that also have a mousewheel handler -* Added ability to handle multiple handlers 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 deleted file mode 100644 index 453ed6701..000000000 --- a/README.markdown +++ /dev/null @@ -1,24 +0,0 @@ -# jQuery Mouse Wheel Plugin - -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. - -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); - }); - - // using the event helper - $('#my_elem').mousewheel(function(event, delta, deltaX, deltaY) { - console.log(delta, deltaX, deltaY); - }); - - -## License - -This plugin is licensed under the MIT License (LICENSE.txt). - -Copyright (c) 2013 [Brandon Aaron](http://brandonaaron.net) diff --git a/index.html b/index.html new file mode 100644 index 000000000..e20a59c16 --- /dev/null +++ b/index.html @@ -0,0 +1 @@ + diff --git a/jquery.mousewheel.js b/jquery.mousewheel.js index 8c603041b..38355c6a1 100755 --- a/jquery.mousewheel.js +++ b/jquery.mousewheel.js @@ -5,15 +5,18 @@ * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix. * Thanks to: Seamus Leahy for adding deltaX and deltaY * - * Version: 3.1.0 + * Version: 3.1.2 * * Requires: 1.2.2+ */ (function (factory) { - if (typeof define === 'function' && define.amd) { + if ( typeof define === 'function' && define.amd ) { // AMD. Register as an anonymous module. define(['jquery'], factory); + } else if (typeof exports === 'object') { + // Node/CommonJS style for Browserify + module.exports = factory; } else { // Browser globals factory(jQuery); @@ -24,8 +27,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 +36,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 +46,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 +67,20 @@ function handler(event) { - var orgEvent = event || window.event, args = [].slice.call( arguments, 1 ), delta = 0, deltaX = 0, deltaY = 0, absDelta = 0, absDeltaXY = 0; + 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,17 +93,23 @@ } // 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); + // Add event and delta to the front of the arguments - args.unshift(event, Math.floor(delta/lowestDelta), Math.floor(deltaX/lowestDeltaXY), Math.floor(deltaY/lowestDeltaXY)); + args.unshift(event, delta, deltaX, deltaY); return ($.event.dispatch || $.event.handle).apply(this, args); } diff --git a/mousewheel.jquery.json b/mousewheel.jquery.json deleted file mode 100644 index 4b52f1d7b..000000000 --- a/mousewheel.jquery.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "name": "mousewheel", - "title": "jQuery Mousewheel", - "description": "A jQuery plugin that adds cross-browser mouse wheel support.", - "keywords": [ - "mousewheel", - "mouse", - "event" - ], - "version": "3.1.0", - "author": { - "name": "Brandon Aaron", - "url": "http://brandonaaron.net" - }, - "licenses": [ - { - "type": "MIT", - "url": "https://raw.github.com/brandonaaron/jquery-mousewheel/master/LICENSE.txt" - } - ], - "bugs": "https://github.com/brandonaaron/jquery-mousewheel/issues", - "homepage": "https://github.com/brandonaaron/jquery-mousewheel", - "download": "https://github.com/brandonaaron/jquery-mousewheel/tags", - "dependencies": { - "jquery": ">=1.2.2" - } -} 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 @@ - - + + + Testing mousewheel plugin - + - + + +

jQuery mousewheel.js Test with jQuery