From 38601e07dae4bc4304eb9842faec5396c9eab787 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Thu, 8 Sep 2011 09:03:16 -0400 Subject: [PATCH] Remove the relatedTarget adjustment for mouseenter/leave events, it's an ambiguous case anyway and it is expensive to do. --- src/event.js | 10 +++------- test/hovertest.html | 24 +++++++++++++++++++----- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/event.js b/src/event.js index c5c5ca66b..560c5cf8d 100644 --- a/src/event.js +++ b/src/event.js @@ -699,8 +699,7 @@ jQuery.Event.prototype = { isImmediatePropagationStopped: returnFalse }; -// Create mouseenter and mouseleave events; IE has its own native ones but -// we need to support event delegation as well so we don't use them. +// Create mouseenter/leave events using mouseover/out and event-time checks jQuery.each({ mouseenter: "mouseover", mouseleave: "mouseout" @@ -716,12 +715,9 @@ jQuery.each({ selector = handleObj.selector, oldType, ret; + // For a real mouseover/out, always call the handler; for + // mousenter/leave call the handler if related is outside the target. // NB: No relatedTarget if the mouse left/entered the browser window - if ( selector && related ) { - // Delegated event; find the real relatedTarget - related = jQuery( related ).closest( selector )[0]; - } - // For mouseover/out, contains isn't needed; handle() already determined it's the right target if ( !related || handleObj.origType === event.type || (related !== target && !jQuery.contains( target, related )) ) { oldType = event.type; event.type = handleObj.origType; diff --git a/test/hovertest.html b/test/hovertest.html index 4c101ec00..d6242091e 100644 --- a/test/hovertest.html +++ b/test/hovertest.html @@ -44,8 +44,7 @@ p { Mouse over here should NOT trigger the counter. - -
+
Live enter/leave: 0 / 0 @@ -54,7 +53,6 @@ p { Mouse over here should NOT trigger the counter.
-
@@ -74,6 +72,15 @@ p { Mouse over here SHOULD trigger the counter.
+
+
+ + Live over/out: 0 / 0 +
+
+ Mouse over here SHOULD trigger the counter. +
+
@@ -115,8 +122,8 @@ $(function(){ .delegate("#delegateenterbox", "mouseleave", countOuts ); $(this).remove(); }); - $("#livebox button").click(function(){ - $("#livebox") + $("#liveenterbox button").click(function(){ + $("#liveenterbox") .data({ ins: 0, outs: 0 }) .live("mouseenter", countIns ) .live("mouseleave", countOuts ); @@ -130,6 +137,13 @@ $(function(){ .bind("mouseout", countOuts ); $(this).remove(); }); + $("#liveoverbox button").click(function(){ + $("#liveoverbox") + .data({ ins: 0, outs: 0 }) + .live("mouseover", countIns ) + .live("mouseout", countOuts ); + $(this).remove(); + }); $("#delegateoverbox button").click(function(){ $(document) .find("#delegateoverbox").data({ ins: 0, outs: 0 }).end()