diff --git a/src/effects.js b/src/effects.js index 7aec8300..a43d5cb3 100644 --- a/src/effects.js +++ b/src/effects.js @@ -1,6 +1,8 @@ (function( jQuery ) { var elemdisplay = {}, + iframe = null, + iframeDoc = null, rfxtypes = /^(?:toggle|show|hide)$/, rfxnum = /^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i, timerId, @@ -548,20 +550,52 @@ if ( jQuery.expr && jQuery.expr.filters ) { } function defaultDisplay( nodeName ) { + if ( !elemdisplay[ nodeName ] ) { - var elem = jQuery("<" + nodeName + ">").appendTo("body"), - display = elem.css("display"); + + var elem = jQuery( "<" + nodeName + ">" ).appendTo( "body" ), + display = elem.css( "display" ); elem.remove(); if ( display === "none" || display === "" ) { - display = "block"; + + // Get element's real default display by attaching it to a temp iframe + // Conritbutions from Louis Remi and Julian Aurbourg + // based on recommendation by Louis Remi + + // No iframe to use yet, so create it + if ( !iframe ) { + iframe = document.createElement( "iframe" ); + iframe.frameBorder = iframe.width = iframe.height = 0; + } + + document.body.appendChild( iframe ); + + // Create a cacheable copy of the iframe document on first call. + // IE and Opera will allow us to reuse the iframeDoc without re-writing the fake html + // document to it, Webkit & Firefox won't allow reusing the iframe document + if ( !iframeDoc || !iframe.createElement ) { + iframeDoc = ( iframe.contentWindow || iframe.contentDocument ).document; + iframeDoc.write( "" ); + } + + elem = iframeDoc.createElement( nodeName ); + + iframeDoc.body.appendChild( elem ); + + display = jQuery.css( elem, "display" ); + + document.body.removeChild( iframe ); } + // Store the correct default display elemdisplay[ nodeName ] = display; } return elemdisplay[ nodeName ]; } + + })( jQuery ); diff --git a/test/data/testsuite.css b/test/data/testsuite.css index a9dd97ba..99851eaa 100644 --- a/test/data/testsuite.css +++ b/test/data/testsuite.css @@ -111,4 +111,9 @@ div#show-tests * { display: none; } #nothiddendivchild.prct { font-size: 150%; } /* For testing type on vml in IE #7071 */ -v\:oval { behavior:url(#default#VML); display:inline-block; } \ No newline at end of file +v\:oval { behavior:url(#default#VML); display:inline-block; } + +/* 8099 changes to default styles are read correctly */ +tt { display: none; } +sup { display: none; } +dfn { display: none; } diff --git a/test/unit/effects.js b/test/unit/effects.js index 4faf6174..8b7cf467 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -162,6 +162,28 @@ test("Persist correct display value", function() { }); }); +test("show() resolves correct default display #8099", function() { + expect(7); + var tt8099 = jQuery("").appendTo("body"), + dfn8099 = jQuery("", { html: "foo"}).appendTo("body"); + + equals( tt8099.css("display"), "none", "default display override for all tt" ); + equals( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" ); + + equals( jQuery("#foo").hide().show().css("display"), "block", "Correctly resolves display:block after hide/show" ); + + equals( tt8099.hide().css("display"), "none", "default display override for all tt" ); + equals( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" ); + + equals( dfn8099.css("display"), "none", "default display override for all dfn" ); + equals( dfn8099.show().css("display"), "inline", "Correctly resolves display:inline" ); + + tt8099.remove(); + dfn8099.remove(); + +}); + + test("animate(Hash, Object, Function)", function() { expect(1); stop();