| 14217 |
anikendra |
1 |
define([
|
|
|
2 |
"../core",
|
|
|
3 |
"../manipulation" // appendTo
|
|
|
4 |
], function( jQuery ) {
|
|
|
5 |
|
|
|
6 |
var iframe,
|
|
|
7 |
elemdisplay = {};
|
|
|
8 |
|
|
|
9 |
/**
|
|
|
10 |
* Retrieve the actual display of a element
|
|
|
11 |
* @param {String} name nodeName of the element
|
|
|
12 |
* @param {Object} doc Document object
|
|
|
13 |
*/
|
|
|
14 |
// Called only from within defaultDisplay
|
|
|
15 |
function actualDisplay( name, doc ) {
|
|
|
16 |
var style,
|
|
|
17 |
elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
|
|
|
18 |
|
|
|
19 |
// getDefaultComputedStyle might be reliably used only on attached element
|
|
|
20 |
display = window.getDefaultComputedStyle && ( style = window.getDefaultComputedStyle( elem[ 0 ] ) ) ?
|
|
|
21 |
|
|
|
22 |
// Use of this method is a temporary fix (more like optimization) until something better comes along,
|
|
|
23 |
// since it was removed from specification and supported only in FF
|
|
|
24 |
style.display : jQuery.css( elem[ 0 ], "display" );
|
|
|
25 |
|
|
|
26 |
// We don't have any data stored on the element,
|
|
|
27 |
// so use "detach" method as fast way to get rid of the element
|
|
|
28 |
elem.detach();
|
|
|
29 |
|
|
|
30 |
return display;
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Try to determine the default display value of an element
|
|
|
35 |
* @param {String} nodeName
|
|
|
36 |
*/
|
|
|
37 |
function defaultDisplay( nodeName ) {
|
|
|
38 |
var doc = document,
|
|
|
39 |
display = elemdisplay[ nodeName ];
|
|
|
40 |
|
|
|
41 |
if ( !display ) {
|
|
|
42 |
display = actualDisplay( nodeName, doc );
|
|
|
43 |
|
|
|
44 |
// If the simple way fails, read from inside an iframe
|
|
|
45 |
if ( display === "none" || !display ) {
|
|
|
46 |
|
|
|
47 |
// Use the already-created iframe if possible
|
|
|
48 |
iframe = (iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" )).appendTo( doc.documentElement );
|
|
|
49 |
|
|
|
50 |
// Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
|
|
|
51 |
doc = iframe[ 0 ].contentDocument;
|
|
|
52 |
|
|
|
53 |
// Support: IE
|
|
|
54 |
doc.write();
|
|
|
55 |
doc.close();
|
|
|
56 |
|
|
|
57 |
display = actualDisplay( nodeName, doc );
|
|
|
58 |
iframe.detach();
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
// Store the correct default display
|
|
|
62 |
elemdisplay[ nodeName ] = display;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
return display;
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
return defaultDisplay;
|
|
|
69 |
|
|
|
70 |
});
|