@@ -697,7 +697,7 @@ describe("ngAnimate", function() {
697
697
698
698
ss . addRule ( '.ani.ng-enter, .ani.ng-leave, .ani-fake.ng-enter, .ani-fake.ng-leave' ,
699
699
'-webkit-animation:1s my_animation;' +
700
- 'transition :1s my_animation;' ) ;
700
+ 'animation :1s my_animation;' ) ;
701
701
702
702
ss . addRule ( '.ani.ng-enter-stagger, .ani.ng-leave-stagger' ,
703
703
'-webkit-animation-delay:0.1s;' +
@@ -747,6 +747,40 @@ describe("ngAnimate", function() {
747
747
expect ( elements [ 3 ] . attr ( 'style' ) ) . not . toMatch ( / a n i m a t i o n - d e l a y : 0 \. 3 \d * s / ) ;
748
748
expect ( elements [ 4 ] . attr ( 'style' ) ) . not . toMatch ( / a n i m a t i o n - d e l a y : 0 \. 4 \d * s / ) ;
749
749
} ) ) ;
750
+
751
+ it ( "should stagger items when multiple animation durations/delays are defined" ,
752
+ inject ( function ( $animate , $rootScope , $compile , $sniffer , $timeout , $document , $rootElement ) {
753
+
754
+ if ( ! $sniffer . transitions ) return ;
755
+
756
+ $animate . enabled ( true ) ;
757
+
758
+ ss . addRule ( '.ani.ng-enter, .ani.ng-leave' ,
759
+ '-webkit-animation:my_animation 1s 1s, your_animation 1s 2s;' +
760
+ 'animation:my_animation 1s 1s, your_animation 1s 2s;' ) ;
761
+
762
+ ss . addRule ( '.ani.ng-enter-stagger, .ani.ng-leave-stagger' ,
763
+ '-webkit-animation-delay:0.1s;' +
764
+ 'animation-delay:0.1s;' ) ;
765
+
766
+ var container = $compile ( html ( '<div></div>' ) ) ( $rootScope ) ;
767
+
768
+ var elements = [ ] ;
769
+ for ( var i = 0 ; i < 4 ; i ++ ) {
770
+ var newScope = $rootScope . $new ( ) ;
771
+ var element = $compile ( '<div class="ani"></div>' ) ( newScope ) ;
772
+ $animate . enter ( element , container ) ;
773
+ elements . push ( element ) ;
774
+ } ;
775
+
776
+ $rootScope . $digest ( ) ;
777
+ $timeout . flush ( ) ;
778
+
779
+ expect ( elements [ 0 ] . attr ( 'style' ) ) . toBeFalsy ( ) ;
780
+ expect ( elements [ 1 ] . attr ( 'style' ) ) . toMatch ( / a n i m a t i o n - d e l a y : 1 \. 1 \d * s , \s * 2 \. 1 \d * s / ) ;
781
+ expect ( elements [ 2 ] . attr ( 'style' ) ) . toMatch ( / a n i m a t i o n - d e l a y : 1 \. 2 \d * s , \s * 2 \. 2 \d * s / ) ;
782
+ expect ( elements [ 3 ] . attr ( 'style' ) ) . toMatch ( / a n i m a t i o n - d e l a y : 1 \. 3 \d * s , \s * 2 \. 3 \d * s / ) ;
783
+ } ) ) ;
750
784
} ) ;
751
785
752
786
describe ( "Transitions" , function ( ) {
@@ -950,7 +984,87 @@ describe("ngAnimate", function() {
950
984
expect ( elements [ 3 ] . attr ( 'style' ) ) . not . toMatch ( / t r a n s i t i o n - d e l a y : 0 \. 3 \d * s / ) ;
951
985
expect ( elements [ 4 ] . attr ( 'style' ) ) . not . toMatch ( / t r a n s i t i o n - d e l a y : 0 \. 4 \d * s / ) ;
952
986
} ) ) ;
987
+
988
+ it ( "should stagger items when multiple transition durations/delays are defined" ,
989
+ inject ( function ( $animate , $rootScope , $compile , $sniffer , $timeout , $document , $rootElement ) {
990
+
991
+ if ( ! $sniffer . transitions ) return ;
992
+
993
+ $animate . enabled ( true ) ;
994
+
995
+ ss . addRule ( '.ani.ng-enter, .ani.ng-leave' ,
996
+ '-webkit-transition:1s linear color 2s, 3s linear font-size 4s;' +
997
+ 'transition:1s linear color 2s, 3s linear font-size 4s;' ) ;
998
+
999
+ ss . addRule ( '.ani.ng-enter-stagger, .ani.ng-leave-stagger' ,
1000
+ '-webkit-transition-delay:0.1s;' +
1001
+ 'transition-delay:0.1s;' ) ;
1002
+
1003
+ var container = $compile ( html ( '<div></div>' ) ) ( $rootScope ) ;
1004
+
1005
+ var elements = [ ] ;
1006
+ for ( var i = 0 ; i < 4 ; i ++ ) {
1007
+ var newScope = $rootScope . $new ( ) ;
1008
+ var element = $compile ( '<div class="ani"></div>' ) ( newScope ) ;
1009
+ $animate . enter ( element , container ) ;
1010
+ elements . push ( element ) ;
1011
+ } ;
1012
+
1013
+ $rootScope . $digest ( ) ;
1014
+ $timeout . flush ( ) ;
1015
+
1016
+ expect ( elements [ 0 ] . attr ( 'style' ) ) . toBeFalsy ( ) ;
1017
+ expect ( elements [ 1 ] . attr ( 'style' ) ) . toMatch ( / t r a n s i t i o n - d e l a y : 2 \. 1 \d * s , \s * 4 \. 1 \d * s / ) ;
1018
+ expect ( elements [ 2 ] . attr ( 'style' ) ) . toMatch ( / t r a n s i t i o n - d e l a y : 2 \. 2 \d * s , \s * 4 \. 2 \d * s / ) ;
1019
+ expect ( elements [ 3 ] . attr ( 'style' ) ) . toMatch ( / t r a n s i t i o n - d e l a y : 2 \. 3 \d * s , \s * 4 \. 3 \d * s / ) ;
1020
+ } ) ) ;
953
1021
} ) ;
1022
+
1023
+ it ( "should apply staggering to both transitions and keyframe animations when used within the same animation" ,
1024
+ inject ( function ( $animate , $rootScope , $compile , $sniffer , $timeout , $document , $rootElement ) {
1025
+
1026
+ if ( ! $sniffer . transitions ) return ;
1027
+
1028
+ $animate . enabled ( true ) ;
1029
+
1030
+ ss . addRule ( '.ani.ng-enter, .ani.ng-leave' ,
1031
+ '-webkit-animation:my_animation 1s 1s, your_animation 1s 2s;' +
1032
+ 'animation:my_animation 1s 1s, your_animation 1s 2s;' +
1033
+ '-webkit-transition:1s linear all 0s;' +
1034
+ 'transition:1s linear all 1s;' ) ;
1035
+
1036
+ ss . addRule ( '.ani.ng-enter-stagger, .ani.ng-leave-stagger' ,
1037
+ '-webkit-transition-delay:0.1s;' +
1038
+ 'transition-delay:0.1s;' +
1039
+ '-webkit-animation-delay:0.2s;' +
1040
+ 'animation-delay:0.2s;' ) ;
1041
+
1042
+ var container = $compile ( html ( '<div></div>' ) ) ( $rootScope ) ;
1043
+
1044
+ var elements = [ ] ;
1045
+ for ( var i = 0 ; i < 3 ; i ++ ) {
1046
+ var newScope = $rootScope . $new ( ) ;
1047
+ var element = $compile ( '<div class="ani"></div>' ) ( newScope ) ;
1048
+ $animate . enter ( element , container ) ;
1049
+ elements . push ( element ) ;
1050
+ } ;
1051
+
1052
+ $rootScope . $digest ( ) ;
1053
+ $timeout . flush ( ) ;
1054
+
1055
+ expect ( elements [ 0 ] . attr ( 'style' ) ) . toBeFalsy ( ) ;
1056
+
1057
+ expect ( elements [ 1 ] . attr ( 'style' ) ) . toMatch ( / t r a n s i t i o n - d e l a y : \s + 1 .1 \d * / ) ;
1058
+ expect ( elements [ 1 ] . attr ( 'style' ) ) . toMatch ( / a n i m a t i o n - d e l a y : 1 \. 2 \d * s , \s * 2 \. 2 \d * s / ) ;
1059
+
1060
+ expect ( elements [ 2 ] . attr ( 'style' ) ) . toMatch ( / t r a n s i t i o n - d e l a y : \s + 1 .2 \d * / ) ;
1061
+ expect ( elements [ 2 ] . attr ( 'style' ) ) . toMatch ( / a n i m a t i o n - d e l a y : 1 \. 4 \d * s , \s * 2 \. 4 \d * s / ) ;
1062
+
1063
+ for ( var i = 0 ; i < 3 ; i ++ ) {
1064
+ browserTrigger ( elements [ i ] , 'transitionend' , { timeStamp : Date . now ( ) + 22000 , elapsedTime : 22000 } ) ;
1065
+ expect ( elements [ i ] . attr ( 'style' ) ) . toBeFalsy ( ) ;
1066
+ }
1067
+ } ) ) ;
954
1068
} ) ;
955
1069
956
1070
describe ( 'animation evaluation' , function ( ) {
0 commit comments