X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fevent%2Fevent.js;h=852b3135233eb017011376ef2060d0376eeeae84;hb=65a88fae8919e5da774dcc45c9b42220f875b697;hp=fd4385cf191b1bd4dbdb823f66078bd610e5c73c;hpb=30f708027f27e100cd73ac2e60d12dc50654381f;p=jquery.git diff --git a/src/event/event.js b/src/event/event.js index fd4385c..852b313 100644 --- a/src/event/event.js +++ b/src/event/event.js @@ -10,6 +10,8 @@ jQuery.fn.extend({ * is fired, when clicked again, the second is fired. All subsequent * clicks continue to rotate through the two functions. * + * Use unbind("click") to remove. + * * @example $("p").toggle(function(){ * $(this).addClass("selected"); * },function(){ @@ -22,18 +24,18 @@ jQuery.fn.extend({ * @param Function odd The function to execute on every odd click. * @cat Events */ - toggle: function(a,b) { - // If two functions are passed in, we're - // toggling on a click - return a && b && a.constructor == Function && b.constructor == Function ? this.click(function(e){ + toggle: function() { + // save reference to arguments for access in closure + var a = arguments; + return typeof a[0] == "function" && typeof a[1] == "function" ? this.click(function(e) { // Figure out which function to execute - this.last = this.last == a ? b : a; + this.lastToggle = this.lastToggle == 0 ? 1 : 0; // Make sure that clicks stop e.preventDefault(); // and execute the function - return this.last.apply( this, [e] ) || false; + return a[this.lastToggle].apply( this, [e] ) || false; }) : // Otherwise, execute the old toggle function