From bea5ecbba72f22e8924186d9b81839122ec86aef Mon Sep 17 00:00:00 2001 From: Oleg Date: Sat, 29 Sep 2012 00:56:49 +0400 Subject: [PATCH] Fix #10416. Don't trust computed styles on detached elements. Close gh-941. --- src/css.js | 14 ++++++-------- 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("