Skip to content

Commit

Permalink
Fix 8985,use DocumentFragment get the default display value of an ele…
Browse files Browse the repository at this point in the history
…ment in domian set page avoid iframe error
  • Loading branch information
cmc3cn committed Apr 29, 2011
1 parent 2667b57 commit 6586b11
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/effects.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function( jQuery ) {

var elemdisplay = {},
iframe, iframeDoc,
iframe, iframeDoc, fragment,
rfxtypes = /^(?:toggle|show|hide)$/,
rfxnum = /^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,
timerId,
Expand Down Expand Up @@ -585,24 +585,30 @@ function defaultDisplay( nodeName ) {
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;
if (!fragment) {
document.body.appendChild( iframe );
try {
iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
}
catch(e){
document.body.removeChild( iframe );
fragment = document.createDocumentFragment();
}
}

if(iframeDoc){
iframeDoc.write( "<!doctype><html><body></body></html>" );
}

elem = iframeDoc.createElement( nodeName );

iframeDoc.body.appendChild( elem );

display = jQuery.css( elem, "display" );

document.body.removeChild( iframe );
iframeDoc.close();
elem = iframeDoc.createElement( nodeName );
iframeDoc.body.appendChild( elem );
display = jQuery.css( elem, "display" );
document.body.removeChild( iframe );
}else{
elem = document.createElement( nodeName );
fragment.appendChild( elem );
display = elem.currentStyle.display;
fragment.removeChild( elem );
}
}

// Store the correct default display
Expand Down

0 comments on commit 6586b11

Please sign in to comment.