Ticket #8099 Performance tweaking, credits

This commit is contained in:
rwldrn 2011-04-13 15:43:15 -04:00
parent 59240d31c0
commit a76decc476
3 changed files with 27 additions and 23 deletions

26
src/effects.js vendored
View file

@ -560,31 +560,33 @@ function defaultDisplay( nodeName ) {
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

View file

@ -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; }

20
test/unit/effects.js vendored
View file

@ -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();
});