aboutsummaryrefslogtreecommitdiffstats
path: root/src/css
diff options
context:
space:
mode:
authorOleg <markelog@gmail.com>2013-09-17 16:06:21 +0400
committerOleg <markelog@gmail.com>2013-09-17 16:16:47 +0400
commitfd2964237f07d8b6985df2145a4990f96eddba87 (patch)
tree106035479d4c80df949d20c3ed222bac8ff6a7a4 /src/css
parent303e41d996317611ee3397ba018b9d4c8fafde47 (diff)
downloadjquery-fd2964237f07d8b6985df2145a4990f96eddba87.tar.gz
jquery-fd2964237f07d8b6985df2145a4990f96eddba87.zip
Fix #12723 and simplification and optmization of defaultDisplay helper
(cherry picked from commit a25343001eea2436dcf8ea60deea3844f77e42e4)
Diffstat (limited to 'src/css')
-rw-r--r--src/css/defaultDisplay.js29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/css/defaultDisplay.js b/src/css/defaultDisplay.js
index 7f54d207a..518c7d8ae 100644
--- a/src/css/defaultDisplay.js
+++ b/src/css/defaultDisplay.js
@@ -4,17 +4,28 @@ define([
], function( jQuery ) {
var iframe,
- elemdisplay = { BODY: "block" };
+ elemdisplay = {};
/**
* Retrieve the actual display of a element
* @param {String} name nodeName of the element
* @param {Object} doc Document object
*/
+// Called only from within defaultDisplay
function actualDisplay( name, doc ) {
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;
}
@@ -31,15 +42,15 @@ function defaultDisplay( nodeName ) {
// If the simple way fails, read from inside an iframe
if ( display === "none" || !display ) {
+
// Use the already-created iframe if possible
- iframe = ( iframe ||
- jQuery("<iframe frameborder='0' width='0' height='0'/>")
- .css( "cssText", "display:block !important" )
- ).appendTo( doc.documentElement );
+ iframe = (iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" )).appendTo( doc.documentElement );
// Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
- doc = ( iframe[0].contentWindow || iframe[0].contentDocument ).document;
- doc.write("<!doctype html><html><body>");
+ doc = ( iframe[ 0 ].contentWindow || iframe[ 0 ].contentDocument ).document;
+
+ // Support: IE
+ doc.write();
doc.close();
display = actualDisplay( nodeName, doc );