aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrwldrn <waldron.rick@gmail.com>2011-04-13 15:43:15 -0400
committerrwldrn <waldron.rick@gmail.com>2011-04-13 15:43:15 -0400
commita76decc47660591bb807aecf56825019da8b39fa (patch)
tree4a18d1d71ff0a4ae074481b6041ace6b28a15e0e
parent59240d31c0c277a60fdc187e0fc9884007971106 (diff)
downloadjquery-a76decc47660591bb807aecf56825019da8b39fa.tar.gz
jquery-a76decc47660591bb807aecf56825019da8b39fa.zip
Ticket #8099 Performance tweaking, credits
-rw-r--r--src/effects.js28
-rw-r--r--test/data/testsuite.css2
-rw-r--r--test/unit/effects.js20
3 files changed, 27 insertions, 23 deletions
diff --git a/src/effects.js b/src/effects.js
index 460811cd9..a43d5cb3c 100644
--- a/src/effects.js
+++ b/src/effects.js
@@ -556,35 +556,37 @@ function defaultDisplay( nodeName ) {
var elem = jQuery( "<" + nodeName + ">" ).appendTo( "body" ),
display = elem.css( "display" );
- elem.remove();
+ elem.remove();
if ( display === "none" || display === "" ) {
+ // Get element's real default display by attaching it to a temp iframe
+ // Conritbutions from Louis Remi and Julian Aurbourg
+ // based on recommendation by Louis Remi
+
// No iframe to use yet, so create it
if ( !iframe ) {
-
iframe = document.createElement( "iframe" );
- iframe.width = iframe.height = 0;
+ iframe.frameBorder = iframe.width = iframe.height = 0;
+ }
- document.body.appendChild( iframe );
+ 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;
- iframeDoc.write("<!doctype><html><body></body></html>");
-
- } else {
-
- // Reuse previous iframe
- document.body.appendChild( iframe );
-
+ iframeDoc.write( "<!doctype><html><body></body></html>" );
}
elem = iframeDoc.createElement( nodeName );
iframeDoc.body.appendChild( elem );
- display = jQuery( elem ).css( "display" );
+ display = jQuery.css( elem, "display" );
- iframe.parentNode.removeChild( iframe );
+ document.body.removeChild( iframe );
}
// Store the correct default display
diff --git a/test/data/testsuite.css b/test/data/testsuite.css
index b307d4989..683803e8b 100644
--- a/test/data/testsuite.css
+++ b/test/data/testsuite.css
@@ -112,3 +112,5 @@ div#show-tests * { display: none; }
/* 8099 changes to default styles are read correctly */
tt { display: none; }
+sup { display: none; }
+dfn { display: none; }
diff --git a/test/unit/effects.js b/test/unit/effects.js
index 082128876..8b7cf4679 100644
--- a/test/unit/effects.js
+++ b/test/unit/effects.js
@@ -164,22 +164,22 @@ test("Persist correct display value", function() {
test("show() resolves correct default display #8099", function() {
expect(7);
- var bug8099 = jQuery("<tt/>").appendTo("#main"),
- div8099 = jQuery("<div/>", { className: "hidden" }).appendTo("#main");
+ var tt8099 = jQuery("<tt/>").appendTo("body"),
+ dfn8099 = jQuery("<dfn/>", { html: "foo"}).appendTo("body");
- equals( bug8099.css("display"), "none", "default display override for all tt" );
- equals( bug8099.show().css("display"), "inline", "Correctly resolves display:inline" );
+ equals( tt8099.css("display"), "none", "default display override for all tt" );
+ equals( tt8099.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" );
+ equals( tt8099.hide().css("display"), "none", "default display override for all tt" );
+ equals( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" );
- equals( div8099.show().css("display"), "block", "default display override for all div.hidden" );
- equals( div8099.hide().css("display"), "none", "Correctly resolves display:none" );
+ equals( dfn8099.css("display"), "none", "default display override for all dfn" );
+ equals( dfn8099.show().css("display"), "inline", "Correctly resolves display:inline" );
- bug8099.remove();
- div8099.remove();
+ tt8099.remove();
+ dfn8099.remove();
});