]> source.dussan.org Git - jquery.git/commitdiff
Don't swap to measure dimensions unless the element is display:none. #807 Fixes ...
authorMike Sherov <mike.sherov@gmail.com>
Thu, 7 Jun 2012 15:08:31 +0000 (11:08 -0400)
committerRick Waldron <waldron.rick@gmail.com>
Thu, 7 Jun 2012 15:08:31 +0000 (11:08 -0400)
src/css.js
test/unit/dimensions.js

index 4496594dcf6ce02322761b7e9361fd3411c661cd..94f8d890386602c0693a44cd66f6c150a479d0ed 100644 (file)
@@ -480,7 +480,7 @@ jQuery.each([ "height", "width" ], function( i, name ) {
        jQuery.cssHooks[ name ] = {
                get: function( elem, computed, extra ) {
                        if ( computed ) {
-                               if ( elem.offsetWidth !== 0 ) {
+                               if ( elem.offsetWidth !== 0 || curCSS( elem, "display" ) !== "none" ) {
                                        return getWidthOrHeight( elem, name, extra );
                                } else {
                                        return jQuery.swap( elem, cssShow, function() {
index 53e37b95d540fce2081b7719b022aeba51db5f26..6fc346dce50b5367d0cbd32bf6f8f6805df0dfc5 100644 (file)
@@ -299,6 +299,16 @@ test("outerWidth(true) returning % instead of px in Webkit, see #10639", functio
        equal( el.outerWidth(true), 400, "outerWidth(true) and css('margin') returning % instead of px in Webkit, see #10639" );
 });
 
+test( "getting dimensions of zero width/height table elements shouldn't alter dimensions", function() {
+       expect( 1 );
+
+       var table = jQuery("<table><tbody><tr><td></td><td>a</td></tr><tr><td></td><td>a</td></tr></tbody></table>").appendTo("#qunit-fixture"),
+               elem = table.find("tr:eq(0) td:eq(0)");
+
+       table.find("td").css({ margin: 0, padding: 0 });
+       equal( elem.width(), elem.width(), "width() doesn't alter dimension values" );
+});
+
 test("box-sizing:border-box child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height()  see #10413", function() {
        expect(16);