X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fcss.js;h=f675e13fc25a217faa7a9ddbe07e761b7cd360e5;hb=a33d01a7b09f2b3b06ba273b89b77fec8d20b144;hp=5d31757b0537db1c761f75249462b883b97b17f6;hpb=3776cbe314ac6f5081e998c3d5ac84d3fbc51872;p=jquery.git diff --git a/src/css.js b/src/css.js index 5d31757..f675e13 100644 --- a/src/css.js +++ b/src/css.js @@ -82,32 +82,13 @@ jQuery.extend({ css: function( elem, name, force, extra ) { if ( name === "width" || name === "height" ) { - var val, props = cssShow, which = name === "width" ? cssWidth : cssHeight; - - function getWH() { - val = name === "width" ? elem.offsetWidth : elem.offsetHeight; - - if ( extra === "border" ) { - return; - } - - jQuery.each( which, function() { - if ( !extra ) { - val -= parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0; - } - - if ( extra === "margin" ) { - val += parseFloat(jQuery.curCSS( elem, "margin" + this, true)) || 0; - } else { - val -= parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0; - } - }); - } - if ( elem.offsetWidth !== 0 ) { - getWH(); + val = getWH( elem, name, extra ); + } else { - jQuery.swap( elem, props, getWH ); + jQuery.swap( elem, cssShow, function() { + val = getWH( elem, name, extra ); + }); } return Math.max(0, Math.round(val)); @@ -205,12 +186,36 @@ jQuery.extend({ callback.call( elem ); // Revert the old values - for ( var name in options ) { + for ( name in options ) { elem.style[ name ] = old[ name ]; } } }); +function getWH( elem, name, extra ) { + var which = name === "width" ? cssWidth : cssHeight, + val = name === "width" ? elem.offsetWidth : elem.offsetHeight; + + if ( extra === "border" ) { + return val; + } + + jQuery.each( which, function() { + if ( !extra ) { + val -= parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0; + } + + if ( extra === "margin" ) { + val += parseFloat(jQuery.curCSS( elem, "margin" + this, true)) || 0; + + } else { + val -= parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0; + } + }); + + return val; +} + if ( jQuery.expr && jQuery.expr.filters ) { jQuery.expr.filters.hidden = function( elem ) { var width = elem.offsetWidth, height = elem.offsetHeight,