Skip to content

Commit dba93f7

Browse files
gibson042timmywil
authored andcommitted
CSS: Restore cascade-override behavior in .show
Fixes gh-2654 Fixes gh-2308 Close gh-2810 Ref 86419b1
1 parent a268f52 commit dba93f7

File tree

5 files changed

+391
-116
lines changed

5 files changed

+391
-116
lines changed

src/css/showHide.js

+38-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,31 @@ define( [
44
"../css/var/isHidden"
55
], function( jQuery, dataPriv, isHidden ) {
66

7+
var defaultDisplayMap = {};
8+
9+
function getDefaultDisplay( elem ) {
10+
var temp,
11+
doc = elem.ownerDocument,
12+
nodeName = elem.nodeName,
13+
display = defaultDisplayMap[ nodeName ];
14+
15+
if ( display ) {
16+
return display;
17+
}
18+
19+
temp = doc.body.appendChild( doc.createElement( nodeName ) ),
20+
display = jQuery.css( temp, "display" );
21+
22+
temp.parentNode.removeChild( temp );
23+
24+
if ( display === "none" ) {
25+
display = "block";
26+
}
27+
defaultDisplayMap[ nodeName ] = display;
28+
29+
return display;
30+
}
31+
732
function showHide( elements, show ) {
833
var display, elem,
934
values = [],
@@ -19,23 +44,30 @@ function showHide( elements, show ) {
1944

2045
display = elem.style.display;
2146
if ( show ) {
22-
if ( display === "none" ) {
2347

24-
// Restore a pre-hide() value if we have one
25-
values[ index ] = dataPriv.get( elem, "display" ) || "";
48+
// Since we force visibility upon cascade-hidden elements, an immediate (and slow)
49+
// check is required in this first loop unless we have a nonempty display value (either
50+
// inline or about-to-be-restored)
51+
if ( display === "none" ) {
52+
values[ index ] = dataPriv.get( elem, "display" ) || null;
53+
if ( !values[ index ] ) {
54+
elem.style.display = "";
55+
}
56+
}
57+
if ( elem.style.display === "" && jQuery.css( elem, "display" ) === "none" ) {
58+
values[ index ] = getDefaultDisplay( elem );
2659
}
2760
} else {
2861
if ( display !== "none" ) {
2962
values[ index ] = "none";
3063

31-
// Remember the value we're replacing
64+
// Remember what we're overwriting
3265
dataPriv.set( elem, "display", display );
3366
}
3467
}
3568
}
3669

37-
// Set the display of the elements in a second loop
38-
// to avoid the constant reflow
70+
// Set the display of the elements in a second loop to avoid constant reflow
3971
for ( index = 0; index < length; index++ ) {
4072
if ( values[ index ] != null ) {
4173
elements[ index ].style.display = values[ index ];

src/effects.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,16 @@ function defaultPrefilter( elem, props, opts ) {
154154
}
155155
display = jQuery.css( elem, "display" );
156156
if ( display === "none" ) {
157-
display = restoreDisplay || swap( elem, { "display": "" }, function() {
158-
return jQuery.css( elem, "display" );
159-
} );
157+
if ( restoreDisplay ) {
158+
display = restoreDisplay;
159+
} else {
160+
161+
// Get nonempty value(s) by temporarily forcing visibility
162+
showHide( [ elem ], true );
163+
restoreDisplay = elem.style.display || restoreDisplay;
164+
display = jQuery.css( elem, "display" );
165+
showHide( [ elem ] );
166+
}
160167
}
161168

162169
// Animate inline elements as inline-block

test/data/testsuite.css

+5-9
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ div#fx-tests div.overflow {
2020
overflow: visible;
2121
}
2222

23-
div.inline {
24-
display: inline;
25-
}
26-
2723
div.autoheight {
2824
height: auto;
2925
}
@@ -68,11 +64,6 @@ div.noopacity {
6864
opacity: 0;
6965
}
7066

71-
div.hidden,
72-
span.hidden {
73-
display: none;
74-
}
75-
7667
div#fx-tests div.widewidth {
7768
background-repeat: repeat-x;
7869
}
@@ -134,3 +125,8 @@ section { background:#f0f; display:block; }
134125
#span-14824 { display: block; }
135126

136127
#display { display: list-item !important; }
128+
129+
.block { display: block; }
130+
.inline { display: inline; }
131+
.list-item { display: list-item; }
132+
.hidden, .none { display: none; }

0 commit comments

Comments
 (0)