X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fattributes.js;h=f3e1b4cb3fb187fdeac44b247822d91a5af9ac79;hb=bbf3334db107abf72cbb3247b68b7e40d9f2cdfe;hp=22275adc03a2aebdafa27f1c65f5db3ce0c5042e;hpb=d7d908b05a442745c1a90728805b74db0a7921cf;p=jquery.git diff --git a/src/attributes.js b/src/attributes.js index 22275ad..f3e1b4c 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -46,7 +46,7 @@ jQuery.fn.extend({ if ( elem ) { if( jQuery.nodeName( elem, 'option' ) ) return (elem.attributes.value || {}).specified ? elem.value : elem.text; - + // We need to handle select boxes special if ( jQuery.nodeName( elem, "select" ) ) { var index = elem.selectedIndex, @@ -75,7 +75,7 @@ jQuery.fn.extend({ } } - return values; + return values; } // Everything else, we just grab the value @@ -130,9 +130,24 @@ jQuery.each({ }, toggleClass: function( classNames, state ) { - if( typeof state !== "boolean" ) - state = !jQuery.className.has( this, classNames ); - jQuery.className[ state ? "add" : "remove" ]( this, classNames ); + var type = typeof classNames; + if ( type === "string" ) { + // toggle individual class names + var isBool = typeof state === "boolean", className, i = 0, + classNames = classNames.split( /\s+/ ); + while ( (className = classNames[ i++ ]) ) { + // check each className given, space seperated list + state = isBool ? state : !jQuery.className.has( this, className ); + jQuery.className[ state ? "add" : "remove" ]( this, 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__" ) || ""; + } } }, function(name, fn){ jQuery.fn[ name ] = function(){