Skip to content

Commit bc77d74

Browse files
committed
This is just an initial proposal for #5804, #5801 and 5852.
I've tested this cases but not had time yet to create an unit test case. This would make live() able to .live('click otherevent',fn), .live('hover',fn) and also proxys focus and blur events trough focusin and focusout. The problem is that bug #5821 still open, so adding 'hover' would incrase #5821 priority. I'll look into a testcase later. Also I'm not sure if I can handle #5821 to provide an stable patch.
1 parent 6438ab0 commit bc77d74

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

src/event.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -838,23 +838,39 @@ jQuery.fn.extend({
838838

839839
hover: function( fnOver, fnOut ) {
840840
return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
841-
},
841+
}
842+
});
843+
844+
jQuery.each(["live", "die"], function( i, name ) {
845+
jQuery.fn[ name ] = function( types, data, fn ) {
842846

843-
live: function( type, data, fn ) {
844847
if ( jQuery.isFunction( data ) ) {
845848
fn = data;
846849
data = undefined;
847850
}
848851

849-
jQuery( this.context ).bind( liveConvert( type, this.selector ), {
850-
data: data, selector: this.selector, live: type
851-
}, fn );
852-
853-
return this;
854-
},
852+
types = types.split( /\s+/ );
853+
var type, i=0;
854+
while ( (type = types[ i++ ]) ) {
855+
856+
type = type == 'focus' ? 'focusin' : // focus --> focusin
857+
type == 'blur' ? 'focusout' : // blur --> focusout
858+
type == 'hover' ? types.push('mouseleave') && 'mouseenter' : // hover support
859+
type;
860+
861+
if(name == 'live') {
862+
// bind live handler
863+
jQuery( this.context ).bind( liveConvert( type, this.selector ), {
864+
data: data, selector: this.selector, live: type
865+
}, fn );
855866

856-
die: function( type, fn ) {
857-
jQuery( this.context ).unbind( liveConvert( type, this.selector ), fn ? { guid: fn.guid + this.selector + type } : null );
867+
} else {
868+
// unbind live handler
869+
jQuery( this.context ).unbind( liveConvert( type, this.selector ), fn ? { guid: fn.guid + this.selector + type } : null );
870+
}
871+
872+
}
873+
858874
return this;
859875
}
860876
});

0 commit comments

Comments
 (0)