Make sure that live mouseenter/mouseleave work properly. Fixes #6077.

This commit is contained in:
jeresig 2010-02-11 16:50:26 -05:00
parent 021b809ace
commit 5d36fe3210

View file

@ -917,9 +917,16 @@ jQuery.fn.extend({
} }
}); });
var liveMap = {
focus: "focusin",
blur: "focusout",
mouseenter: "mouseover",
mouseleave: "mouseout"
};
jQuery.each(["live", "die"], function( i, name ) { jQuery.each(["live", "die"], function( i, name ) {
jQuery.fn[ name ] = function( types, data, fn, origSelector /* Internal Use Only */ ) { jQuery.fn[ name ] = function( types, data, fn, origSelector /* Internal Use Only */ ) {
var type, i = 0, match, namespaces, var type, i = 0, match, namespaces, preType,
selector = origSelector || this.selector, selector = origSelector || this.selector,
context = origSelector ? this : jQuery( this.context ); context = origSelector ? this : jQuery( this.context );
@ -939,18 +946,19 @@ jQuery.each(["live", "die"], function( i, name ) {
type = type.replace( rnamespaces, "" ); type = type.replace( rnamespaces, "" );
} }
type = type === "focus" ? "focusin" : // focus --> focusin if ( type === "hover" ) {
type === "blur" ? "focusout" : // blur --> focusout types.push( "mouseenter" + namespaces, "mouseleave" + namespaces );
type === "hover" ? types.push("mouseleave" + namespaces) && "mouseenter" : // hover support continue;
type; }
type += namespaces; preType = type;
type = (liveMap[ type ] || type) + namespaces;
if ( name === "live" ) { if ( name === "live" ) {
// bind live handler // bind live handler
context.each(function(){ context.each(function(){
jQuery.event.add( this, liveConvert( type, selector ), jQuery.event.add( this, liveConvert( type, selector ),
{ data: data, selector: selector, handler: fn, origType: type, origHandler: fn } ); { data: data, selector: selector, handler: fn, origType: type, origHandler: fn, preType: preType } );
}); });
} else { } else {
@ -999,7 +1007,7 @@ function liveHandler( event ) {
related = null; related = null;
// Those two events require additional checking // Those two events require additional checking
if ( handleObj.origType === "mouseenter" || handleObj.origType === "mouseleave" ) { if ( handleObj.preType === "mouseenter" || handleObj.preType === "mouseleave" ) {
related = jQuery( event.relatedTarget ).closest( handleObj.selector )[0]; related = jQuery( event.relatedTarget ).closest( handleObj.selector )[0];
} }