]> source.dussan.org Git - jquery.git/commitdiff
Bug #8099 - Always restore to correct display value based on element's expected defau...
authorrwldrn <waldron.rick@gmail.com>
Mon, 31 Jan 2011 19:31:15 +0000 (14:31 -0500)
committerrwldrn <waldron.rick@gmail.com>
Mon, 31 Jan 2011 19:31:15 +0000 (14:31 -0500)
src/effects.js
test/data/testsuite.css
test/unit/effects.js

index b0675395f45ac8d2ab5eb6d366da3b5d0bf42186..c73fd929e6af74ac4b3f2c007d1d6b90bcd03818 100644 (file)
@@ -505,17 +505,38 @@ if ( jQuery.expr && jQuery.expr.filters ) {
 }
 
 function defaultDisplay( nodeName ) {
+       var stylesheets = document.styleSheets,
+                       disabled = [],
+                       elem, display;
+
        if ( !elemdisplay[ nodeName ] ) {
-               var elem = jQuery("<" + nodeName + ">").appendTo("body"),
-                       display = elem.css("display");
 
+               // #8099 - If the end-dev has globally changed a default
+               // display, we can temporarily disable their styles to check
+               // for the correct default value
+               jQuery.each( stylesheets, function( idx, obj ) { 
+                       disabled[ idx ] = obj.disabled;
+                       obj.disabled = true;
+               }); 
+               
+               // Create a temp element and check it's default display
+               elem = jQuery("<" + nodeName + ">").appendTo("body"),
+               display = elem.css("display");
+               
+               // Remove temp element
                elem.remove();
 
                if ( display === "none" || display === "" ) {
                        display = "block";
                }
-
+               
+               // Store the correct default display
                elemdisplay[ nodeName ] = display;
+
+               // Restore stylesheets
+               jQuery.each( stylesheets, function( idx, obj ) {
+                       this.disabled = disabled[ idx ];
+               });
        }
 
        return elemdisplay[ nodeName ];
index cffaaa46ab307c507a5441beb534e7303fe4ace7..9ca2cd74827b2eb6c4864c0c625f3527994e66e8 100644 (file)
@@ -109,3 +109,6 @@ div#show-tests * { display: none; }
 #nothiddendiv { font-size: 16px; }
 #nothiddendivchild.em { font-size: 2em; }
 #nothiddendivchild.prct { font-size: 150%; }
+
+/* 8099 changes to default styles are read correctly */
+tt { display: none; }
index b1dd28840e7d6271fe6351518a9a611653e0ad14..ce9c16c8cd3b1dfc3322bd53d55fff3d7d947050 100644 (file)
@@ -169,6 +169,18 @@ test("Persist correct display value", function() {
   });
 });
 
+test("show() resolves correct default display #8099", function() {
+       expect(3);
+       var bug8099 = jQuery("<tt/>").appendTo("#main");
+
+       equals( bug8099.css("display"), "none", "default display override for all tt" );
+       equals( bug8099.show().css("display"), "inline", "Correctly resolves display:inline" );
+
+       bug8099.remove();
+
+       equals( jQuery("#foo").hide().show().css("display"), "block", "Correctly resolves display:block after hide/show" );
+});
+
 test("animate(Hash, Object, Function)", function() {
        expect(1);
        stop();