Limit the scope of the CSS 'auto' change to just height/width. Fixes #7293.
[jquery.git] / src / css.js
index d0e55db..1fbee3f 100644 (file)
@@ -12,8 +12,8 @@ var ralpha = /alpha\([^)]*\)/i,
        cssHeight = [ "Top", "Bottom" ],
        curCSS,
 
-       // cache check for defaultView.getComputedStyle
-       getComputedStyle = document.defaultView && document.defaultView.getComputedStyle,
+       getComputedStyle,
+       currentStyle,
 
        fcamelCase = function( all, letter ) {
                return letter.toUpperCase();
@@ -169,7 +169,24 @@ jQuery.each(["height", "width"], function( i, name ) {
                                        });
                                }
 
-                               return val + "px";
+                               if ( val <= 0 ) {
+                                       val = curCSS( elem, name, name );
+
+                                       if ( val === "0px" && currentStyle ) {
+                                               val = currentStyle( elem, name, name );
+                                       }
+
+                                       if ( val != null ) {
+                                               return val === "" ? "auto" : val;
+                                       }
+                               }
+
+                               if ( val < 0 || val == null ) {
+                                       val = elem.style[ name ];
+                                       return val === "" ? "auto" : val;
+                               }
+
+                               return typeof val === "string" ? val : val + "px";
                        }
                },
 
@@ -218,8 +235,8 @@ if ( !jQuery.support.opacity ) {
        };
 }
 
-if ( getComputedStyle ) {
-       curCSS = function( elem, newName, name ) {
+if ( document.defaultView && document.defaultView.getComputedStyle ) {
+       getComputedStyle = function( elem, newName, name ) {
                var ret, defaultView, computedStyle;
 
                name = name.replace( rupper, "-$1" ).toLowerCase();
@@ -230,13 +247,17 @@ if ( getComputedStyle ) {
 
                if ( (computedStyle = defaultView.getComputedStyle( elem, null )) ) {
                        ret = computedStyle.getPropertyValue( name );
+                       if ( ret === "" && !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) {
+                               ret = jQuery.style( elem, name );
+                       }
                }
 
                return ret;
        };
+}
 
-} else if ( document.documentElement.currentStyle ) {
-       curCSS = function( elem, name ) {
+if ( document.documentElement.currentStyle ) {
+       currentStyle = function( elem, name ) {
                var left, rsLeft, ret = elem.currentStyle && elem.currentStyle[ name ], style = elem.style;
 
                // From the awesome hack by Dean Edwards
@@ -259,10 +280,12 @@ if ( getComputedStyle ) {
                        elem.runtimeStyle.left = rsLeft;
                }
 
-               return ret;
+               return ret === "" ? "auto" : ret;
        };
 }
 
+curCSS = getComputedStyle || currentStyle;
+
 function getWH( elem, name, extra ) {
        var which = name === "width" ? cssWidth : cssHeight,
                val = name === "width" ? elem.offsetWidth : elem.offsetHeight;