Skip to content

Commit 86419b1

Browse files
committed
CSS: Ignore the CSS cascade in show()/hide()/etc.
Fixes gh-1767 Fixes gh-2071 Closes gh-2180
1 parent 5c3101f commit 86419b1

File tree

7 files changed

+379
-429
lines changed

7 files changed

+379
-429
lines changed

src/css.js

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ define([
1111
"./css/var/swap",
1212
"./css/curCSS",
1313
"./css/adjustCSS",
14-
"./css/defaultDisplay",
1514
"./css/addGetHookIf",
1615
"./css/support",
17-
"./data/var/dataPriv",
16+
"./css/showHide",
1817

1918
"./core/init",
2019
"./core/ready",
2120
"./selector" // contains
2221
], function( jQuery, pnum, access, rmargin, rcssNum, rnumnonpx, cssExpand, isHidden,
23-
getStyles, swap, curCSS, adjustCSS, defaultDisplay, addGetHookIf, support, dataPriv ) {
22+
getStyles, swap, curCSS, adjustCSS, addGetHookIf, support, showHide ) {
2423

2524
var
2625
// Swappable if display is none or starts with table
@@ -151,65 +150,6 @@ function getWidthOrHeight( elem, name, extra ) {
151150
) + "px";
152151
}
153152

154-
function showHide( elements, show ) {
155-
var display, elem, hidden,
156-
values = [],
157-
index = 0,
158-
length = elements.length;
159-
160-
for ( ; index < length; index++ ) {
161-
elem = elements[ index ];
162-
if ( !elem.style ) {
163-
continue;
164-
}
165-
166-
values[ index ] = dataPriv.get( elem, "olddisplay" );
167-
display = elem.style.display;
168-
if ( show ) {
169-
// Reset the inline display of this element to learn if it is
170-
// being hidden by cascaded rules or not
171-
if ( !values[ index ] && display === "none" ) {
172-
elem.style.display = "";
173-
}
174-
175-
// Set elements which have been overridden with display: none
176-
// in a stylesheet to whatever the default browser style is
177-
// for such an element
178-
if ( elem.style.display === "" && isHidden( elem ) ) {
179-
values[ index ] = dataPriv.access(
180-
elem,
181-
"olddisplay",
182-
defaultDisplay(elem.nodeName)
183-
);
184-
}
185-
} else {
186-
hidden = isHidden( elem );
187-
188-
if ( display !== "none" || !hidden ) {
189-
dataPriv.set(
190-
elem,
191-
"olddisplay",
192-
hidden ? display : jQuery.css( elem, "display" )
193-
);
194-
}
195-
}
196-
}
197-
198-
// Set the display of most of the elements in a second loop
199-
// to avoid the constant reflow
200-
for ( index = 0; index < length; index++ ) {
201-
elem = elements[ index ];
202-
if ( !elem.style ) {
203-
continue;
204-
}
205-
if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
206-
elem.style.display = show ? values[ index ] || "" : "none";
207-
}
208-
}
209-
210-
return elements;
211-
}
212-
213153
jQuery.extend({
214154

215155
// Add in style property hooks for overriding the default

src/css/defaultDisplay.js

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/css/showHide.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
define([
2+
"../data/var/dataPriv"
3+
], function( dataPriv ) {
4+
5+
function showHide( elements, show ) {
6+
var display, elem,
7+
values = [],
8+
index = 0,
9+
length = elements.length;
10+
11+
// Determine new display value for elements that need to change
12+
for ( ; index < length; index++ ) {
13+
elem = elements[ index ];
14+
if ( !elem.style ) {
15+
continue;
16+
}
17+
18+
display = elem.style.display;
19+
if ( show ) {
20+
if ( display === "none" ) {
21+
// Restore a pre-hide() value if we have one
22+
values[ index ] = dataPriv.get( elem, "display" ) || "";
23+
}
24+
} else {
25+
if ( display !== "none" ) {
26+
values[ index ] = "none";
27+
28+
// Remember the value we're replacing
29+
dataPriv.set( elem, "display", display );
30+
}
31+
}
32+
}
33+
34+
// Set the display of the elements in a second loop
35+
// to avoid the constant reflow
36+
for ( index = 0; index < length; index++ ) {
37+
if ( values[ index ] != null ) {
38+
elements[ index ].style.display = values[ index ];
39+
}
40+
}
41+
42+
return elements;
43+
}
44+
45+
return showHide;
46+
47+
});

0 commit comments

Comments
 (0)