diff options
author | Ariel Flesler <aflesler@gmail.com> | 2009-09-09 21:14:28 +0000 |
---|---|---|
committer | Ariel Flesler <aflesler@gmail.com> | 2009-09-09 21:14:28 +0000 |
commit | d1285504fb636a077ae5b1e53e35959cc7faebc7 (patch) | |
tree | 15271c5670399017b72ef45198015fb1ee3c9849 /src/css.js | |
parent | aadc268abf555f0f1cc7c5bc05d0dc73b35cb705 (diff) | |
download | jquery-d1285504fb636a077ae5b1e53e35959cc7faebc7.tar.gz jquery-d1285504fb636a077ae5b1e53e35959cc7faebc7.zip |
jquery core: Closes #5189. Added a generic function to handle getting/setting key-value/setting a hash.
Diffstat (limited to 'src/css.js')
-rw-r--r-- | src/css.js | 50 |
1 files changed, 8 insertions, 42 deletions
diff --git a/src/css.js b/src/css.js index 5dd8dd062..f47bc8e2b 100644 --- a/src/css.js +++ b/src/css.js @@ -17,51 +17,17 @@ var rexclude = /z-?index|font-?weight|opacity|zoom|line-?height/i, }; jQuery.fn.css = function( name, value ) { - var options = name, isFunction = jQuery.isFunction( value ); - - if ( typeof name === "string" ) { - // Are we setting the style? - if ( value === undefined ) { - return this.length ? - jQuery.css( this[0], name ) : - null; - - // Convert name, value params to options hash format - } else { - options = {}; - options[ name ] = value; + return access( this, name, value, true, function( elem, name, value ) { + if (value === undefined) { + return jQuery.css( elem, name ); } - } - - var isFunction = {}; - - // For each value, determine whether it's a Function so we don't - // need to determine it again for each element - for ( var prop in options ) { - isFunction[prop] = jQuery.isFunction( options[prop] ); - } - - // For each element... - for ( var i = 0, l = this.length; i < l; i++ ) { - var elem = this[i]; - - // Set all the styles - for ( var prop in options ) { - value = options[prop]; - - if ( isFunction[prop] ) { - value = value.call( elem, i ); - } - - if ( typeof value === "number" && !rexclude.test(prop) ) { - value = value + "px"; - } - - jQuery.style( elem, prop, value ); + + if ( typeof value === "number" && !rexclude.test(name) ) { + value += "px"; } - } - return this; + jQuery.style( elem, name, value ); + }); }; jQuery.extend({ |