+ toggleClass: function( classNames, state ) {
+ var type = typeof classNames;
+
+ if ( jQuery.isFunction( classNames ) ) {
+ return this.each(function(i) {
+ var self = jQuery(this);
+ self.toggleClass( classNames.call(this, i, self.attr("class")), state );
+ });
+ }
+
+ return this.each(function(){
+ if ( type === "string" ) {
+ // toggle individual class names
+ var isBool = typeof state === "boolean", className, i = 0,
+ classNames = classNames.split( rspace );
+
+ while ( (className = classNames[ i++ ]) ) {
+ // check each className given, space seperated list
+ state = isBool ? state : !jQuery(this).hasClass( className );
+ jQuery(this)[ state ? "addClass" : "removeClass" ]( className );
+ }
+
+ } else if ( type === "undefined" || type === "boolean" ) {
+ if ( this.className ) {
+ // store className if set
+ jQuery.data( this, "__className__", this.className );
+ }
+
+ // toggle whole className
+ this.className = this.className || classNames === false ? "" : jQuery.data( this, "__className__" ) || "";
+ }
+ });
+ },
+