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 | 63 +++++++++++++++++++++++++++----------------- test/unit/effects.js | 8 ++++-- 2 files changed, 45 insertions(+), 26 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 ]; - - document.body.appendChild( iframe ); - - iframeDoc = ( iframe.contentWindow || iframe.contentDocument ).document; - - iframeDoc.open(); - iframeDoc.write(""); - elem = iframeDoc.createElement( nodeName ); - iframeDoc.body.appendChild( elem ); - iframeDoc.close(); - - display = jQuery( elem ).css( "display" ); + elem.remove(); if ( display === "none" || display === "" ) { - display = "block"; + + var iframe = defaultDisplay.iframe, + iframeDoc = defaultDisplay.iframeDoc; + + // No iframe to use yet, so create it + if ( !defaultDisplay.iframe ) { + + iframe = document.createElement( "iframe" ); + iframe.width = iframe.height = 0; + + 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("