moving mousewheel plugin to git hub

This commit is contained in:
Brandon Aaron 2008-10-15 20:35:05 -05:00
commit 02de3f0bec
5 changed files with 3651 additions and 0 deletions

35
ChangeLog.markdown Normal file
View File

@ -0,0 +1,35 @@
# Mouse Wheel ChangeLog
# 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

10
README.markdown Normal file
View File

@ -0,0 +1,10 @@
# jQuery Mouse Wheel Plugin
A jQuery plugin that adds cross-browser mouse wheel support.
## License
The batch 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.
Copyright (c) 2007 [Brandon Aaron](http://brandonaaron.net)

82
jquery.mousewheel.js Normal file
View File

@ -0,0 +1,82 @@
/* Copyright (c) 2006 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.
* 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.1-pre
*
* 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);
return $.event.handle.apply(this, args);
}
};
$.fn.extend({
mousewheel: function(fn) {
return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
},
unmousewheel: function(fn) {
return this.unbind("mousewheel", fn);
}
});
})(jQuery);

193
test/index.html Normal file
View File

@ -0,0 +1,193 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Testing mousewheel plugin</title>
<link rel="Stylesheet" media="screen" href="../../../qunit/testsuite.css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="../jquery.mousewheel.js"></script>
<style>
#test1 {
background-color: #000;
width: 100px;
height: 100px;
color: #fff;
float: left;
}
#test2 {
background-color: #333;
width: 100px;
height: 100px;
color: #fff;
float: left;
}
#test3 {
background-color: #666;
width: 100px;
height: 100px;
color: #fff;
float: left;
}
#test4 {
background-color: #000;
width: 100px;
height: 100px;
color: #fff;
float: left;
}
#test5 {
background-color: #333;
padding: 5px;
width: 400px;
height: 400px;
color: #fff;
float: left;
}
#test6 {
background-color: #666;
padding: 5px;
width: 250px;
height: 250px;
color: #fff;
float: left;
}
#test7 {
background-color: #000;
padding: 5px;
width: 100px;
height: 100px;
color: #fff;
float: left;
}
#forceScroll {
clear: both;
height: 1000px;
}
</style>
<script type="text/javascript">
$(function() {
$('#userAgent').html(navigator.userAgent);
$('#test1')
.mousewheel(function(event, delta) {
if (delta > 0)
$('#logger').append('#test1: up ('+delta+')<br />');
else if (delta < 0)
$('#logger').append('#test1: down ('+delta+')<br />');
$('#logger').append('pageX: ' + event.pageX + ' pageY: ' + event.pageY );
});
$('#test2')
.mousewheel(function(event, delta) {
if (delta > 0)
$('#logger').append('#test2: up ('+delta+')<br />');
else if (delta < 0)
$('#logger').append('#test2: down ('+delta+')<br />');
return false; // prevent default
});
$('#test3')
.hover(function() { $('#logger').append('#test3: mouseover'); }, function() { $('#logger').append('#test3: mouseout'); })
.mousewheel(function(event, delta) {
$('#logger').append('#test3: I should not have been logged');
})
.unmousewheel();
var testRemoval = function(event, delta) {
$('#logger').append('#test4: I should not have been logged');
};
$('#test4')
.mousewheel(function(event, delta) {
if (delta > 0)
$('#logger').append('#test4: up ('+delta+')<br />');
else if (delta < 0)
$('#logger').append('#test4: down ('+delta+')<br />');
return false;
})
.mousewheel(testRemoval)
.mousewheel(function(event, delta) {
if (delta > 0)
$('#logger').append('#test4: up ('+delta+') from 2nd handler');
else if (delta < 0)
$('#logger').append('#test4: down ('+delta+') from 2nd handler');
return false;
})
.unmousewheel(testRemoval);
$('#test5')
.mousewheel(function(event, delta) {
if (delta > 0)
$('#logger').append('#test5: up ('+delta+')<br />');
else if (delta < 0)
$('#logger').append('#test5: down ('+delta+')<br />');
event.stopPropagation();
event.preventDefault();
});
$('#test6')
.mousewheel(function(event, delta) {
if (delta > 0)
$('#logger').append('#test6: up ('+delta+')<br />');
else if (delta < 0)
$('#logger').append('#test6: down ('+delta+')<br />');
event.stopPropagation();
event.preventDefault();
});
$('#test7')
.mousewheel(function(event, delta) {
if (delta > 0)
$('#logger').append('#test7: up ('+delta+')<br />');
else if (delta < 0)
$('#logger').append('#test7 down ('+delta+')<br />');
event.preventDefault();
});
});
</script>
</head>
<body>
<h1 id="banner">jQuery mousewheel.js - Test</h1>
<h2 id="userAgent"></h2>
<ul>
<li><strong>Test1</strong> is just using the plain on mousewheel() with a function passed in and does not prevent default. (Also logs the value of pageX and pageY event properties.)</li>
<li><strong>Test2</strong> should prevent the default action.</li>
<li><strong>Test3</strong> should only log a mouseover and mouseout event. Testing unmousewheel().</li>
<li><strong>Test4</strong> has two handlers.</li>
<li><strong>Test5</strong> is like Test2 but has children. The children should not scroll until mousing over them.</li>
<li><strong>Test6</strong> is like Test5 but should not scroll children or parents.</li>
<li><strong>Test7</strong> is like Test6 but has no children. It will propagate the event and scroll test 6 as well.</li>
</ul>
<div id="test1"><p>Test1</p></div>
<div id="test2"><p>Test2</p></div>
<div id="test3"><p>Test3</p></div>
<div id="test4"><p>Test4</p></div>
<div id="test5">
<p>Test5</p>
<div id="test6">
<p>Test6</p>
<div id="test7"><p>Test7</p></div>
</div>
</div>
<div id="logger"></div>
<div id="forceScroll"></div>
</body>
</html>

3331
test/jquery.js vendored Normal file

File diff suppressed because it is too large Load Diff