From a25343001eea2436dcf8ea60deea3844f77e42e4 Mon Sep 17 00:00:00 2001 From: Oleg Date: Tue, 17 Sep 2013 15:47:31 +0400 Subject: [PATCH] Fix #12723 and simplification and optmization of defaultDisplay helper --- src/css/defaultDisplay.js | 29 ++++++++++++++++++++--------- test/unit/css.js | 24 ++++++++++++++---------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/css/defaultDisplay.js b/src/css/defaultDisplay.js index 78acb2bcd..45af9f90f 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("