]> source.dussan.org Git - jquery.git/commitdiff
Ticket #8099 Conditional iframe approache, caches both iframe and iframedoc for reuse
authorrwldrn <waldron.rick@gmail.com>
Wed, 13 Apr 2011 17:43:52 +0000 (13:43 -0400)
committerrwldrn <waldron.rick@gmail.com>
Wed, 13 Apr 2011 17:43:52 +0000 (13:43 -0400)
src/effects.js
test/unit/effects.js

index bdd0715efd3858d903706f1aa07beab37ba6ddda..828798cb5a8420ee5a86d69498da396bff65ee7b 100644 (file)
@@ -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("<!doctype><html><body></body></html>");
-               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("<!doctype><html><body></body></html>");
+
+                               // 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("<iframe/>", {
-       css: {
-               width: 0,
-               height: 0, 
-               border: 0
-       }
-});
+defaultDisplay.iframe = null;
+defaultDisplay.iframeDoc = null;
+
+
 
 })( jQuery );
index b68b9b6b0d0aab08b46995c229ff9991bf267916..f3ccd218c9a394887cb3513ecd7850ef07b92ee5 100644 (file)
@@ -163,15 +163,19 @@ test("Persist correct display value", function() {
 });
 
 test("show() resolves correct default display #8099", function() {
-       expect(3);
+       expect(5);
        var bug8099 = jQuery("<tt/>").appendTo("#main");
 
        equals( bug8099.css("display"), "none", "default display override for all tt" );
        equals( bug8099.show().css("display"), "inline", "Correctly resolves display:inline" );
 
+       equals( jQuery("#foo").hide().show().css("display"), "block", "Correctly resolves display:block after hide/show" );
+
+       equals( bug8099.hide().css("display"), "none", "default display override for all tt" );
+       equals( bug8099.show().css("display"), "inline", "Correctly resolves display:inline" );
+
        bug8099.remove();
 
-       equals( jQuery("#foo").hide().show().css("display"), "block", "Correctly resolves display:block after hide/show" );
 });