Skip to content

Commit 351092f

Browse files
committed
Effects: Use showHide directly
1 parent 222b90d commit 351092f

File tree

3 files changed

+54
-46
lines changed

3 files changed

+54
-46
lines changed

src/css.js

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ define([
1212
"./css/adjustCSS",
1313
"./css/addGetHookIf",
1414
"./css/support",
15-
"./data/var/dataPriv",
15+
"./css/showHide",
1616

1717
"./core/init",
1818
"./css/swap",
1919
"./core/ready",
2020
"./selector" // contains
2121
], function( jQuery, pnum, access, rmargin, rcssNum, rnumnonpx, cssExpand, isHidden,
22-
getStyles, curCSS, adjustCSS, addGetHookIf, support, dataPriv ) {
22+
getStyles, curCSS, adjustCSS, addGetHookIf, support, showHide ) {
2323

2424
var
2525
// Swappable if display is none or starts with table
@@ -150,46 +150,6 @@ function getWidthOrHeight( elem, name, extra ) {
150150
) + "px";
151151
}
152152

153-
function showHide( elements, show ) {
154-
var display, elem,
155-
values = [],
156-
index = 0,
157-
length = elements.length;
158-
159-
// Determine new display value for elements that need to change
160-
for ( ; index < length; index++ ) {
161-
elem = elements[ index ];
162-
if ( !elem.style ) {
163-
continue;
164-
}
165-
166-
display = elem.style.display;
167-
if ( show ) {
168-
if ( display === "none" ) {
169-
// Restore a pre-hide() value if we have one
170-
values[ index ] = dataPriv.get( elem, "olddisplay" ) || "";
171-
}
172-
} else {
173-
if ( display !== "none" ) {
174-
values[ index ] = "none";
175-
176-
// Remember the value we're replacing
177-
dataPriv.set( elem, "olddisplay", display );
178-
}
179-
}
180-
}
181-
182-
// Set the display of the elements in a second loop
183-
// to avoid the constant reflow
184-
for ( index = 0; index < length; index++ ) {
185-
if ( values[ index ] != null ) {
186-
elements[ index ].style.display = values[ index ];
187-
}
188-
}
189-
190-
return elements;
191-
}
192-
193153
jQuery.extend({
194154

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

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, "olddisplay" ) || "";
23+
}
24+
} else {
25+
if ( display !== "none" ) {
26+
values[ index ] = "none";
27+
28+
// Remember the value we're replacing
29+
dataPriv.set( elem, "olddisplay", 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+
});

src/effects.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ define([
66
"./css/var/isHidden",
77
"./css/adjustCSS",
88
"./data/var/dataPriv",
9+
"./css/showHide",
910

1011
"./core/init",
1112
"./queue",
@@ -14,7 +15,7 @@ define([
1415
"./manipulation",
1516
"./css",
1617
"./effects/Tween"
17-
], function( jQuery, document, rcssNum, cssExpand, isHidden, adjustCSS, dataPriv ) {
18+
], function( jQuery, document, rcssNum, cssExpand, isHidden, adjustCSS, dataPriv, showHide ) {
1819

1920
var
2021
fxNow, timerId,
@@ -117,7 +118,7 @@ function defaultPrefilter( elem, props, opts ) {
117118
// Detect show/hide animations
118119
for ( prop in props ) {
119120
value = props[ prop ];
120-
if ( rfxtypes.exec( value ) ) {
121+
if ( rfxtypes.test( value ) ) {
121122
delete props[ prop ];
122123
toggle = toggle || value === "toggle";
123124
if ( value === ( hidden ? "hide" : "show" ) ) {
@@ -210,14 +211,14 @@ function defaultPrefilter( elem, props, opts ) {
210211

211212
// Show elements before animating them
212213
if ( hidden ) {
213-
jQuery( elem ).show();
214+
showHide( [ elem ], true );
214215
}
215216

216217
/* jshint -W083 */
217218
anim.done(function() {
218219
// The final step of a "hide" animation is actually hiding the element
219220
if ( !hidden ) {
220-
jQuery( elem ).hide();
221+
showHide( [ elem ] );
221222
}
222223
dataPriv.remove( elem, "fxshow" );
223224
for ( prop in orig ) {

0 commit comments

Comments
 (0)