Make sure that .width()/.height() don't return NaN also standardize on returning...
authorjeresig <jeresig@gmail.com>
Fri, 22 Oct 2010 06:39:06 +0000 (02:39 -0400)
committerjeresig <jeresig@gmail.com>
Fri, 22 Oct 2010 06:39:06 +0000 (02:39 -0400)
src/css.js
src/dimensions.js
test/unit/css.js

index 88c4ffa..30cecf3 100644 (file)
@@ -169,15 +169,11 @@ jQuery.each(["height", "width"], function( i, name ) {
                                        });
                                }
 
-                               if ( val < 0 ) {
-                                       return elem.style[ name ] || "0px";
-                               }
-
-                               if ( val === 0 ) {
+                               if ( val <= 0 ) {
                                        val = curCSS( elem, name, name );
 
                                        if ( val != null ) {
-                                               return val;
+                                               return val === "auto" ? "" : val;
                                        }
                                }
 
index 5aafbf4..f5212e1 100644 (file)
@@ -33,27 +33,29 @@ jQuery.each([ "Height", "Width" ], function( i, name ) {
                        });
                }
 
-               return jQuery.isWindow( elem ) ?
+               if ( jQuery.isWindow( elem ) ) {
                        // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
-                       elem.document.compatMode === "CSS1Compat" && elem.document.documentElement[ "client" + name ] ||
-                       elem.document.body[ "client" + name ] :
-
-                       // Get document width or height
-                       (elem.nodeType === 9) ? // is it a document
-                               // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
-                               Math.max(
-                                       elem.documentElement["client" + name],
-                                       elem.body["scroll" + name], elem.documentElement["scroll" + name],
-                                       elem.body["offset" + name], elem.documentElement["offset" + name]
-                               ) :
-
-                               // Get or set width or height on the element
-                               size === undefined ?
-                                       // Get width or height on the element
-                                       parseFloat( jQuery.css( elem, type ) ) :
-
-                                       // Set the width or height on the element (default to pixels if value is unitless)
-                                       this.css( type, typeof size === "string" ? size : size + "px" );
+                       return elem.document.compatMode === "CSS1Compat" && elem.document.documentElement[ "client" + name ] ||
+                               elem.document.body[ "client" + name ];
+
+               // Get document width or height
+               } else if ( elem.nodeType === 9 ) {
+                       // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
+                       return Math.max(
+                               elem.documentElement["client" + name],
+                               elem.body["scroll" + name], elem.documentElement["scroll" + name],
+                               elem.body["offset" + name], elem.documentElement["offset" + name]
+                       );
+
+               // Get or set width or height on the element
+               } else if ( size === undefined ) {
+                       var orig = jQuery.css( elem, type ), ret = parseFloat( orig );
+                       return jQuery.isNaN( ret ) ? orig : ret;
+
+               // Set the width or height on the element (default to pixels if value is unitless)
+               } else {
+                       return this.css( type, typeof size === "string" ? size : size + "px" );
+               }
        };
 
 });
index 2c2e9ed..9c262af 100644 (file)
@@ -13,8 +13,8 @@ test("css(String|Hash)", function() {
 
        var div = jQuery( "<div>" );
 
-       equals( div.css("width") || "auto", "auto", "Width on disconnected node." );
-       equals( div.css("height") || "auto", "auto", "Height on disconnected node." );
+       equals( div.css("width"), "", "Width on disconnected node." );
+       equals( div.css("height"), "", "Height on disconnected node." );
 
        div.css({ width: 4, height: 4 });