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
1920var
2021 fxNow , timerId ,
@@ -81,8 +82,8 @@ function createTween( value, prop, animation ) {
8182
8283function defaultPrefilter ( elem , props , opts ) {
8384 /* jshint validthis: true */
84- var prop , value , toggle , tween , hooks , oldfire , display , restoreDisplay ,
85- isBox = "height " in props || "width " in props ,
85+ var prop , value , toggle , hooks , oldfire , propTween , restoreDisplay , display ,
86+ isBox = "width " in props || "height " in props ,
8687 anim = this ,
8788 orig = { } ,
8889 style = elem . style ,
@@ -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" ) ) {
@@ -136,7 +137,13 @@ function defaultPrefilter( elem, props, opts ) {
136137 }
137138 }
138139
139- // Temporarily restrict "overflow" and "display" styles during box animations
140+ // Bail out if this is a no-op like .hide().hide()
141+ propTween = ! jQuery . isEmptyObject ( props ) ;
142+ if ( ! propTween && jQuery . isEmptyObject ( orig ) ) {
143+ return ;
144+ }
145+
146+ // Restrict "overflow" and "display" styles during box animations
140147 if ( isBox && elem . nodeType === 1 ) {
141148 // Support: IE 9 - 11
142149 // Record all 3 overflow attributes because IE does not infer the shorthand
@@ -158,20 +165,18 @@ function defaultPrefilter( elem, props, opts ) {
158165 // Animate inline elements as inline-block
159166 if ( display === "inline" || display === "inline-block" && restoreDisplay != null ) {
160167 if ( jQuery . css ( elem , "float" ) === "none" ) {
161- if ( ! jQuery . isEmptyObject ( props ) ) {
162- style . display = "inline-block" ;
163168
164169 // Restore the original display value at the end of pure show/hide animations
165- } else if ( ! jQuery . isEmptyObject ( orig ) ) {
170+ if ( ! propTween ) {
171+ anim . done ( function ( ) {
172+ style . display = restoreDisplay ;
173+ } ) ;
166174 if ( restoreDisplay == null ) {
167175 display = style . display ;
168176 restoreDisplay = display === "none" ? "" : display ;
169177 }
170- style . display = "inline-block" ;
171- anim . done ( function ( ) {
172- style . display = restoreDisplay ;
173- } ) ;
174178 }
179+ style . display = "inline-block" ;
175180 }
176181 }
177182 }
@@ -186,43 +191,49 @@ function defaultPrefilter( elem, props, opts ) {
186191 }
187192
188193 // Implement show/hide animations
189- if ( ! jQuery . isEmptyObject ( orig ) ) {
190- if ( dataShow ) {
191- if ( "hidden" in dataShow ) {
192- hidden = dataShow . hidden ;
194+ propTween = false ;
195+ for ( prop in orig ) {
196+
197+ // General show/hide setup for this element animation
198+ if ( ! propTween ) {
199+ if ( dataShow ) {
200+ if ( "hidden" in dataShow ) {
201+ hidden = dataShow . hidden ;
202+ }
203+ } else {
204+ dataShow = dataPriv . access ( elem , "fxshow" , { display : restoreDisplay } ) ;
193205 }
194- } else {
195- dataShow = dataPriv . access ( elem , "fxshow" , { display : restoreDisplay } ) ;
196- }
197206
198- // Store hidden/visible for toggle so `.stop().toggle()` "reverses"
199- if ( toggle ) {
200- dataShow . hidden = ! hidden ;
201- }
202-
203- if ( hidden ) {
204- jQuery ( elem ) . show ( ) ;
205- }
206-
207- anim . done ( function ( ) {
208- if ( ! hidden ) {
209- jQuery ( elem ) . hide ( ) ;
210- }
211- dataPriv . remove ( elem , "fxshow" ) ;
212- for ( prop in orig ) {
213- jQuery . style ( elem , prop , orig [ prop ] ) ;
207+ // Store hidden/visible for toggle so `.stop().toggle()` "reverses"
208+ if ( toggle ) {
209+ dataShow . hidden = ! hidden ;
214210 }
215- } ) ;
216211
217- for ( prop in orig ) {
218- tween = createTween ( hidden ? dataShow [ prop ] : 0 , prop , anim ) ;
212+ // Show elements before animating them
213+ if ( hidden ) {
214+ showHide ( [ elem ] , true ) ;
215+ }
219216
220- if ( ! ( prop in dataShow ) ) {
221- dataShow [ prop ] = tween . start ;
222- if ( hidden ) {
223- tween . end = tween . start ;
224- tween . start = prop === "width" || prop === "height" ? 1 : 0 ;
217+ /* jshint -W083 */
218+ anim . done ( function ( ) {
219+ // The final step of a "hide" animation is actually hiding the element
220+ if ( ! hidden ) {
221+ showHide ( [ elem ] ) ;
222+ }
223+ dataPriv . remove ( elem , "fxshow" ) ;
224+ for ( prop in orig ) {
225+ jQuery . style ( elem , prop , orig [ prop ] ) ;
225226 }
227+ } ) ;
228+ }
229+
230+ // Per-property setup
231+ propTween = createTween ( hidden ? dataShow [ prop ] : 0 , prop , anim ) ;
232+ if ( ! ( prop in dataShow ) ) {
233+ dataShow [ prop ] = propTween . start ;
234+ if ( hidden ) {
235+ propTween . end = propTween . start ;
236+ propTween . start = prop === "width" || prop === "height" ? 1 : 0 ;
226237 }
227238 }
228239 }
0 commit comments