Skip to content
Browse files

fixed passing the opts argument out of the "key" method.

  • Loading branch information...
1 parent 06ec7f3 commit 8de56aa13feb165d68eb98b88456aa9056e726d2 Michael Helgeson committed Feb 13, 2011
Showing with 79 additions and 75 deletions.
  1. +49 −51 event.wheel/jquery.event.wheel.js
  2. +30 −24 fire/jquery.fire.js
View
100 event.wheel/jquery.event.wheel.js
@@ -1,52 +1,50 @@
-/*!
- * jquery.event.wheel - v 1.0.0 - http://jquery-ux.com/
- * Copyright (c) 2010 Michael Helgeson, Three Dub Media
- * Open Source MIT License - http://jquery-ux.com/license
- */
-// Created: 2008-07-01
-// Updated: 2010-01-08
-// REQUIRES: jquery 1.3+
-
-;(function( $ ){ // secure $ jQuery alias
-
-// jquery method
-$.fn.wheel = function( fn ){
- return this[ fn ? "bind" : "trigger" ]( "wheel", fn );
- };
-
-// special event config
-$.event.special.wheel = {
- setup: function(){
- $.event.add( this, wheelEvents, wheelHandler, {} );
- },
- teardown: function(){
- $.event.remove( this, wheelEvents, wheelHandler );
- }
- };
-
-// events to bind ( browser sniffed... )
-var wheelEvents = "DOMMouseScroll mousewheel" // IE, opera, safari, firefox
- +( $.browser.mozilla && $.browser.version < "1.9" ? " mousemove" : "" ); // firefox 2
-
-// shared event handler
-function wheelHandler( event ){
- switch ( event.type ){
- case "mousewheel": // IE, opera, safari
- event.delta = event.wheelDelta/120;
- if ( window.opera ) event.delta *= -1;
- break;
- case "DOMMouseScroll": // firefox
- $.extend( event, event.data ); // fix event properties in FF2
- event.delta = -event.detail/3;
- break;
- case "mousemove": // FF2 has incorrect event positions
- return $.extend( event.data, { // store the correct properties
- clientX: event.clientX, pageX: event.pageX,
- clientY: event.clientY, pageY: event.pageY
- });
- }
- event.type = "wheel"; // hijack the event
- return $.event.handle.call( this, event, event.delta );
- };
-
+/*!
+ * jquery.event.wheel - v 1.0.0 - http://jquery-ux.com/
+ * Copyright (c) 2010 Michael Helgeson, Three Dub Media
+ * Open Source MIT License - http://jquery-ux.com/license
+ */
+// Created: 2008-07-01
+// Updated: 2010-01-08
+// REQUIRES: jquery 1.3+
+
+;(function( $ ){ // secure $ jQuery alias
+
+// jquery method
+$.fn.wheel = function( fn ){
+ return this[ fn ? "bind" : "trigger" ]( "wheel", fn );
+};
+
+// special event config
+var wheel = $.event.special.wheel = {
+ events: "DOMMouseScroll mousewheel" // IE, opera, safari, firefox
+ +( $.browser.mozilla && $.browser.version < "1.9" ? " mousemove" : "" ), // firefox 2
+ setup: function(){
+ $.event.add( this, wheel.events, wheel.handler, {} );
+ },
+ teardown: function(){
+ $.event.remove( this, wheel.events, wheel.handler );
+ },
+ handler: function( event ){
+ switch ( event.type ){
+ case "mousewheel": // IE, opera, safari
+ event.delta = event.wheelDelta/120;
+ if ( window.opera ){
+ event.delta *= -1;
+ }
+ break;
+ case "DOMMouseScroll": // firefox
+ $.extend( event, event.data ); // fix event properties in FF2
+ event.delta = -event.detail/3;
+ break;
+ case "mousemove": // FF2 has incorrect event positions
+ return $.extend( event.data, { // store the correct properties
+ clientX: event.clientX, pageX: event.pageX,
+ clientY: event.clientY, pageY: event.pageY
+ });
+ }
+ event.type = "wheel"; // hijack the event
+ return $.event.handle.call( this, event, event.delta );
+ }
+};
+
})( jQuery ); // confine scope
View
54 fire/jquery.fire.js
@@ -1,8 +1,22 @@
-;(function($){
+;(function( $, window ){
+
+/*
+ http://www.w3.org/TR/DOM-Level-3-Events/#event-type-wheel
+*/
// jQuery method
$.fn.fire = function( type, opts ){
+ // translate pageX to clientX
+ if ( opts.pageX && !opts.clientX )
+ opts.clientX = opts.pageX - $( window ).scrollLeft();
+ // translate pageY to clientY
+ if ( opts.pageY && !opts.clientY )
+ opts.clientY = opts.pageY - $( window ).scrollTop();
+ // iterate the jquery collection
return this.each(function(){
+ // clone options uniquely for each instance
+ opts = $.extend( {}, $.fire.defaults, opts );
+ // instanitate a new event
new $.fire( this, type, opts );
});
};
@@ -11,14 +25,7 @@ $.fn.fire = function( type, opts ){
$.fire = function( element, type, opts ){
this.element = element;
this.type = type;
- this.opts = $.extend( {}, $.fire.defaults, opts );
- // translate pageX to clientX
- if ( this.opts.pageX && !this.opts.clientX )
- this.opts.clientX = this.opts.pageX - $( window ).scrollLeft();
- // translate pageY to clientY
- if ( this.opts.pageY && !this.opts.clientY )
- this.opts.clientY = this.opts.pageY - $( window ).scrollTop();
- this.event = this.create( type, opts );
+ this.event = this.create( opts );
this.dispatch();
};
@@ -41,10 +48,10 @@ $.fire.defaults = {
// Methods
$.fire.prototype = {
- create: function(){
+ create: function( opts ){
switch ( this.type ){
case "mousemove":
- this.opts.cancelable = false;
+ opts.cancelable = false;
case "mousedown":
case "mouseup":
case "mouseover":
@@ -54,17 +61,17 @@ $.fire.prototype = {
case "touchstart":
case "touchmove":
case "touchend":
- return this.mouse();
+ return this.mouse( opts );
case "keyup":
case "keypress":
case "keydown":
- return this.key();
+ return this.key( opts );
default:
- return this.event();
+ return this.event( opts );
}
},
- event: function(){
- var event, opts = this.opts;
+ event: function( opts ){
+ var event;
if ( document.createEvent ){
event = document.createEvent("HTMLEvents");
event.initEvent(
@@ -93,8 +100,8 @@ $.fire.prototype = {
}
return event;
},
- mouse: function(){
- var event, opts = this.opts;
+ mouse: function( opts ){
+ var event;
if ( document.createEvent ){
event = document.createEvent("MouseEvents");
event.initMouseEvent(
@@ -121,8 +128,8 @@ $.fire.prototype = {
}
return event;
},
- key: function(){
- var event, opts = this.opts;
+ key: function( opts ){
+ var event;
if ( document.createEvent ) {
try {
event = document.createEvent("KeyEvents");
@@ -140,11 +147,11 @@ $.fire.prototype = {
);
}
catch ( err ){
- event = this.event();
+ event = this.event( opts );
}
}
else if ( document.createEventObject ){
- event = this.event();
+ event = this.event( opts );
}
if ( $.browser.msie || $.browser.opera ){
event.keyCode = opts.charCode > 0 ? opts.charCode : opts.keyCode;
@@ -160,5 +167,4 @@ $.fire.prototype = {
}
};
-})( jQuery );
-
+})( jQuery, window );

0 comments on commit 8de56aa

Please sign in to comment.
Something went wrong with that request. Please try again.