X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fcss.js;h=1fbee3f4719639146de6b6b7290f547902ec8943;hb=e57b73a0ac6f8fd0cdbbe7d43f1c7e198f475337;hp=88c4ffa05a8933ce971f381d33da4f8113ddff5f;hpb=7e02cee5ff8b5e9117366d7b43af7b5794f0f258;p=jquery.git diff --git a/src/css.js b/src/css.js index 88c4ffa..1fbee3f 100644 --- a/src/css.js +++ b/src/css.js @@ -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,20 +169,21 @@ 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 === "0px" && currentStyle ) { + val = currentStyle( elem, name, name ); + } + if ( val != null ) { - return val; + return val === "" ? "auto" : val; } } if ( val < 0 || val == null ) { - return elem.style[ name ]; + val = elem.style[ name ]; + return val === "" ? "auto" : val; } return typeof val === "string" ? val : val + "px"; @@ -234,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(); @@ -253,9 +254,10 @@ if ( getComputedStyle ) { 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 @@ -278,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;