Merge branch 'master' of git://github.com/jquery/jquery into fixedbuild
[jquery.git] / src / css.js
index a6e2bb6..2eeef6c 100644 (file)
@@ -12,6 +12,9 @@ var ralpha = /alpha\([^)]*\)/i,
        cssHeight = [ "Top", "Bottom" ],
        curCSS,
 
+       getComputedStyle,
+       currentStyle,
+
        fcamelCase = function( all, letter ) {
                return letter.toUpperCase();
        };
@@ -169,6 +172,10 @@ jQuery.each(["height", "width"], function( i, name ) {
                                if ( val <= 0 ) {
                                        val = curCSS( elem, name, name );
 
+                                       if ( val === "0px" && currentStyle ) {
+                                               val = currentStyle( elem, name, name );
+                                       }
+
                                        if ( val != null ) {
                                                // Should return "auto" instead of 0, use 0 for
                                                // temporary backwards-compat
@@ -233,8 +240,30 @@ if ( !jQuery.support.opacity ) {
        };
 }
 
+jQuery(function() {
+       // This hook cannot be added until DOM ready because the support test
+       // for it is not run until after DOM ready
+       if ( !jQuery.support.reliableMarginRight ) {
+               jQuery.cssHooks.marginRight = {
+                       get: function( elem, computed ) {
+                               // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
+                               // Work around by temporarily setting element display to inline-block
+                               var ret;
+                               jQuery.swap( elem, { "display": "inline-block" }, function() {
+                                       if ( computed ) {
+                                               ret = curCSS( elem, "margin-right", "marginRight" );
+                                       } else {
+                                               ret = elem.style.marginRight;
+                                       }
+                               });
+                               return ret;
+                       }
+               };
+       }
+});
+
 if ( document.defaultView && document.defaultView.getComputedStyle ) {
-       curCSS = function( elem, newName, name ) {
+       getComputedStyle = function( elem, newName, name ) {
                var ret, defaultView, computedStyle;
 
                name = name.replace( rupper, "-$1" ).toLowerCase();
@@ -252,10 +281,13 @@ if ( document.defaultView && document.defaultView.getComputedStyle ) {
 
                return ret;
        };
-} else if ( document.documentElement.currentStyle ) {
-       curCSS = function( elem, name ) {
-               var left, rsLeft,
+}
+
+if ( document.documentElement.currentStyle ) {
+       currentStyle = function( elem, name ) {
+               var left,
                        ret = elem.currentStyle && elem.currentStyle[ name ],
+                       rsLeft = elem.runtimeStyle && elem.runtimeStyle[ name ],
                        style = elem.style;
 
                // From the awesome hack by Dean Edwards
@@ -266,22 +298,27 @@ if ( document.defaultView && document.defaultView.getComputedStyle ) {
                if ( !rnumpx.test( ret ) && rnum.test( ret ) ) {
                        // Remember the original values
                        left = style.left;
-                       rsLeft = elem.runtimeStyle.left;
 
                        // Put in the new values to get a computed value out
-                       elem.runtimeStyle.left = elem.currentStyle.left;
+                       if ( rsLeft ) {
+                               elem.runtimeStyle.left = elem.currentStyle.left;
+                       }
                        style.left = name === "fontSize" ? "1em" : (ret || 0);
                        ret = style.pixelLeft + "px";
 
                        // Revert the changed values
                        style.left = left;
-                       elem.runtimeStyle.left = rsLeft;
+                       if ( rsLeft ) {
+                               elem.runtimeStyle.left = rsLeft;
+                       }
                }
 
                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;