Skip to content

Commit

Permalink
Remove the relatedTarget adjustment for mouseenter/leave events, it's…
Browse files Browse the repository at this point in the history
… an ambiguous case anyway and it is expensive to do.
  • Loading branch information
dmethvin authored and timmywil committed Sep 19, 2011
1 parent 2886249 commit 38601e0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
10 changes: 3 additions & 7 deletions src/event.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -699,8 +699,7 @@ jQuery.Event.prototype = {
isImmediatePropagationStopped: returnFalse isImmediatePropagationStopped: returnFalse
}; };


// Create mouseenter and mouseleave events; IE has its own native ones but // Create mouseenter/leave events using mouseover/out and event-time checks
// we need to support event delegation as well so we don't use them.
jQuery.each({ jQuery.each({
mouseenter: "mouseover", mouseenter: "mouseover",
mouseleave: "mouseout" mouseleave: "mouseout"
Expand All @@ -716,12 +715,9 @@ jQuery.each({
selector = handleObj.selector, selector = handleObj.selector,
oldType, ret; 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 // 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 )) ) { if ( !related || handleObj.origType === event.type || (related !== target && !jQuery.contains( target, related )) ) {
oldType = event.type; oldType = event.type;
event.type = handleObj.origType; event.type = handleObj.origType;
Expand Down
24 changes: 19 additions & 5 deletions test/hovertest.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ <h2>Hover (mouse{over,out,enter,leave}) Tests</h2>
Mouse over here should NOT trigger the counter. Mouse over here should NOT trigger the counter.
</div> </div>
</div> </div>

<div id="liveenterbox" class="hover-box">
<div id="livebox" class="hover-box">
<div class="hover-status"> <div class="hover-status">
<button>Activate</button> <button>Activate</button>
Live enter/leave: <span class="ins">0</span> / <span class="outs">0</span> Live enter/leave: <span class="ins">0</span> / <span class="outs">0</span>
Expand All @@ -54,7 +53,6 @@ <h2>Hover (mouse{over,out,enter,leave}) Tests</h2>
Mouse over here should NOT trigger the counter. Mouse over here should NOT trigger the counter.
</div> </div>
</div> </div>

<div id="delegateenterbox" class="hover-box"> <div id="delegateenterbox" class="hover-box">
<div class="hover-status"> <div class="hover-status">
<button>Activate</button> <button>Activate</button>
Expand All @@ -74,6 +72,15 @@ <h2>Hover (mouse{over,out,enter,leave}) Tests</h2>
Mouse over here SHOULD trigger the counter. Mouse over here SHOULD trigger the counter.
</div> </div>
</div> </div>
<div id="liveoverbox" class="hover-box">
<div class="hover-status">
<button>Activate</button>
Live over/out: <span class="ins">0</span> / <span class="outs">0</span>
</div>
<div class="hover-inside">
Mouse over here SHOULD trigger the counter.
</div>
</div>
<div id="delegateoverbox" class="hover-box"> <div id="delegateoverbox" class="hover-box">
<div class="hover-status"> <div class="hover-status">
<button>Activate</button> <button>Activate</button>
Expand Down Expand Up @@ -115,8 +122,8 @@ <h2>Hover (mouse{over,out,enter,leave}) Tests</h2>
.delegate("#delegateenterbox", "mouseleave", countOuts ); .delegate("#delegateenterbox", "mouseleave", countOuts );
$(this).remove(); $(this).remove();
}); });
$("#livebox button").click(function(){ $("#liveenterbox button").click(function(){
$("#livebox") $("#liveenterbox")
.data({ ins: 0, outs: 0 }) .data({ ins: 0, outs: 0 })
.live("mouseenter", countIns ) .live("mouseenter", countIns )
.live("mouseleave", countOuts ); .live("mouseleave", countOuts );
Expand All @@ -130,6 +137,13 @@ <h2>Hover (mouse{over,out,enter,leave}) Tests</h2>
.bind("mouseout", countOuts ); .bind("mouseout", countOuts );
$(this).remove(); $(this).remove();
}); });
$("#liveoverbox button").click(function(){
$("#liveoverbox")
.data({ ins: 0, outs: 0 })
.live("mouseover", countIns )
.live("mouseout", countOuts );
$(this).remove();
});
$("#delegateoverbox button").click(function(){ $("#delegateoverbox button").click(function(){
$(document) $(document)
.find("#delegateoverbox").data({ ins: 0, outs: 0 }).end() .find("#delegateoverbox").data({ ins: 0, outs: 0 }).end()
Expand Down

0 comments on commit 38601e0

Please sign in to comment.