Skip to main content

Bug Tracker

Side navigation

Ticket #5259: patchEvent.txt
File patchEvent.txt, 1.7 KB (added by lrbabe, September 16, 2009 08:27PM UTC)
Index: event.js
===================================================================
--- event.js	(revision 6581)
+++ event.js	(working copy)
@@ -517,7 +517,13 @@
 		// handle event if we actually just moused on to a non sub-element
 		jQuery.event.handle.apply( this, arguments );
 	}
-};
+},
+	// In case of event delegation, all mouseout and mouseover events
+	// should be passed to the liveHandler 
+	delegate = function( event ) {
+		event.type = event.data;
+		jQuery.event.handle.apply( this, arguments );
+	};
 
 // Create mouseenter and mouseleave events
 jQuery.each({
@@ -525,11 +531,11 @@
 	mouseout: "mouseleave"
 }, function( orig, fix ) {
 	jQuery.event.special[ fix ] = {
-		setup: function(){
-			jQuery.event.add( this, orig, withinElement, fix );
+		setup: function(data){
+			jQuery.event.add( this, orig, data && data.selector? delegate : withinElement, fix );
 		},
-		teardown: function(){
-			jQuery.event.remove( this, orig, withinElement );
+		teardown: function(data){
+			jQuery.event.remove( this, orig, data && data.selector? delegate : withinElement );
 		}
 	};
 });
@@ -743,9 +749,16 @@
 
 	jQuery.each( jQuery.data( this, "events" ).live || [], function( i, fn ) {
 		if ( fn.live === event.type ) {
-			var elem = jQuery( event.target ).closest( fn.selector )[0];
+			var elem = jQuery( event.target ).closest( fn.selector )[0],
+				related;
 			if ( elem ) {
-				elems.push({ elem: elem, fn: fn });
+				// Those two events require additional checking
+				if(fn.live == "mouseenter" || fn.live == "mouseleave") {
+					related = jQuery( event.relatedTarget ).closest( fn.selector )[0];
+				}
+				if(!related || related != elem) {
+					elems.push({ elem: elem, fn: fn });
+				}
 			}
 		}
 	});

Download in other formats:

Original Format