]> source.dussan.org Git - jquery.git/commitdiff
Make sure that the correct height/width of the elements is retreived. Fixes #7225.
authorjeresig <jeresig@gmail.com>
Fri, 22 Oct 2010 06:16:14 +0000 (02:16 -0400)
committerjeresig <jeresig@gmail.com>
Fri, 22 Oct 2010 06:16:14 +0000 (02:16 -0400)
src/css.js
test/unit/css.js

index f2165f904c05b8afbda90992846f16d3661cfe28..88c4ffa05a8933ce971f381d33da4f8113ddff5f 100644 (file)
@@ -169,11 +169,23 @@ jQuery.each(["height", "width"], function( i, name ) {
                                        });
                                }
 
-                               if ( val < 0 || val === 0 && !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) {
+                               if ( val < 0 ) {
                                        return elem.style[ name ] || "0px";
                                }
 
-                               return val + "px";
+                               if ( val === 0 ) {
+                                       val = curCSS( elem, name, name );
+
+                                       if ( val != null ) {
+                                               return val;
+                                       }
+                               }
+
+                               if ( val < 0 || val == null ) {
+                                       return elem.style[ name ];
+                               }
+
+                               return typeof val === "string" ? val : val + "px";
                        }
                },
 
index 8f24e2e347cb852fd8767cb3072ace1ba2fa3062..2c2e9ed212a1af631e254eaba902c2cdf5ee976a 100644 (file)
@@ -1,7 +1,7 @@
 module("css");
 
 test("css(String|Hash)", function() {
-       expect(42);
+       expect(41);
 
        equals( jQuery('#main').css("display"), 'block', 'Check for css property "display"');
 
@@ -13,21 +13,19 @@ test("css(String|Hash)", function() {
 
        var div = jQuery( "<div>" );
 
-       equals( div.css("width"), "0px", "Width on disconnected node." );
-       equals( div.css("height"), "0px", "Height on disconnected node." );
+       equals( div.css("width") || "auto", "auto", "Width on disconnected node." );
+       equals( div.css("height") || "auto", "auto", "Height on disconnected node." );
 
        div.css({ width: 4, height: 4 });
 
        equals( div.css("width"), "4px", "Width on disconnected node." );
        equals( div.css("height"), "4px", "Height on disconnected node." );
 
-       var div2 = jQuery( "<div style='display:none;'><input type='text'/><textarea/></div>").appendTo("body");
+       var div2 = jQuery( "<div style='display:none;'><input type='text' style='height:20px;'/><textarea style='height:20px;'/><div style='height:20px;'></div></div>").appendTo("body");
 
-       equals( div2.find("input").css("width"), "0px", "Width on hidden input." );
-       equals( div2.find("input").css("height"), "0px", "Height on hidden input." );
-
-       equals( div2.find("textarea").css("width"), "0px", "Width on hidden textarea." );
-       equals( div2.find("textarea").css("height"), "0px", "Height on hidden textarea." );
+       equals( div2.find("input").css("height"), "20px", "Height on hidden input." );
+       equals( div2.find("textarea").css("height"), "20px", "Height on hidden textarea." );
+       equals( div2.find("div").css("height"), "20px", "Height on hidden textarea." );
 
        div2.remove();