Created
March 12, 2010 04:26
-
-
Save furf/330030 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
/** | |
* Add live and die to the jQuery root | |
*/ | |
$.extend({ | |
live: function( selector, type, data, fn, thisObject ) { | |
if ( jQuery.isFunction( data ) ) { | |
if ( fn !== undefined ) { | |
thisObject = fn; | |
} | |
fn = data; | |
data = undefined; | |
} | |
// this.context || document handles instance and root usage | |
jQuery( this.context || document ).bind( liveConvert( type, selector ), { | |
data: data, selector: selector, live: type | |
}, fn, thisObject ); | |
return this; | |
}, | |
die: function( selector, type, fn ) { | |
// this.context || document handles instance and root usage | |
jQuery( this.context || document ).unbind( liveConvert( type, selector ), fn ? { guid: fn.guid + selector + type } : null ); | |
return this; | |
} | |
}); | |
/** | |
* Replace plugin live and die with aliased methods | |
*/ | |
$.fn.extend({ | |
live: function( type, data, fn, thisObject ) { | |
return jQuery.live.call( this, this.selector, type, data, fn, thisObject ); | |
}, | |
die: function( type, fn ) { | |
return jQuery.die.call( this, this.selector, type, fn ); | |
} | |
}); | |
// Borrowed from closure for patch | |
function liveConvert( type, selector ) { | |
return ["live", type, selector.replace(/\./g, "`").replace(/ /g, "|")].join("."); | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment