Fixed and improved jQuery's event system: The target property of the event object is now fixed (IE and Safari), bind() accepts now a third parameter "amount" to run the function only the specified number of times, oneclick etc. uses this new bind - it removes the handler when it is not necessary anymore, therefore providing better performance, see accordion for test/demo ( http://joern.jquery.com/accordion/accordion.html )

This commit is contained in:
Jörn Zaefferer 2006-10-26 12:41:25 +00:00
parent 5131224427
commit 897fbfe89c
2 changed files with 26 additions and 21 deletions

View file

@ -1583,8 +1583,8 @@ new function(){
var o = e[i];
// Handle event binding
jQuery.fn[o] = function(f){
return f ? this.bind(o, f) : this.trigger(o);
jQuery.fn[o] = function(f, amount){
return f ? this.bind(o, f, amount) : this.trigger(o);
};
// Handle event unbinding
@ -1592,20 +1592,8 @@ new function(){
// Finally, handle events that only fire once
jQuery.fn["one"+o] = function(f){
// Attach the event listener
return this.each(function(){
var count = 0;
// Add the event
jQuery.event.add( this, o, function(e){
// If this function has already been executed, stop
if ( count++ ) return true;
// And execute the bound function
return f.apply(this, [e]);
});
});
// use bind with amount param to bind only once
return this.bind(o, f, 1);
};
};