From 4fde550cb62219d7edd14653888608fbbf39c22a Mon Sep 17 00:00:00 2001 From: rwldrn Date: Wed, 13 Apr 2011 13:43:52 -0400 Subject: [PATCH] Ticket #8099 Conditional iframe approache, caches both iframe and iframedoc for reuse --- src/effects.js | 57 ++++++++++++++++++++++++++++---------------- test/unit/effects.js | 8 +++++-- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/effects.js b/src/effects.js index bdd0715ef..828798cb5 100644 --- a/src/effects.js +++ b/src/effects.js @@ -551,41 +551,56 @@ function defaultDisplay( nodeName ) { if ( !elemdisplay[ nodeName ] ) { - var iframe, iframeDoc, iframeNode, display, elem; + var elem = jQuery( "<" + nodeName + ">" ).appendTo( "body" ), + display = elem.css( "display" ); - iframe = defaultDisplay.iframe.clone()[ 0 ]; + elem.remove(); - document.body.appendChild( iframe ); + if ( display === "none" || display === "" ) { - iframeDoc = ( iframe.contentWindow || iframe.contentDocument ).document; + var iframe = defaultDisplay.iframe, + iframeDoc = defaultDisplay.iframeDoc; - iframeDoc.open(); - iframeDoc.write(""); - elem = iframeDoc.createElement( nodeName ); - iframeDoc.body.appendChild( elem ); - iframeDoc.close(); + // No iframe to use yet, so create it + if ( !defaultDisplay.iframe ) { - display = jQuery( elem ).css( "display" ); + iframe = document.createElement( "iframe" ); + iframe.width = iframe.height = 0; - if ( display === "none" || display === "" ) { - display = "block"; + document.body.appendChild( iframe ); + + iframeDoc = ( iframe.contentWindow || iframe.contentDocument ).document; + iframeDoc.write(""); + + // Cache iframe element + defaultDisplay.iframe = iframe; + defaultDisplay.iframeDoc = iframeDoc; + } else { + + // Reuse previous iframe + document.body.appendChild( iframe ); + + } + + elem = iframeDoc.createElement( nodeName ); + + iframeDoc.body.appendChild( elem ); + + display = jQuery( elem ).css( "display" ); + + iframe.parentNode.removeChild( iframe ); } // Store the correct default display elemdisplay[ nodeName ] = display; - - iframe.parentNode.removeChild( iframe ); } return elemdisplay[ nodeName ]; } -defaultDisplay.iframe = jQuery("