Skip to content

Commit 5d36fe3

Browse files
committed
Make sure that live mouseenter/mouseleave work properly. Fixes #6077.
1 parent 021b809 commit 5d36fe3

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/event.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -917,9 +917,16 @@ jQuery.fn.extend({
917917
}
918918
});
919919

920+
var liveMap = {
921+
focus: "focusin",
922+
blur: "focusout",
923+
mouseenter: "mouseover",
924+
mouseleave: "mouseout"
925+
};
926+
920927
jQuery.each(["live", "die"], function( i, name ) {
921928
jQuery.fn[ name ] = function( types, data, fn, origSelector /* Internal Use Only */ ) {
922-
var type, i = 0, match, namespaces,
929+
var type, i = 0, match, namespaces, preType,
923930
selector = origSelector || this.selector,
924931
context = origSelector ? this : jQuery( this.context );
925932

@@ -939,18 +946,19 @@ jQuery.each(["live", "die"], function( i, name ) {
939946
type = type.replace( rnamespaces, "" );
940947
}
941948

942-
type = type === "focus" ? "focusin" : // focus --> focusin
943-
type === "blur" ? "focusout" : // blur --> focusout
944-
type === "hover" ? types.push("mouseleave" + namespaces) && "mouseenter" : // hover support
945-
type;
949+
if ( type === "hover" ) {
950+
types.push( "mouseenter" + namespaces, "mouseleave" + namespaces );
951+
continue;
952+
}
946953

947-
type += namespaces;
954+
preType = type;
955+
type = (liveMap[ type ] || type) + namespaces;
948956

949957
if ( name === "live" ) {
950958
// bind live handler
951959
context.each(function(){
952960
jQuery.event.add( this, liveConvert( type, selector ),
953-
{ data: data, selector: selector, handler: fn, origType: type, origHandler: fn } );
961+
{ data: data, selector: selector, handler: fn, origType: type, origHandler: fn, preType: preType } );
954962
});
955963

956964
} else {
@@ -999,7 +1007,7 @@ function liveHandler( event ) {
9991007
related = null;
10001008

10011009
// Those two events require additional checking
1002-
if ( handleObj.origType === "mouseenter" || handleObj.origType === "mouseleave" ) {
1010+
if ( handleObj.preType === "mouseenter" || handleObj.preType === "mouseleave" ) {
10031011
related = jQuery( event.relatedTarget ).closest( handleObj.selector )[0];
10041012
}
10051013

0 commit comments

Comments
 (0)