diff options
author | Richard Gibson <richard.gibson@gmail.com> | 2012-12-08 18:04:13 -0500 |
---|---|---|
committer | Richard Gibson <richard.gibson@gmail.com> | 2012-12-08 18:04:13 -0500 |
commit | d343e6b9ed501052f1676694d5e53649c92e65a0 (patch) | |
tree | 50879e4c04e34f7c51e2aa21958203242808b006 /src/css.js | |
parent | 23d7cf0488bfeaab51d8f55435cab01f5cf990ca (diff) | |
download | jquery-d343e6b9ed501052f1676694d5e53649c92e65a0.tar.gz jquery-d343e6b9ed501052f1676694d5e53649c92e65a0.zip |
Fix #12904: Firefox defaultDisplay with body/iframe display:none. Report and solution by @maranomynet; test by @rwldrn.
Diffstat (limited to 'src/css.js')
-rw-r--r-- | src/css.js | 64 |
1 files changed, 29 insertions, 35 deletions
diff --git a/src/css.js b/src/css.js index 334e31a92..c9a1ab433 100644 --- a/src/css.js +++ b/src/css.js @@ -1,4 +1,4 @@ -var curCSS, iframe, iframeDoc, +var curCSS, iframe, ralpha = /alpha\([^)]*\)/i, ropacity = /opacity\s*=\s*([^)]*)/, rposition = /^(top|right|bottom|left)$/, @@ -446,44 +446,38 @@ function getWidthOrHeight( elem, name, extra ) { // Try to determine the default display value of an element function css_defaultDisplay( nodeName ) { - if ( elemdisplay[ nodeName ] ) { - return elemdisplay[ nodeName ]; - } - - var elem = jQuery( "<" + nodeName + ">" ).appendTo( document.body ), - display = elem.css("display"); - elem.remove(); - - // If the simple way fails, - // get element's real default display by attaching it to a temp iframe - if ( display === "none" || display === "" ) { - // Use the already-created iframe if possible - iframe = document.body.appendChild( - iframe || jQuery.extend( document.createElement("iframe"), { - frameBorder: 0, - width: 0, - height: 0 - }) - ); - - // 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("<!doctype html><html><body>"); - iframeDoc.close(); + var elem, + doc = document, + display = elemdisplay[ nodeName ]; + + if ( !display ) { + elem = jQuery( doc.createElement( nodeName ) ); + display = curCSS( elem.appendTo( doc.body )[0], "display" ); + elem.remove(); + + // If the simple way fails, read from inside an iframe + if ( display === "none" || !display ) { + // Use the already-created iframe if possible + iframe = ( iframe || + jQuery("<iframe frameborder='0' width='0' height='0'/>") + .css( "cssText", "display:block !important" ) + ).appendTo( doc.documentElement ); + + // Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse + doc = ( iframe[0].contentWindow || iframe[0].contentDocument ).document; + doc.write("<!doctype html><html><body>"); + doc.close(); + + elem = jQuery( doc.createElement( nodeName ) ); + display = curCSS( elem.appendTo( doc.body )[0], "display" ); + elem.remove(); + iframe.detach(); } - elem = iframeDoc.body.appendChild( iframeDoc.createElement(nodeName) ); - - display = curCSS( elem, "display" ); - document.body.removeChild( iframe ); + // Store the correct default display + elemdisplay[ nodeName ] = display; } - // Store the correct default display - elemdisplay[ nodeName ] = display; - return display; } |