Fixed issues with oneEvent events.

This commit is contained in:
John Resig 2006-07-16 00:52:30 +00:00
parent 7d57c67749
commit f5f6cbc8c0

View file

@ -120,17 +120,18 @@ new function(){
// Finally, handle events that only fire once // Finally, handle events that only fire once
jQuery.fn["one"+o] = function(f){ jQuery.fn["one"+o] = function(f){
// Attach the event listener // Attach the event listener
return this.bind(o, function(e){ return this.each(function(){
// TODO: Remove the event listener, instead of this hack
// If this function has already been executed, stop var count = 0;
if ( this[o+f] !== null ) return;
// Otherwise, mark as having been executed // Add the event
this[o+f]++; jQuery.event.add( this, o, function(e){
// If this function has already been executed, stop
if ( count++ ) return;
// And execute the bound function // And execute the bound function
return f.apply(this, [e]); return f.apply(this, [e]);
});
}); });
}; };