Fix #10416. Don't trust computed styles on detached elements. Close gh-941.

This commit is contained in:
Oleg 2012-09-29 00:56:49 +04:00 committed by Dave Methvin
parent 5be4c10cf7
commit bea5ecbba7
2 changed files with 21 additions and 13 deletions

View File

@ -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 File

@ -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() {