mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Fix #12723 and simplification and optmization of defaultDisplay helper
This commit is contained in:
parent
642e9a4557
commit
a25343001e
@ -4,17 +4,28 @@ define([
|
|||||||
], function( jQuery ) {
|
], function( jQuery ) {
|
||||||
|
|
||||||
var iframe,
|
var iframe,
|
||||||
elemdisplay = { BODY: "block" };
|
elemdisplay = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the actual display of a element
|
* Retrieve the actual display of a element
|
||||||
* @param {String} name nodeName of the element
|
* @param {String} name nodeName of the element
|
||||||
* @param {Object} doc Document object
|
* @param {Object} doc Document object
|
||||||
*/
|
*/
|
||||||
|
// Called only from within defaultDisplay
|
||||||
function actualDisplay( name, doc ) {
|
function actualDisplay( name, doc ) {
|
||||||
var elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
|
var elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
|
||||||
display = jQuery.css( elem[0], "display" );
|
|
||||||
elem.remove();
|
// getDefaultComputedStyle might be reliably used only on attached element
|
||||||
|
display = window.getDefaultComputedStyle ?
|
||||||
|
|
||||||
|
// Use of this method is a temporary fix (more like optmization) until something better comes along,
|
||||||
|
// since it was removed from specification and supported only in FF
|
||||||
|
window.getDefaultComputedStyle( elem[ 0 ] ).display : jQuery.css( elem[ 0 ], "display" );
|
||||||
|
|
||||||
|
// We don't have any data stored on the element,
|
||||||
|
// so use "detach" method as fast way to get rid of the element
|
||||||
|
elem.detach();
|
||||||
|
|
||||||
return display;
|
return display;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,15 +42,15 @@ function defaultDisplay( nodeName ) {
|
|||||||
|
|
||||||
// If the simple way fails, read from inside an iframe
|
// If the simple way fails, read from inside an iframe
|
||||||
if ( display === "none" || !display ) {
|
if ( display === "none" || !display ) {
|
||||||
|
|
||||||
// Use the already-created iframe if possible
|
// Use the already-created iframe if possible
|
||||||
iframe = ( iframe ||
|
iframe = (iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" )).appendTo( doc.documentElement );
|
||||||
jQuery("<iframe frameborder='0' width='0' height='0'/>")
|
|
||||||
.css( "cssText", "display:block !important" )
|
|
||||||
).appendTo( doc.documentElement );
|
|
||||||
|
|
||||||
// Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
|
// Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
|
||||||
doc = ( iframe[0].contentWindow || iframe[0].contentDocument ).document;
|
doc = iframe[ 0 ].contentDocument;
|
||||||
doc.write("<!doctype html><html><body>");
|
|
||||||
|
// Support: IE
|
||||||
|
doc.write();
|
||||||
doc.close();
|
doc.close();
|
||||||
|
|
||||||
display = actualDisplay( nodeName, doc );
|
display = actualDisplay( nodeName, doc );
|
||||||
|
@ -543,21 +543,25 @@ test( "show() resolves correct default display for detached nodes", function(){
|
|||||||
span.remove();
|
span.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("show() resolves correct default display #10227", function() {
|
test("show() resolves correct default display #10227", 4, function() {
|
||||||
expect(2);
|
var html = jQuery( document.documentElement ),
|
||||||
|
body = jQuery( "body" );
|
||||||
|
|
||||||
var body = jQuery("body");
|
body.append( "<p class='ddisplay'>a<style>body{display:none}</style></p>" );
|
||||||
body.append(
|
|
||||||
"<p id='ddisplay'>a<style>body{display:none}</style></p>"
|
|
||||||
);
|
|
||||||
|
|
||||||
equal( body.css("display"), "none", "Initial display: none" );
|
equal( body.css("display"), "none", "Initial display for body element: none" );
|
||||||
|
|
||||||
body.show();
|
body.show();
|
||||||
equal( body.css("display"), "block", "Correct display: block" );
|
equal( body.css("display"), "block", "Correct display for body element: block" );
|
||||||
|
|
||||||
jQuery("#ddisplay").remove();
|
body.append( "<p class='ddisplay'>a<style>html{display:none}</style></p>" );
|
||||||
QUnit.expectJqData( body[0], "olddisplay" );
|
|
||||||
|
equal( html.css("display"), "none", "Initial display for html element: none" );
|
||||||
|
|
||||||
|
html.show();
|
||||||
|
equal( html.css( "display" ), "block", "Correct display for html element: block" );
|
||||||
|
|
||||||
|
jQuery( ".ddisplay" ).remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("show() resolves correct default display when iframe display:none #12904", function() {
|
test("show() resolves correct default display when iframe display:none #12904", function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user