Skip to content

Commit 4c53800

Browse files
committed
jQuery.live Implementation
Moves jQuery.fn.live/die implementations to jQuery.live/die. jQuery.fn.live/die implementations are appropriately refactored. Unit tests included.
1 parent eb496f7 commit 4c53800

File tree

2 files changed

+450
-5
lines changed

2 files changed

+450
-5
lines changed

src/event.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -839,24 +839,51 @@ jQuery.fn.extend({
839839
},
840840

841841
live: function( type, data, fn ) {
842+
// shift arguments if data argument was omitted
842843
if ( jQuery.isFunction( data ) ) {
843844
fn = data;
844845
data = undefined;
845846
}
846847

847-
jQuery( this.context ).bind( liveConvert( type, this.selector ), {
848-
data: data, selector: this.selector, live: type
849-
}, fn );
850-
848+
jQuery.live( this.selector, this.context, type, data, fn );
851849
return this;
852850
},
853851

854852
die: function( type, fn ) {
855-
jQuery( this.context ).unbind( liveConvert( type, this.selector ), fn ? { guid: fn.guid + this.selector + type } : null );
853+
jQuery.die( this.selector, this.context, type, fn );
856854
return this;
857855
}
858856
});
859857

858+
jQuery.extend({
859+
live: function( selector, context, type, data, fn ) {
860+
// shift arguments if context argument was omited
861+
if ( typeof type != "string" ) {
862+
fn = data;
863+
data = type;
864+
type = context;
865+
context = document;
866+
}
867+
// shift arguments if data argument was omitted
868+
if ( jQuery.isFunction( data ) ) {
869+
fn = data;
870+
data = undefined;
871+
}
872+
873+
jQuery ( context ).bind( liveConvert( type, selector ), { data: data, selector: selector, live: type }, fn );
874+
},
875+
876+
die: function( selector, context, type, fn ) {
877+
// shift arguments if context was omitted
878+
if ( typeof type != "string" ) {
879+
fn = type;
880+
type = context;
881+
context = document;
882+
}
883+
jQuery( context ).unbind( liveConvert( type, selector ), fn ? { guid: fn.guid + selector + type } : null );
884+
}
885+
});
886+
860887
function liveHandler( event ) {
861888
var stop = true, elems = [], selectors = [], args = arguments,
862889
related, match, fn, elem, j, i, data,

0 commit comments

Comments
 (0)