diff options
author | Oleg <markelog@gmail.com> | 2012-09-29 00:56:49 +0400 |
---|---|---|
committer | Dave Methvin <dave.methvin@gmail.com> | 2012-10-28 23:32:54 -0400 |
commit | bea5ecbba72f22e8924186d9b81839122ec86aef (patch) | |
tree | d2a84f93922a58ec1a390c18a1349fe49fefd86b | |
parent | 5be4c10cf78c0ec6785217a8a4ea10eacaedeb1c (diff) | |
download | jquery-bea5ecbba72f22e8924186d9b81839122ec86aef.tar.gz jquery-bea5ecbba72f22e8924186d9b81839122ec86aef.zip |
Fix #10416. Don't trust computed styles on detached elements. Close gh-941.
-rw-r--r-- | src/css.js | 14 | ||||
-rw-r--r-- | test/unit/css.js | 20 |
2 files changed, 21 insertions, 13 deletions
diff --git a/src/css.js b/src/css.js index ad42a048a..6dd13efdf 100644 --- a/src/css.js +++ b/src/css.js @@ -44,12 +44,14 @@ function vendorPropName( style, name ) { } function isHidden( elem, el ) { + // isHidden might be called from jQuery#filter function; + // in that case, element will be second argument elem = el || elem; - return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem ); + return curCSS( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem ); } function showHide( elements, show ) { - var elem, display, + var elem, values = [], index = 0, length = elements.length; @@ -73,12 +75,8 @@ function showHide( elements, show ) { if ( elem.style.display === "" && isHidden( elem ) ) { values[ index ] = jQuery._data( elem, "olddisplay", css_defaultDisplay(elem.nodeName) ); } - } else { - display = curCSS( elem, "display" ); - - if ( !values[ index ] && display !== "none" ) { - jQuery._data( elem, "olddisplay", display ); - } + } else if ( !values[ index ] && !isHidden( elem ) ) { + jQuery._data( elem, "olddisplay", curCSS( elem, "display" ) ); } } diff --git a/test/unit/css.js b/test/unit/css.js index 3b5914380..ec1af1dd5 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -504,12 +504,10 @@ test("show() resolves correct default display #8099", function() { dfn8099.remove(); }); -test( "show() resolves correct default display, detached nodes (#10006)", function(){ - // Tests originally contributed by Orkel in - // https://github.com/jquery/jquery/pull/458 - expect( 11 ); +test( "show() resolves correct default display for detached nodes", function(){ + expect( 13 ); - var div, span; + var div, span, tr, trDisplay; div = jQuery("<div class='hidden'>"); div.show().appendTo("#qunit-fixture"); @@ -559,6 +557,18 @@ test( "show() resolves correct default display, detached nodes (#10006)", functi div.show().appendTo("#qunit-fixture"); equal( div.css("display"), "inline", "Make sure that element has same display when it was created." ); div.remove(); + + tr = jQuery("<tr/>"); + jQuery("#table").append( tr ); + trDisplay = tr.css( "display" ); + tr.detach().hide().show(); + + equal( tr[ 0 ].style.display, trDisplay, "For detached tr elements, display should always be like for attached trs" ); + tr.remove(); + + span = span = jQuery("<span/>").hide().show(); + equal( span[ 0 ].style.display, "inline", "For detached span elements, display should always be inline" ); + span.remove(); }); test("show() resolves correct default display #10227", function() { |