Skip to content
Browse files

Fix #10416. Don't trust computed styles on detached elements. Close g…

  • Loading branch information...
1 parent 5be4c10 commit bea5ecbba72f22e8924186d9b81839122ec86aef @markelog markelog committed with dmethvin Sep 29, 2012
Showing with 21 additions and 13 deletions.
  1. +6 −8 src/css.js
  2. +15 −5 test/unit/css.js
View
14 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" ) );
}
}
View
20 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() {

0 comments on commit bea5ecb

Please sign in to comment.
Something went wrong with that request. Please try again.