Added support for adding multiple classes simultaneously, fixed a bug with remove...
[jquery.git] / src / event / event.js
index 72ea29a..852b313 100644 (file)
@@ -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
@@ -315,6 +317,9 @@ new function(){
                 * Trigger the focus event of each matched element. This causes all of the functions
                 * that have been bound to thet focus event to be executed.
                 *
+                * Note: This does not execute the focus method of the underlying elements! If you need to
+                * focus an element via code, you have to use the DOM method, eg. $("#myinput")[0].focus();
+                *
                 * @example $("p").focus();
                 * @before <p onfocus="alert('Hello');">Hello</p>
                 * @result alert('Hello');
@@ -655,6 +660,9 @@ new function(){
                 * Trigger the blur event of each matched element. This causes all of the functions
                 * that have been bound to thet blur event to be executed.
                 *
+                * Note: This does not execute the blur method of the underlying elements! If you need to
+                * blur an element via code, you have to use the DOM method, eg. $("#myinput")[0].blur();
+                *
                 * @example $("p").blur();
                 * @before <p onblur="alert('Hello');">Hello</p>
                 * @result alert('Hello');
@@ -1527,7 +1535,7 @@ new function(){
                 */
 
        var e = ("blur,focus,load,resize,scroll,unload,click,dblclick," +
-               "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," + 
+               "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," + 
                "submit,keydown,keypress,keyup,error").split(",");
 
        // Go through all the event names, but make sure that