Fixes #8099 using iframe to capture an element's real default display; suggested by lrbabe/louisremi

This commit is contained in:
rwldrn 2011-04-12 13:47:27 -04:00
parent 7164615f67
commit 885b64d4e6

50
src/effects.js vendored
View file

@ -548,30 +548,35 @@ if ( jQuery.expr && jQuery.expr.filters ) {
} }
function defaultDisplay( nodeName ) { function defaultDisplay( nodeName ) {
var stylesheets = document.styleSheets, var iframe, iframeDoc, iframeNode, display;
disabled = [],
elem, display, style, idx;
if ( !elemdisplay[ nodeName ] ) { if ( !elemdisplay[ nodeName ] ) {
// #8099 - If the end-dev has globally changed a default iframe = defaultDisplay.iframe.clone()[ 0 ];
// display, we can temporarily disable their styles to check
// for the correct default value iframe.style.display = "none";
for ( idx = 0; idx < stylesheets.length; ++idx ) {
style = stylesheets[ idx ]; document.body.appendChild( iframe );
disabled[ idx ] = style.disabled;
style.disabled = true; iframeDoc = iframe.contentWindow && iframe.contentWindow ||
iframe.contentDocument.document && iframe.contentDocument.document ||
iframe.contentDocument;
iframeNode = jQuery( "<" + nodeName + ">" ).appendTo( jQuery( "body", iframeDoc.document ) );
if ( !iframeNode.length ) {
// this will only occur in IE
iframeDoc.document.open();
iframeDoc.document.write("<!doctype html><html><body></body></html>");
elem = iframeDoc.document.createElement( nodeName );
iframeDoc.document.body.appendChild( elem );
iframeDoc.document.close();
iframeNode = jQuery( elem );
} }
// To accurately check an element's default display value, // firefox returns undefined from css("display")
// create a temp element and check it's default display, this display = iframeNode.css("display") || iframeNode[ 0 ].style.display;
// 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 === "" ) { if ( display === "none" || display === "" ) {
display = "block"; display = "block";
@ -580,13 +585,12 @@ function defaultDisplay( nodeName ) {
// Store the correct default display // Store the correct default display
elemdisplay[ nodeName ] = display; elemdisplay[ nodeName ] = display;
// Restore stylesheets iframe.parentNode.removeChild( iframe );
for ( idx = 0; idx < stylesheets.length; ++idx ) {
stylesheets[ idx ].disabled = disabled[ idx ];
}
} }
return elemdisplay[ nodeName ]; return elemdisplay[ nodeName ];
} }
defaultDisplay.iframe = jQuery("<iframe/>");
})( jQuery ); })( jQuery );