mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Fix #13310. Get the right display value for disconnected nodes. Close gh-1156.
This commit is contained in:
parent
a30785a4dd
commit
f3db084f7c
17
src/css.js
17
src/css.js
@ -54,7 +54,7 @@ function getStyles( elem ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function showHide( elements, show ) {
|
function showHide( elements, show ) {
|
||||||
var elem,
|
var display, elem, hidden,
|
||||||
values = [],
|
values = [],
|
||||||
index = 0,
|
index = 0,
|
||||||
length = elements.length;
|
length = elements.length;
|
||||||
@ -64,11 +64,13 @@ function showHide( elements, show ) {
|
|||||||
if ( !elem.style ) {
|
if ( !elem.style ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
values[ index ] = jQuery._data( elem, "olddisplay" );
|
values[ index ] = jQuery._data( elem, "olddisplay" );
|
||||||
|
display = elem.style.display;
|
||||||
if ( show ) {
|
if ( show ) {
|
||||||
// Reset the inline display of this element to learn if it is
|
// Reset the inline display of this element to learn if it is
|
||||||
// being hidden by cascaded rules or not
|
// being hidden by cascaded rules or not
|
||||||
if ( !values[ index ] && elem.style.display === "none" ) {
|
if ( !values[ index ] && display === "none" ) {
|
||||||
elem.style.display = "";
|
elem.style.display = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,8 +80,15 @@ function showHide( elements, show ) {
|
|||||||
if ( elem.style.display === "" && isHidden( elem ) ) {
|
if ( elem.style.display === "" && isHidden( elem ) ) {
|
||||||
values[ index ] = jQuery._data( elem, "olddisplay", css_defaultDisplay(elem.nodeName) );
|
values[ index ] = jQuery._data( elem, "olddisplay", css_defaultDisplay(elem.nodeName) );
|
||||||
}
|
}
|
||||||
} else if ( !values[ index ] && !isHidden( elem ) ) {
|
} else {
|
||||||
jQuery._data( elem, "olddisplay", jQuery.css( elem, "display" ) );
|
|
||||||
|
if ( !values[ index ] ) {
|
||||||
|
hidden = isHidden( elem );
|
||||||
|
|
||||||
|
if ( display && display !== "none" || !hidden ) {
|
||||||
|
jQuery._data( elem, "olddisplay", hidden ? display : jQuery.css( elem, "display" ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,3 +151,5 @@ section { background:#f0f; display:block; }
|
|||||||
|
|
||||||
/* #11971 */
|
/* #11971 */
|
||||||
#foo { background: url(1x1.jpg) right bottom no-repeat; }
|
#foo { background: url(1x1.jpg) right bottom no-repeat; }
|
||||||
|
|
||||||
|
#display { display: list-item !important; }
|
||||||
|
@ -318,6 +318,7 @@ Z</textarea>
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="fx-tests"></div>
|
<div id="fx-tests"></div>
|
||||||
|
<span id="display"></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</dl>
|
</dl>
|
||||||
|
@ -970,4 +970,27 @@ asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original Eleme
|
|||||||
window.setTimeout( start, 1000 );
|
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 ] );
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user