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;
},
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
remove++;
});
- if ( remove <= 1 )
+ if ( remove < 1 )
jQuery.event.remove( this, namespaces[0], liveHandler );
}
}
},
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;
}
});
function liveHandler( event ){
var check = RegExp("(^|\\.)" + event.type + "(\\.|$)"),
- stop = true;
+ stop = true,
+ elems = [];
jQuery.each(jQuery.data(this, "events").live || [], function(i, fn){
- if ( !event.isImmediatePropagationStopped() && check.test(fn.type) ) {
+ if ( check.test(fn.type) ) {
var elem = jQuery(event.target).closest(fn.data)[0];
- if ( elem && fn.call(elem, event, fn.data) === false )
- stop = false;
+ if ( elem )
+ elems.push({ elem: elem, fn: fn });
}
});
+
+ jQuery.each(elems, function(){
+ if ( !event.isImmediatePropagationStopped() &&
+ this.fn.call(this.elem, event, this.fn.data) === false )
+ stop = false;
+ });
+
return stop;
}