@@ -141,7 +141,8 @@ jQuery.fn.extend({
141
141
isElement = this . nodeType === 1 ,
142
142
hidden = isElement && jQuery ( this ) . is ( ":hidden" ) ,
143
143
name , val , p , e ,
144
- parts , start , end , unit ;
144
+ parts , start , end , unit ,
145
+ method ;
145
146
146
147
// will store per property easing and be used to determine when an animation is complete
147
148
opt . animatedProperties = { } ;
@@ -203,7 +204,15 @@ jQuery.fn.extend({
203
204
val = prop [ p ] ;
204
205
205
206
if ( rfxtypes . test ( val ) ) {
206
- e [ val === "toggle" ? hidden ? "show" : "hide" : val ] ( ) ;
207
+ // Tracks whether to show or hide based on private
208
+ // data attached to the element
209
+ method = jQuery . _data ( this , "toggle" + p ) || ( val === "toggle" ? hidden ? "show" : "hide" : 0 ) ;
210
+ if ( method ) {
211
+ jQuery . _data ( this , "toggle" + p , method === "show" ? "hide" : "show" ) ;
212
+ e [ method ] ( ) ;
213
+ } else {
214
+ e [ val ] ( ) ;
215
+ }
207
216
208
217
} else {
209
218
parts = rfxnum . exec ( val ) ;
@@ -246,6 +255,7 @@ jQuery.fn.extend({
246
255
this . each ( function ( ) {
247
256
var timers = jQuery . timers ,
248
257
i = timers . length ;
258
+
249
259
// clear marker counters if we know they won't be
250
260
if ( ! gotoEnd ) {
251
261
jQuery . _unmark ( true , this ) ;
@@ -255,6 +265,8 @@ jQuery.fn.extend({
255
265
if ( gotoEnd ) {
256
266
// force the next step to be the last
257
267
timers [ i ] ( true ) ;
268
+ } else {
269
+ timers [ i ] . saveState ( ) ;
258
270
}
259
271
260
272
timers . splice ( i , 1 ) ;
@@ -398,6 +410,11 @@ jQuery.fx.prototype = {
398
410
}
399
411
400
412
t . elem = this . elem ;
413
+ t . saveState = function ( ) {
414
+ if ( self . options . hide && jQuery . _data ( self . elem , "fxshow" + self . prop ) === undefined ) {
415
+ jQuery . _data ( self . elem , "fxshow" + self . prop , self . start ) ;
416
+ }
417
+ } ;
401
418
402
419
if ( t ( ) && jQuery . timers . push ( t ) && ! timerId ) {
403
420
// Use requestAnimationFrame instead of setInterval if available
@@ -419,14 +436,20 @@ jQuery.fx.prototype = {
419
436
420
437
// Simple 'show' function
421
438
show : function ( ) {
439
+ var dataShow = jQuery . _data ( this . elem , "fxshow" + this . prop ) ;
440
+
422
441
// Remember where we started, so that we can go back to it later
423
- this . options . orig [ this . prop ] = jQuery . style ( this . elem , this . prop ) ;
442
+ this . options . orig [ this . prop ] = dataShow || jQuery . style ( this . elem , this . prop ) ;
424
443
this . options . show = true ;
425
444
426
445
// Begin the animation
427
- // Make sure that we start at a small width/height to avoid any
428
- // flash of content
429
- this . custom ( this . prop === "width" || this . prop === "height" ? 1 : 0 , this . cur ( ) ) ;
446
+ // Make sure that we start at a small width/height to avoid any flash of content
447
+ if ( dataShow !== undefined ) {
448
+ // This show is picking up where a previous hide or show left off
449
+ this . custom ( this . cur ( ) , dataShow ) ;
450
+ } else {
451
+ this . custom ( this . prop === "width" || this . prop === "height" ? 1 : 0 , this . cur ( ) ) ;
452
+ }
430
453
431
454
// Start by showing the element
432
455
jQuery ( this . elem ) . show ( ) ;
@@ -435,7 +458,7 @@ jQuery.fx.prototype = {
435
458
// Simple 'hide' function
436
459
hide : function ( ) {
437
460
// Remember where we started, so that we can go back to it later
438
- this . options . orig [ this . prop ] = jQuery . style ( this . elem , this . prop ) ;
461
+ this . options . orig [ this . prop ] = jQuery . _data ( this . elem , "fxshow" + this . prop ) || jQuery . style ( this . elem , this . prop ) ;
439
462
this . options . hide = true ;
440
463
441
464
// Begin the animation
@@ -448,7 +471,7 @@ jQuery.fx.prototype = {
448
471
done = true ,
449
472
elem = this . elem ,
450
473
options = this . options ,
451
- i , n ;
474
+ p , n ;
452
475
453
476
if ( gotoEnd || t >= options . duration + this . startTime ) {
454
477
this . now = this . end ;
@@ -457,8 +480,8 @@ jQuery.fx.prototype = {
457
480
458
481
options . animatedProperties [ this . prop ] = true ;
459
482
460
- for ( i in options . animatedProperties ) {
461
- if ( options . animatedProperties [ i ] !== true ) {
483
+ for ( p in options . animatedProperties ) {
484
+ if ( options . animatedProperties [ p ] !== true ) {
462
485
done = false ;
463
486
}
464
487
}
@@ -479,8 +502,11 @@ jQuery.fx.prototype = {
479
502
480
503
// Reset the properties, if the item has been hidden or shown
481
504
if ( options . hide || options . show ) {
482
- for ( var p in options . animatedProperties ) {
483
- jQuery . style ( elem , p , options . orig [ p ] ) ;
505
+ for ( p in options . animatedProperties ) {
506
+ jQuery . style ( elem , p , options . orig [ p ] ) ;
507
+ jQuery . removeData ( elem , "fxshow" + p , true ) ;
508
+ // Toggle data is no longer needed
509
+ jQuery . removeData ( elem , "toggle" + p , true ) ;
484
510
}
485
511
}
486
512
@@ -512,7 +538,7 @@ jQuery.fx.prototype = {
512
538
513
539
jQuery . extend ( jQuery . fx , {
514
540
tick : function ( ) {
515
- for ( var timers = jQuery . timers , i = 0 ; i < timers . length ; ++ i ) {
541
+ for ( var timers = jQuery . timers , i = 0 ; i < timers . length ; i ++ ) {
516
542
if ( ! timers [ i ] ( ) ) {
517
543
timers . splice ( i -- , 1 ) ;
518
544
}
0 commit comments