aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJörn Zaefferer <joern.zaefferer@gmail.com>2006-12-24 01:16:20 +0000
committerJörn Zaefferer <joern.zaefferer@gmail.com>2006-12-24 01:16:20 +0000
commitdef8c734edd6ab2b8188070520ef2019502ffd98 (patch)
tree52783d31783924ebfc268c4706ffe2613a1dd71b /src
parenta960b2d3b50bd4077b646d020ef0ec3cd7328b88 (diff)
downloadjquery-def8c734edd6ab2b8188070520ef2019502ffd98.tar.gz
jquery-def8c734edd6ab2b8188070520ef2019502ffd98.zip
Fix for #689
Diffstat (limited to 'src')
-rw-r--r--src/event/event.js14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/event/event.js b/src/event/event.js
index fd4385cf1..852b31352 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