X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fevent.js;h=1ba0357d2252760091d6310bcade548de394a9d9;hb=ec7baf230d3c246dadf00c94115e6668425b9354;hp=da03813b97ccf3b5dda4bee6b5fa5b4d6a23ad8a;hpb=69e86d4f98a362d3834adf1bf4c32ed8e433f135;p=jquery.git diff --git a/src/event.js b/src/event.js index da03813..1ba0357 100644 --- a/src/event.js +++ b/src/event.js @@ -26,10 +26,7 @@ jQuery.event = { var fn = handler; // Create unique handler function, wrapped around original handler - handler = this.proxy( fn, function() { - // Pass arguments and context to original handler - return fn.apply(this, arguments); - }); + handler = this.proxy( fn ); // Store data in unique handler handler.data = data; @@ -128,10 +125,10 @@ jQuery.event = { // remove all handlers for the given type else - for ( handler in events[type] ) + for ( var handle in events[type] ) // Handle the removal of namespaced events - if ( namespace.test(events[type][handler].type) ) - delete events[type][handler]; + if ( namespace.test(events[type][handle].type) ) + delete events[type][handle]; if ( jQuery.event.specialAll[type] ) jQuery.event.specialAll[type].teardown.call(elem, namespaces); @@ -334,6 +331,7 @@ jQuery.event = { }, proxy: function( fn, proxy ){ + proxy = proxy || function(){ return fn.apply(this, arguments); }; // Set the guid of unique handler to the same of original handler, so it can be removed proxy.guid = fn.guid = fn.guid || proxy.guid || this.guid++; // So proxy can be declared as an argument @@ -362,7 +360,7 @@ jQuery.event = { remove++; }); - if ( remove <= 1 ) + if ( remove < 1 ) jQuery.event.remove( this, namespaces[0], liveHandler ); } } @@ -546,12 +544,16 @@ jQuery.fn.extend({ }, live: function( type, fn ){ - jQuery(document).bind( liveConvert(type, this.selector), this.selector, fn ); + var proxy = jQuery.event.proxy( fn ); + proxy.guid += this.selector + type; + + jQuery(document).bind( liveConvert(type, this.selector), this.selector, proxy ); + return this; }, die: function( type, fn ){ - jQuery(document).unbind( liveConvert(type, this.selector), fn ); + jQuery(document).unbind( liveConvert(type, this.selector), fn ? { guid: fn.guid + this.selector + type } : null ); return this; } });