From ef6d8779de9d5959eafc0b9706b90a585aaf7a26 Mon Sep 17 00:00:00 2001 From: Mike Sherov Date: Tue, 11 Dec 2012 08:06:48 -0500 Subject: [PATCH] Fixes #11938: Adding array getter method to jQuery.fn.css --- src/core.js | 2 +- src/css.js | 15 +++++++++++++++ test/unit/css.js | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/core.js b/src/core.js index d666567f2..2e794fb25 100644 --- a/src/core.js +++ b/src/core.js @@ -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 ); diff --git a/src/css.js b/src/css.js index 37f4d03e0..18ca9c831 100644 --- a/src/css.js +++ b/src/css.js @@ -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 ); diff --git a/test/unit/css.js b/test/unit/css.js index c90011687..e27d5b615 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -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("
").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 ); -- 2.39.5