From 0d2e4796dc97d3f9d6b5c1977e883b3ddf2f53d9 Mon Sep 17 00:00:00 2001 From: rwldrn Date: Mon, 31 Jan 2011 14:31:15 -0500 Subject: [PATCH 1/2] Bug #8099 - Always restore to correct display value based on element's expected default display --- src/effects.js | 29 +++++++++++++++++++++++++---- test/data/testsuite.css | 3 +++ test/unit/effects.js | 12 ++++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/effects.js b/src/effects.js index b0675395..c73fd929 100644 --- a/src/effects.js +++ b/src/effects.js @@ -505,17 +505,38 @@ if ( jQuery.expr && jQuery.expr.filters ) { } function defaultDisplay( nodeName ) { - if ( !elemdisplay[ nodeName ] ) { - var elem = jQuery("<" + nodeName + ">").appendTo("body"), - display = elem.css("display"); + var stylesheets = document.styleSheets, + disabled = [], + elem, display; + if ( !elemdisplay[ nodeName ] ) { + + // #8099 - If the end-dev has globally changed a default + // display, we can temporarily disable their styles to check + // for the correct default value + jQuery.each( stylesheets, function( idx, obj ) { + disabled[ idx ] = obj.disabled; + obj.disabled = true; + }); + + // Create a temp element and check it's default display + elem = jQuery("<" + nodeName + ">").appendTo("body"), + display = elem.css("display"); + + // Remove temp element elem.remove(); if ( display === "none" || display === "" ) { display = "block"; } - + + // Store the correct default display elemdisplay[ nodeName ] = display; + + // Restore stylesheets + jQuery.each( stylesheets, function( idx, obj ) { + this.disabled = disabled[ idx ]; + }); } return elemdisplay[ nodeName ]; diff --git a/test/data/testsuite.css b/test/data/testsuite.css index cffaaa46..9ca2cd74 100644 --- a/test/data/testsuite.css +++ b/test/data/testsuite.css @@ -109,3 +109,6 @@ div#show-tests * { display: none; } #nothiddendiv { font-size: 16px; } #nothiddendivchild.em { font-size: 2em; } #nothiddendivchild.prct { font-size: 150%; } + +/* 8099 changes to default styles are read correctly */ +tt { display: none; } diff --git a/test/unit/effects.js b/test/unit/effects.js index b1dd2884..ce9c16c8 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -169,6 +169,18 @@ test("Persist correct display value", function() { }); }); +test("show() resolves correct default display #8099", function() { + expect(3); + var bug8099 = jQuery("").appendTo("#main"); + + equals( bug8099.css("display"), "none", "default display override for all tt" ); + equals( bug8099.show().css("display"), "inline", "Correctly resolves display:inline" ); + + bug8099.remove(); + + equals( jQuery("#foo").hide().show().css("display"), "block", "Correctly resolves display:block after hide/show" ); +}); + test("animate(Hash, Object, Function)", function() { expect(1); stop(); From c67867ad0cd546ab461f13336f74b3f762d8fe7d Mon Sep 17 00:00:00 2001 From: rwldrn Date: Mon, 31 Jan 2011 14:50:03 -0500 Subject: [PATCH 2/2] Bug #8099 - Updates per review --- src/effects.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/effects.js b/src/effects.js index c73fd929..2dd70111 100644 --- a/src/effects.js +++ b/src/effects.js @@ -507,19 +507,23 @@ if ( jQuery.expr && jQuery.expr.filters ) { function defaultDisplay( nodeName ) { var stylesheets = document.styleSheets, disabled = [], - elem, display; + elem, display, style, idx; if ( !elemdisplay[ nodeName ] ) { // #8099 - If the end-dev has globally changed a default // display, we can temporarily disable their styles to check // for the correct default value - jQuery.each( stylesheets, function( idx, obj ) { - disabled[ idx ] = obj.disabled; - obj.disabled = true; - }); + for ( idx = 0; idx < stylesheets.length; ++idx ) { + style = stylesheets[ idx ]; + disabled[ idx ] = style.disabled; + style.disabled = true; + } - // Create a temp element and check it's default display + // To accurately check an element's default display value, + // create a temp element and check it's default display, this + // will ensure that the value returned is not a user-tampered + // value. elem = jQuery("<" + nodeName + ">").appendTo("body"), display = elem.css("display"); @@ -534,9 +538,9 @@ function defaultDisplay( nodeName ) { elemdisplay[ nodeName ] = display; // Restore stylesheets - jQuery.each( stylesheets, function( idx, obj ) { - this.disabled = disabled[ idx ]; - }); + for ( idx = 0; idx < stylesheets.length; ++idx ) { + stylesheets[ idx ].disabled = disabled[ idx ]; + } } return elemdisplay[ nodeName ];