@@ -267,8 +267,8 @@ angular.module('ngAnimate', ['ng'])
267
267
* |----------------------------------------------------------------------------------------------|-----------------------------------------------|
268
268
* | 1. $animate.enter(...) is called | class="my-animation" |
269
269
* | 2. element is inserted into the parent element or beside the after element | class="my-animation" |
270
- * | 3. the .ng-enter class is added to the element | class="my-animation ng-enter" |
271
- * | 4. $animate runs any JavaScript-defined animations on the element | class="my-animation ng-enter" |
270
+ * | 3. $animate runs any JavaScript-defined animations on the element | class="my-animation" |
271
+ * | 4. the .ng-enter class is added to the element | class="my-animation ng-enter" |
272
272
* | 5. $animate scans the element styles to get the CSS transition/animation duration and delay | class="my-animation ng-enter" |
273
273
* | 6. the .ng-enter-active class is added (this triggers the CSS transition/animation) | class="my-animation ng-enter ng-enter-active" |
274
274
* | 7. $animate waits for X milliseconds for the animation to complete | class="my-animation ng-enter ng-enter-active" |
@@ -302,8 +302,8 @@ angular.module('ngAnimate', ['ng'])
302
302
* | Animation Step | What the element class attribute looks like |
303
303
* |----------------------------------------------------------------------------------------------|----------------------------------------------|
304
304
* | 1. $animate.leave(...) is called | class="my-animation" |
305
- * | 2. the .ng-leave class is added to the element | class="my-animation ng-leave" |
306
- * | 3. $animate runs any JavaScript-defined animations on the element | class="my-animation ng-leave" |
305
+ * | 2. $animate runs any JavaScript-defined animations on the element | class="my-animation" |
306
+ * | 3. the .ng-leave class is added to the element | class="my-animation ng-leave" |
307
307
* | 4. $animate scans the element styles to get the CSS transition/animation duration and delay | class="my-animation ng-leave" |
308
308
* | 5. the .ng-leave-active class is added (this triggers the CSS transition/animation) | class="my-animation ng-leave ng-leave-active |
309
309
* | 6. $animate waits for X milliseconds for the animation to complete | class="my-animation ng-leave ng-leave-active |
@@ -337,8 +337,8 @@ angular.module('ngAnimate', ['ng'])
337
337
* |----------------------------------------------------------------------------------------------|---------------------------------------------|
338
338
* | 1. $animate.move(...) is called | class="my-animation" |
339
339
* | 2. element is moved into the parent element or beside the after element | class="my-animation" |
340
- * | 3. the .ng-move class is added to the element | class="my-animation ng-move" |
341
- * | 4. $animate runs any JavaScript-defined animations on the element | class="my-animation ng-move" |
340
+ * | 3. $animate runs any JavaScript-defined animations on the element | class="my-animation" |
341
+ * | 4. the .ng-move class is added to the element | class="my-animation ng-move" |
342
342
* | 5. $animate scans the element styles to get the CSS transition/animation duration and delay | class="my-animation ng-move" |
343
343
* | 6. the .ng-move-active class is added (this triggers the CSS transition/animation) | class="my-animation ng-move ng-move-active" |
344
344
* | 7. $animate waits for X milliseconds for the animation to complete | class="my-animation ng-move ng-move-active" |
@@ -373,8 +373,8 @@ angular.module('ngAnimate', ['ng'])
373
373
* | Animation Step | What the element class attribute looks like |
374
374
* |------------------------------------------------------------------------------------------------|---------------------------------------------|
375
375
* | 1. $animate.addClass(element, 'super') is called | class="" |
376
- * | 2. the .super-add class is added to the element | class="super-add" |
377
- * | 3. $animate runs any JavaScript-defined animations on the element | class="super-add" |
376
+ * | 2. $animate runs any JavaScript-defined animations on the element | class="" |
377
+ * | 3. the .super-add class is added to the element | class="super-add" |
378
378
* | 4. $animate scans the element styles to get the CSS transition/animation duration and delay | class="super-add" |
379
379
* | 5. the .super-add-active class is added (this triggers the CSS transition/animation) | class="super-add super-add-active" |
380
380
* | 6. $animate waits for X milliseconds for the animation to complete | class="super-add super-add-active" |
@@ -408,8 +408,8 @@ angular.module('ngAnimate', ['ng'])
408
408
* | Animation Step | What the element class attribute looks like |
409
409
* |-----------------------------------------------------------------------------------------------|-------------------------------------------------|
410
410
* | 1. $animate.removeClass(element, 'super') is called | class="super" |
411
- * | 2. the .super-remove class is added to the element | class="super super-remove" |
412
- * | 3. $animate runs any JavaScript-defined animations on the element | class="super super-remove" |
411
+ * | 2. $animate runs any JavaScript-defined animations on the element | class="super" |
412
+ * | 3. the .super-remove class is added to the element | class="super super-remove" |
413
413
* | 4. $animate scans the element styles to get the CSS transition/animation duration and delay | class="super super-remove" |
414
414
* | 5. the .super-remove-active class is added (this triggers the CSS transition/animation) | class="super super-remove super-remove-active" |
415
415
* | 6. $animate waits for X milliseconds for the animation to complete | class="super super-remove super-remove-active" |
@@ -494,23 +494,14 @@ angular.module('ngAnimate', ['ng'])
494
494
done :done
495
495
} ) ;
496
496
497
- var baseClassName = className ;
498
- if ( event == 'addClass' ) {
499
- className = suffixClasses ( className , '-add' ) ;
500
- } else if ( event == 'removeClass' ) {
501
- className = suffixClasses ( className , '-remove' ) ;
502
- }
503
-
504
- element . addClass ( className ) ;
505
-
506
497
forEach ( animations , function ( animation , index ) {
507
498
var fn = function ( ) {
508
499
progress ( index ) ;
509
500
} ;
510
501
511
502
if ( animation . start ) {
512
503
if ( event == 'addClass' || event == 'removeClass' ) {
513
- animation . endFn = animation . start ( element , baseClassName , fn ) ;
504
+ animation . endFn = animation . start ( element , className , fn ) ;
514
505
} else {
515
506
animation . endFn = animation . start ( element , fn ) ;
516
507
}
@@ -538,7 +529,6 @@ angular.module('ngAnimate', ['ng'])
538
529
function done ( ) {
539
530
if ( ! done . hasBeenRun ) {
540
531
done . hasBeenRun = true ;
541
- element . removeClass ( className ) ;
542
532
element . removeData ( NG_ANIMATE_STATE ) ;
543
533
( onComplete || noop ) ( ) ;
544
534
}
@@ -549,26 +539,45 @@ angular.module('ngAnimate', ['ng'])
549
539
$animateProvider . register ( '' , [ '$window' , '$sniffer' , '$timeout' , function ( $window , $sniffer , $timeout ) {
550
540
var noop = angular . noop ;
551
541
var forEach = angular . forEach ;
542
+
543
+ //one day all browsers will have these properties
544
+ var w3cAnimationProp = 'animation' ;
545
+ var w3cTransitionProp = 'transition' ;
546
+
547
+ //but some still use vendor-prefixed styles
548
+ var vendorAnimationProp = $sniffer . vendorPrefix + 'Animation' ;
549
+ var vendorTransitionProp = $sniffer . vendorPrefix + 'Transition' ;
550
+
551
+ var durationKey = 'Duration' ,
552
+ delayKey = 'Delay' ,
553
+ animationIterationCountKey = 'IterationCount' ,
554
+ ELEMENT_NODE = 1 ;
555
+
552
556
function animate ( element , className , done ) {
553
557
if ( ! ( $sniffer . transitions || $sniffer . animations ) ) {
554
558
done ( ) ;
555
559
return ;
556
560
}
561
+ else if ( [ 'ng-enter' , 'ng-leave' , 'ng-move' ] . indexOf ( className ) == - 1 ) {
562
+ var existingDuration = 0 ;
563
+ forEach ( element , function ( element ) {
564
+ if ( element . nodeType == ELEMENT_NODE ) {
565
+ var elementStyles = $window . getComputedStyle ( element ) || { } ;
566
+ existingDuration = Math . max ( parseMaxTime ( elementStyles [ w3cTransitionProp + durationKey ] ) ,
567
+ parseMaxTime ( elementStyles [ vendorTransitionProp + durationKey ] ) ,
568
+ existingDuration ) ;
569
+ }
570
+ } ) ;
571
+ if ( existingDuration > 0 ) {
572
+ done ( ) ;
573
+ return ;
574
+ }
575
+ }
557
576
558
- //one day all browsers will have these properties
559
- var w3cAnimationProp = 'animation' ;
560
- var w3cTransitionProp = 'transition' ;
561
-
562
- //but some still use vendor-prefixed styles
563
- var vendorAnimationProp = $sniffer . vendorPrefix + 'Animation' ;
564
- var vendorTransitionProp = $sniffer . vendorPrefix + 'Transition' ;
565
-
566
- var durationKey = 'Duration' ,
567
- delayKey = 'Delay' ,
568
- animationIterationCountKey = 'IterationCount' ;
577
+ element . addClass ( className ) ;
569
578
570
579
//we want all the styles defined before and after
571
- var duration = 0 , ELEMENT_NODE = 1 ;
580
+ var duration = 0 ;
572
581
forEach ( element , function ( element ) {
573
582
if ( element . nodeType == ELEMENT_NODE ) {
574
583
var elementStyles = $window . getComputedStyle ( element ) || { } ;
@@ -615,6 +624,7 @@ angular.module('ngAnimate', ['ng'])
615
624
//there is no need to attach this internally to the
616
625
//timeout done method
617
626
return function onEnd ( cancelled ) {
627
+ element . removeClass ( className ) ;
618
628
element . removeClass ( activeClassName ) ;
619
629
620
630
//only when the animation is cancelled is the done()
@@ -626,6 +636,7 @@ angular.module('ngAnimate', ['ng'])
626
636
}
627
637
}
628
638
else {
639
+ element . removeClass ( className ) ;
629
640
done ( ) ;
630
641
}
631
642
@@ -656,16 +667,15 @@ angular.module('ngAnimate', ['ng'])
656
667
}
657
668
} ;
658
669
670
+ function suffixClasses ( classes , suffix ) {
671
+ var className = '' ;
672
+ classes = angular . isArray ( classes ) ? classes : classes . split ( / \s + / ) ;
673
+ forEach ( classes , function ( klass , i ) {
674
+ if ( klass && klass . length > 0 ) {
675
+ className += ( i > 0 ? ' ' : '' ) + klass + suffix ;
676
+ }
677
+ } ) ;
678
+ return className ;
679
+ }
659
680
} ] ) ;
660
-
661
- function suffixClasses ( classes , suffix ) {
662
- var className = '' ;
663
- classes = angular . isArray ( classes ) ? classes : classes . split ( / \s + / ) ;
664
- forEach ( classes , function ( klass , i ) {
665
- if ( klass && klass . length > 0 ) {
666
- className += ( i > 0 ? ' ' : '' ) + klass + suffix ;
667
- }
668
- } ) ;
669
- return className ;
670
- }
671
681
} ] ) ;
0 commit comments