Skip to main content

Bug Tracker

Side navigation

Ticket #2655: handle-fix.diff
File handle-fix.diff, 2.1 KB (added by flesler, April 05, 2008 05:28AM UTC)

Changes

Index: src/event.js
===================================================================
--- src/event.js	(revision 5202)
+++ src/event.js	(working copy)
@@ -240,34 +240,30 @@
 		var val;
 
 		// Empty object is for triggered events with no data
-		event = jQuery.event.fix( event || window.event || {} ); 
+		event = arguments[0] = jQuery.event.fix( event || window.event ); 
 
 		// Namespaced event handlers
-		var parts = event.type.split(".");
-		event.type = parts[0];
+		var ns = event.type.split(".");
+		event.type = ns[0];
+		ns = ns[1];//namespace
 
-		var handlers = jQuery.data(this, "events") && jQuery.data(this, "events")[event.type], args = Array.prototype.slice.call( arguments, 1 );
-		args.unshift( event );
+		var handlers = jQuery.data(this, "events") && jQuery.data(this, "events")[event.type];
 
 		for ( var j in handlers ) {
 			var handler = handlers[j];
 			// Pass in a reference to the handler function itself
 			// So that we can later remove it
-			args[0].handler = handler;
-			args[0].data = handler.data;
+			event.handler = handler;
+			event.data = handler.data;
 
 			// Filter the functions by class
-			if ( !parts[1] && !event.exclusive || handler.type == parts[1] ) {
-				var ret = handler.apply( this, args );
+			if ( !ns && !event.exclusive || handler.type == ns ) 
+				val = handler.apply( this, arguments ) !== false && val;
+		}
 
-				if ( val !== false )
-					val = ret;
-
-				if ( ret === false ) {
-					event.preventDefault();
-					event.stopPropagation();
-				}
-			}
+		if ( val === false ) {//check after the loop
+			event.preventDefault();
+			event.stopPropagation();
 		}
 
 		// Clean up added properties in IE to prevent memory leak
@@ -279,10 +275,13 @@
 	},
 
 	fix: function(event) {
+		if( event._fixed_ )//already fixed
+			return event;
+		
 		// store a copy of the original event object 
 		// and clone to set read-only properties
 		var originalEvent = event;
-		event = jQuery.extend({}, originalEvent);
+		event = jQuery.extend({ _fixed_:true }, originalEvent);
 		
 		// add preventDefault and stopPropagation since 
 		// they will not work on the clone

Download in other formats:

Original Format