]> source.dussan.org Git - jquery.git/commitdiff
Fix #13310. Get the right display value for disconnected nodes. Close gh-1155.
authorOleg <markelog@gmail.com>
Fri, 1 Feb 2013 12:57:50 +0000 (16:57 +0400)
committerDave Methvin <dave.methvin@gmail.com>
Mon, 4 Feb 2013 20:13:01 +0000 (15:13 -0500)
src/css.js
test/data/testsuite.css
test/index.html
test/unit/css.js

index 72a9962d313f09ec41688227e8996a3d21c6cfe1..1d15314528f25b6b9c892b99100015c1a1d8bde0 100644 (file)
@@ -51,7 +51,7 @@ function isHidden( elem, el ) {
 }
 
 function showHide( elements, show ) {
-       var elem,
+       var display, elem, hidden,
                values = [],
                index = 0,
                length = elements.length;
@@ -61,11 +61,13 @@ function showHide( elements, show ) {
                if ( !elem.style ) {
                        continue;
                }
+
                values[ index ] = jQuery._data( elem, "olddisplay" );
+               display = elem.style.display;
                if ( show ) {
                        // Reset the inline display of this element to learn if it is
                        // being hidden by cascaded rules or not
-                       if ( !values[ index ] && elem.style.display === "none" ) {
+                       if ( !values[ index ] && display === "none" ) {
                                elem.style.display = "";
                        }
 
@@ -75,8 +77,15 @@ function showHide( elements, show ) {
                        if ( elem.style.display === "" && isHidden( elem ) ) {
                                values[ index ] = jQuery._data( elem, "olddisplay", css_defaultDisplay(elem.nodeName) );
                        }
-               } else if ( !values[ index ] && !isHidden( elem ) ) {
-                       jQuery._data( elem, "olddisplay", jQuery.css( elem, "display" ) );
+               } else {
+
+                       if ( !values[ index ] ) {
+                               hidden = isHidden( elem );
+
+                               if ( display && display !== "none" || !hidden ) {
+                                       jQuery._data( elem, "olddisplay", hidden ? display : jQuery.css( elem, "display" ) );
+                               }
+                       }
                }
        }
 
index 6bb3a5ded4fbfd66660562e91327e25125e08170..1dfa7cd344dfb238089887ff072ab23d365fada3 100644 (file)
@@ -151,3 +151,5 @@ section { background:#f0f; display:block; }
 
 /* #11971 */
 #foo { background: url(1x1.jpg) right bottom no-repeat; }
+
+#display { display: list-item !important; }
index 918d7d2d705415998d83ec7543c50def2750581c..f073054d8f66ff5725b261635bfb7b5c09ec0cd2 100644 (file)
@@ -318,6 +318,7 @@ Z</textarea>
                        </div>
 
                        <div id="fx-tests"></div>
+                       <span id="display"></span>
                </div>
        </div>
        </dl>
index f7c7ad424db66ee4c0eded8b88dcd96bc144f249..303ee55153620841b5ebdcc2188509e4379dc5f2 100644 (file)
@@ -1010,4 +1010,27 @@ asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original Eleme
        window.setTimeout( start, 1000 );
 });
 
+asyncTest( "Make sure initialized display value for disconnected nodes is correct (#13310)", 4, function() {
+       var display = jQuery("#display").css("display"),
+               div = jQuery("<div/>");
+
+       equal( div.css( "display", "inline" ).hide().show().appendTo("body").css( "display" ), "inline", "Initialized display value has returned" );
+       div.remove();
+
+       div.css( "display", "none" ).hide();
+       equal( jQuery._data( div[ 0 ], "olddisplay" ), undefined, "olddisplay is undefined after hiding a detached and hidden element" );
+       div.remove();
+
+       div.css( "display", "inline-block" ).hide().appendTo("body").fadeIn(function() {
+               equal( div.css( "display" ), "inline-block", "Initialized display value has returned" );
+               div.remove();
+
+               start();
+       });
+
+       equal( jQuery._data( jQuery("#display").css( "display", "inline" ).hide()[ 0 ], "olddisplay" ), display,
+       "display: * !Important value should used as initialized display" );
+       jQuery._removeData( jQuery("#display")[ 0 ] );
+});
+
 }