]> source.dussan.org Git - jquery.git/commitdiff
Fixes #11938: Adding array getter method to jQuery.fn.css
authorMike Sherov <mike.sherov@gmail.com>
Tue, 11 Dec 2012 13:06:48 +0000 (08:06 -0500)
committerMike Sherov <mike.sherov@gmail.com>
Tue, 11 Dec 2012 18:58:14 +0000 (13:58 -0500)
src/core.js
src/css.js
test/unit/css.js

index d666567f253a6357578f9db931c50eaea84cb314..2e794fb2581b03a93c2a60eb1eb7a45fd56fec56 100644 (file)
@@ -798,7 +798,7 @@ jQuery.extend({
                        bulk = key == null;
 
                // Sets many values
-               if ( key && typeof key === "object" ) {
+               if ( jQuery.type( key ) === "object" ) {
                        chainable = true;
                        for ( i in key ) {
                                jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
index 37f4d03e013172d9e2e5457adbf4a067c3d13c04..18ca9c831dad37d85c8f7ab84a469d2505b6496b 100644 (file)
@@ -98,6 +98,21 @@ function showHide( elements, show ) {
 jQuery.fn.extend({
        css: function( name, value ) {
                return jQuery.access( this, function( elem, name, value ) {
+                       var styles, len,
+                               map = {},
+                               i = 0;
+
+                       if ( jQuery.isArray( name ) ) {
+                               styles = getStyles( elem );
+                               len = name.length;
+
+                               for ( ; i < len; i++ ) {
+                                       map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
+                               }
+
+                               return map;
+                       }
+
                        return value !== undefined ?
                                jQuery.style( elem, name, value ) :
                                jQuery.css( elem, name );
index c90011687fbe8a6b601ff61fe396d03f64430c4a..e27d5b615aff684610d9e8bfeaf4987cb64ea753 100644 (file)
@@ -257,6 +257,22 @@ test("css(String, Object)", function() {
        ok( success, "Setting RGBA values does not throw Error" );
 });
 
+test( "css(Array)", function() {
+       expect( 2 );
+
+       var expectedMany = {
+                       "overflow": "visible",
+                       "width": "16px"
+               },
+               expectedSingle = {
+                       "width": "16px"
+               },
+               elem = jQuery("<div></div>").appendTo("#qunit-fixture");
+
+       deepEqual( elem.css( expectedMany ).css([ "overflow", "width" ]), expectedMany, "Getting multiple element array" );
+       deepEqual( elem.css( expectedSingle ).css([ "width" ]), expectedSingle, "Getting single element array" );
+});
+
 if ( !jQuery.support.opacity ) {
        test("css(String, Object) for MSIE", function() {
                expect( 5 );