From: jeresig Date: Mon, 14 Feb 2011 17:36:49 +0000 (-0500) Subject: Merge branch '8099' of https://github.com/rwldrn/jquery into rwldrn-8099 X-Git-Url: http://git.asbjorn.it/?a=commitdiff_plain;h=bb9408516aa0fc8892f4e07a99b1a47bce06081b;hp=3ad8dd242acec1066f43a9349f4c1a352680d37b;p=jquery.git Merge branch '8099' of https://github.com/rwldrn/jquery into rwldrn-8099 --- diff --git a/src/effects.js b/src/effects.js index fd832ce..09aba14c 100644 --- a/src/effects.js +++ b/src/effects.js @@ -505,17 +505,42 @@ if ( jQuery.expr && jQuery.expr.filters ) { } function defaultDisplay( nodeName ) { + var stylesheets = document.styleSheets, + disabled = [], + elem, display, style, idx; + if ( !elemdisplay[ nodeName ] ) { - var elem = jQuery("<" + nodeName + ">").appendTo("body"), - display = elem.css("display"); + // #8099 - If the end-dev has globally changed a default + // display, we can temporarily disable their styles to check + // for the correct default value + for ( idx = 0; idx < stylesheets.length; ++idx ) { + style = stylesheets[ idx ]; + disabled[ idx ] = style.disabled; + style.disabled = true; + } + + // 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"); + + // Remove temp element elem.remove(); if ( display === "none" || display === "" ) { display = "block"; } - + + // Store the correct default display elemdisplay[ nodeName ] = display; + + // Restore stylesheets + for ( idx = 0; idx < stylesheets.length; ++idx ) { + stylesheets[ idx ].disabled = disabled[ idx ]; + } } return elemdisplay[ nodeName ]; diff --git a/test/data/testsuite.css b/test/data/testsuite.css index cffaaa4..9ca2cd7 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 a07c076..7da8143 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -162,6 +162,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();