@@ -12,6 +12,13 @@ describe("ngAnimate $animateCss", function() {
12
12
: expect ( className ) . not . toMatch ( regex ) ;
13
13
}
14
14
15
+ function getPossiblyPrefixedStyleValue ( element , styleProp ) {
16
+ var value = element . css ( prefix + styleProp ) ;
17
+ if ( isUndefined ( value ) ) value = element . css ( styleProp ) ;
18
+
19
+ return value ;
20
+ }
21
+
15
22
function keyframeProgress ( element , duration , delay ) {
16
23
browserTrigger ( element , 'animationend' ,
17
24
{ timeStamp : Date . now ( ) + ( ( delay || 1 ) * 1000 ) , elapsedTime : duration } ) ;
@@ -31,6 +38,16 @@ describe("ngAnimate $animateCss", function() {
31
38
return function ( $document , $sniffer , $$rAF , $animate ) {
32
39
prefix = '-' + $sniffer . vendorPrefix . toLowerCase ( ) + '-' ;
33
40
ss = createMockStyleSheet ( $document ) ;
41
+ ss . addPossiblyPrefixedRule = function ( selector , styles ) {
42
+ var prefixedStyles = styles . split ( / \s * ; \s * / g) . map ( function ( style ) {
43
+ return ! style ? '' : prefix + style ;
44
+ } ) . join ( '; ' ) ;
45
+
46
+ ss . addRule ( selector , styles ) ;
47
+ ss . addRule ( selector , prefixedStyles ) ;
48
+ } ;
49
+
50
+
34
51
$animate . enabled ( true ) ;
35
52
triggerAnimationStartFrame = function ( ) {
36
53
$$rAF . flush ( ) ;
@@ -325,7 +342,7 @@ describe("ngAnimate $animateCss", function() {
325
342
triggerAnimationStartFrame ( ) ;
326
343
327
344
runner . pause ( ) ;
328
- expect ( element . css ( prefix + 'animation-play-state' ) ) . toEqual ( 'paused' ) ;
345
+ expect ( getPossiblyPrefixedStyleValue ( element , 'animation-play-state' ) ) . toEqual ( 'paused' ) ;
329
346
runner . resume ( ) ;
330
347
expect ( element . attr ( 'style' ) ) . toBeFalsy ( ) ;
331
348
} ) ) ;
@@ -346,7 +363,7 @@ describe("ngAnimate $animateCss", function() {
346
363
triggerAnimationStartFrame ( ) ;
347
364
348
365
runner . pause ( ) ;
349
- expect ( element . css ( prefix + 'animation-play-state' ) ) . toEqual ( 'paused' ) ;
366
+ expect ( getPossiblyPrefixedStyleValue ( element , 'animation-play-state' ) ) . toEqual ( 'paused' ) ;
350
367
runner . end ( ) ;
351
368
expect ( element . attr ( 'style' ) ) . toBeFalsy ( ) ;
352
369
} ) ) ;
@@ -784,8 +801,8 @@ describe("ngAnimate $animateCss", function() {
784
801
785
802
jqLite ( $document [ 0 ] . body ) . append ( $rootElement ) ;
786
803
787
- ss . addRule ( '.ng-enter-stagger' , prefix + 'animation-delay:0.2s' ) ;
788
- ss . addRule ( '.ng-enter' , prefix + 'animation:my_animation 2s;' ) ;
804
+ ss . addPossiblyPrefixedRule ( '.ng-enter-stagger' , 'animation-delay:0.2s' ) ;
805
+ ss . addPossiblyPrefixedRule ( '.ng-enter' , 'animation:my_animation 2s;' ) ;
789
806
790
807
var i , element , elements = [ ] ;
791
808
for ( i = 0 ; i < 5 ; i ++ ) {
@@ -803,7 +820,7 @@ describe("ngAnimate $animateCss", function() {
803
820
if ( i === 0 ) { // the first element is always run right away
804
821
expect ( element . attr ( 'style' ) ) . toBeFalsy ( ) ;
805
822
} else {
806
- expect ( element . css ( prefix + 'animation-play-state' ) ) . toBe ( 'paused' ) ;
823
+ expect ( getPossiblyPrefixedStyleValue ( element , 'animation-play-state' ) ) . toBe ( 'paused' ) ;
807
824
}
808
825
}
809
826
} ) ) ;
@@ -879,7 +896,7 @@ describe("ngAnimate $animateCss", function() {
879
896
jqLite ( $document [ 0 ] . body ) . append ( $rootElement ) ;
880
897
881
898
ss . addRule ( '.ng-enter-stagger' , 'transition-delay:0.2s' ) ;
882
- ss . addRule ( '.transition-animation' , prefix + 'animation:2s 5s my_animation;' ) ;
899
+ ss . addPossiblyPrefixedRule ( '.transition-animation' , 'animation: 2s 5s my_animation;' ) ;
883
900
884
901
for ( var i = 0 ; i < 5 ; i ++ ) {
885
902
var elm = jqLite ( '<div class="transition-animation"></div>' ) ;
@@ -898,11 +915,11 @@ describe("ngAnimate $animateCss", function() {
898
915
899
916
jqLite ( $document [ 0 ] . body ) . append ( $rootElement ) ;
900
917
901
- ss . addRule ( '.ng-enter-stagger' , 'transition-delay:0.5s;' +
902
- prefix + 'animation-delay:1s' ) ;
918
+ ss . addPossiblyPrefixedRule ( '.ng-enter-stagger' , 'transition-delay: 0.5s; ' +
919
+ 'animation-delay: 1s' ) ;
903
920
904
- ss . addRule ( '.ng-enter' , 'transition:10s linear all;' +
905
- prefix + 'animation:my_animation 20s' ) ;
921
+ ss . addPossiblyPrefixedRule ( '.ng-enter' , 'transition: 10s linear all; ' +
922
+ 'animation: 20s my_animation ' ) ;
906
923
907
924
var i , elm , elements = [ ] ;
908
925
for ( i = 0 ; i < 5 ; i ++ ) {
@@ -1258,14 +1275,14 @@ describe("ngAnimate $animateCss", function() {
1258
1275
// At this point, the animation should still be running (closing timeout is 7500ms ... duration * 1.5 + delay => 7.5)
1259
1276
$timeout . flush ( 7000 ) ;
1260
1277
1261
- expect ( element . css ( prefix + 'transition-delay' ) ) . toBe ( '3s' ) ;
1262
- expect ( element . css ( prefix + 'transition-duration' ) ) . toBe ( '3s' ) ;
1278
+ expect ( getPossiblyPrefixedStyleValue ( element , 'transition-delay' ) ) . toBe ( '3s' ) ;
1279
+ expect ( getPossiblyPrefixedStyleValue ( element , 'transition-duration' ) ) . toBe ( '3s' ) ;
1263
1280
1264
1281
// Let's flush the remaining amount of time for the timeout timer to kick in
1265
1282
$timeout . flush ( 500 ) ;
1266
1283
1267
- expect ( element . css ( prefix + 'transition-duration' ) ) . toBeOneOf ( '' , '0s' ) ;
1268
- expect ( element . css ( prefix + 'transition-delay' ) ) . toBeOneOf ( '' , '0s' ) ;
1284
+ expect ( getPossiblyPrefixedStyleValue ( element , 'transition-duration' ) ) . toBeOneOf ( '' , '0s' ) ;
1285
+ expect ( getPossiblyPrefixedStyleValue ( element , 'transition-delay' ) ) . toBeOneOf ( '' , '0s' ) ;
1269
1286
} ) ) ;
1270
1287
1271
1288
it ( "should ignore a boolean options.delay value for the closing timeout" ,
@@ -1291,14 +1308,14 @@ describe("ngAnimate $animateCss", function() {
1291
1308
// At this point, the animation should still be running (closing timeout is 4500ms ... duration * 1.5 => 4.5)
1292
1309
$timeout . flush ( 4000 ) ;
1293
1310
1294
- expect ( element . css ( prefix + 'transition-delay' ) ) . toBeOneOf ( 'initial' , '0s' ) ;
1295
- expect ( element . css ( prefix + 'transition-duration' ) ) . toBe ( '3s' ) ;
1311
+ expect ( getPossiblyPrefixedStyleValue ( element , 'transition-delay' ) ) . toBeOneOf ( 'initial' , '0s' ) ;
1312
+ expect ( getPossiblyPrefixedStyleValue ( element , 'transition-duration' ) ) . toBe ( '3s' ) ;
1296
1313
1297
1314
// Let's flush the remaining amount of time for the timeout timer to kick in
1298
1315
$timeout . flush ( 500 ) ;
1299
1316
1300
- expect ( element . css ( prefix + 'transition-duration' ) ) . toBeOneOf ( '' , '0s' ) ;
1301
- expect ( element . css ( prefix + 'transition-delay' ) ) . toBeOneOf ( '' , '0s' ) ;
1317
+ expect ( getPossiblyPrefixedStyleValue ( element , 'transition-duration' ) ) . toBeOneOf ( '' , '0s' ) ;
1318
+ expect ( getPossiblyPrefixedStyleValue ( element , 'transition-delay' ) ) . toBeOneOf ( '' , '0s' ) ;
1302
1319
} ) ) ;
1303
1320
1304
1321
} ) ;
@@ -2104,7 +2121,7 @@ describe("ngAnimate $animateCss", function() {
2104
2121
triggerAnimationStartFrame ( ) ;
2105
2122
2106
2123
2107
- expect ( element . css ( prefix + 'animation-duration' ) ) . toEqual ( '5s' ) ;
2124
+ expect ( getPossiblyPrefixedStyleValue ( element , 'animation-duration' ) ) . toEqual ( '5s' ) ;
2108
2125
} ) ) ;
2109
2126
2110
2127
it ( "should remove all inline keyframe styling when an animation completes if a custom duration was applied" ,
@@ -2145,7 +2162,7 @@ describe("ngAnimate $animateCss", function() {
2145
2162
triggerAnimationStartFrame ( ) ;
2146
2163
2147
2164
2148
- expect ( element . css ( prefix + 'animation-delay' ) ) . toEqual ( '5s' ) ;
2165
+ expect ( getPossiblyPrefixedStyleValue ( element , 'animation-delay' ) ) . toEqual ( '5s' ) ;
2149
2166
2150
2167
browserTrigger ( element , 'animationend' ,
2151
2168
{ timeStamp : Date . now ( ) + 5000 , elapsedTime : 1.5 } ) ;
@@ -2299,7 +2316,7 @@ describe("ngAnimate $animateCss", function() {
2299
2316
triggerAnimationStartFrame ( ) ;
2300
2317
2301
2318
2302
- expect ( element . css ( prefix + 'animation-delay' ) ) . toEqual ( '400s' ) ;
2319
+ expect ( getPossiblyPrefixedStyleValue ( element , 'animation-delay' ) ) . toEqual ( '400s' ) ;
2303
2320
expect ( element . attr ( 'style' ) ) . not . toContain ( 'transition-delay' ) ;
2304
2321
} ) ) ;
2305
2322
@@ -2323,7 +2340,7 @@ describe("ngAnimate $animateCss", function() {
2323
2340
triggerAnimationStartFrame ( ) ;
2324
2341
2325
2342
2326
- expect ( element . css ( prefix + 'animation-delay' ) ) . toEqual ( '10s' ) ;
2343
+ expect ( getPossiblyPrefixedStyleValue ( element , 'animation-delay' ) ) . toEqual ( '10s' ) ;
2327
2344
expect ( element . css ( 'transition-delay' ) ) . toEqual ( '10s' ) ;
2328
2345
} ) ) ;
2329
2346
@@ -2363,7 +2380,7 @@ describe("ngAnimate $animateCss", function() {
2363
2380
var assertionsRun = false ;
2364
2381
classSpy = function ( ) {
2365
2382
assertionsRun = true ;
2366
- expect ( element . css ( prefix + 'animation-delay' ) ) . toEqual ( '2s' ) ;
2383
+ expect ( getPossiblyPrefixedStyleValue ( element , 'animation-delay' ) ) . toEqual ( '2s' ) ;
2367
2384
expect ( element . css ( 'transition-delay' ) ) . toEqual ( '2s' ) ;
2368
2385
expect ( element ) . not . toHaveClass ( 'superman' ) ;
2369
2386
} ;
@@ -2397,8 +2414,8 @@ describe("ngAnimate $animateCss", function() {
2397
2414
it ( "should consider a negative value when delay:true is used with a keyframe animation" ,
2398
2415
inject ( function ( $animateCss , $rootElement ) {
2399
2416
2400
- ss . addRule ( '.ng-enter' , prefix + 'animation:2s keyframe_animation; ' +
2401
- prefix + 'animation-delay: -1s;' ) ;
2417
+ ss . addPossiblyPrefixedRule ( '.ng-enter' , 'animation: 2s keyframe_animation; ' +
2418
+ 'animation-delay: -1s;' ) ;
2402
2419
2403
2420
var options = {
2404
2421
delay : true ,
@@ -2411,7 +2428,7 @@ describe("ngAnimate $animateCss", function() {
2411
2428
animator . start ( ) ;
2412
2429
triggerAnimationStartFrame ( ) ;
2413
2430
2414
- expect ( element . css ( prefix + 'animation-delay' ) ) . toContain ( '-1s' ) ;
2431
+ expect ( getPossiblyPrefixedStyleValue ( element , 'animation-delay' ) ) . toContain ( '-1s' ) ;
2415
2432
} ) ) ;
2416
2433
2417
2434
they ( "should consider a negative value when a negative option delay is provided for a $prop animation" , {
@@ -2421,17 +2438,17 @@ describe("ngAnimate $animateCss", function() {
2421
2438
css : 'transition:2s linear all'
2422
2439
} ;
2423
2440
} ,
2424
- 'keyframe' : function ( prefix ) {
2441
+ 'keyframe' : function ( ) {
2425
2442
return {
2426
- prop : prefix + 'animation-delay' ,
2427
- css : prefix + 'animation:2s keyframe_animation'
2443
+ prop : 'animation-delay' ,
2444
+ css : 'animation: 2s keyframe_animation'
2428
2445
} ;
2429
2446
}
2430
2447
} , function ( testDetailsFactory ) {
2431
2448
inject ( function ( $animateCss , $rootElement ) {
2432
2449
var testDetails = testDetailsFactory ( prefix ) ;
2433
2450
2434
- ss . addRule ( '.ng-enter' , testDetails . css ) ;
2451
+ ss . addPossiblyPrefixedRule ( '.ng-enter' , testDetails . css ) ;
2435
2452
var options = {
2436
2453
delay : - 2 ,
2437
2454
event : 'enter' ,
@@ -2443,7 +2460,7 @@ describe("ngAnimate $animateCss", function() {
2443
2460
animator . start ( ) ;
2444
2461
triggerAnimationStartFrame ( ) ;
2445
2462
2446
- expect ( element . css ( testDetails . prop ) ) . toContain ( '-2s' ) ;
2463
+ expect ( getPossiblyPrefixedStyleValue ( element , testDetails . prop ) ) . toContain ( '-2s' ) ;
2447
2464
} ) ;
2448
2465
} ) ;
2449
2466
@@ -2454,18 +2471,18 @@ describe("ngAnimate $animateCss", function() {
2454
2471
css : 'transition:5s linear all; transition-delay: -2s'
2455
2472
} ;
2456
2473
} ,
2457
- 'animation' : function ( prefix ) {
2474
+ 'animation' : function ( ) {
2458
2475
return {
2459
2476
event : 'animationend' ,
2460
- css : prefix + 'animation:5s keyframe_animation; ' + prefix + ' animation-delay: -2s;'
2477
+ css : 'animation: 5s keyframe_animation; animation-delay: -2s;'
2461
2478
} ;
2462
2479
}
2463
2480
} , function ( testDetailsFactory ) {
2464
2481
inject ( function ( $animateCss , $rootElement ) {
2465
- var testDetails = testDetailsFactory ( prefix ) ;
2482
+ var testDetails = testDetailsFactory ( ) ;
2466
2483
var event = testDetails . event ;
2467
2484
2468
- ss . addRule ( '.ng-enter' , testDetails . css ) ;
2485
+ ss . addPossiblyPrefixedRule ( '.ng-enter' , testDetails . css ) ;
2469
2486
var options = { event : 'enter' , structural : true } ;
2470
2487
2471
2488
var animator = $animateCss ( element , options ) ;
@@ -2571,15 +2588,15 @@ describe("ngAnimate $animateCss", function() {
2571
2588
$animateCss ( element , options ) . start ( ) ;
2572
2589
triggerAnimationStartFrame ( ) ;
2573
2590
2574
- expect ( element . css ( prefix + 'transition-delay' ) ) . not . toEqual ( '4s' ) ;
2575
- expect ( element . css ( prefix + 'transition-duration' ) ) . not . toEqual ( '6s' ) ;
2591
+ expect ( getPossiblyPrefixedStyleValue ( element , 'transition-delay' ) ) . not . toEqual ( '4s' ) ;
2592
+ expect ( getPossiblyPrefixedStyleValue ( element , 'transition-duration' ) ) . not . toEqual ( '6s' ) ;
2576
2593
2577
2594
options . to = { color : 'brown' } ;
2578
2595
$animateCss ( element , options ) . start ( ) ;
2579
2596
triggerAnimationStartFrame ( ) ;
2580
2597
2581
- expect ( element . css ( prefix + 'transition-delay' ) ) . toEqual ( '4s' ) ;
2582
- expect ( element . css ( prefix + 'transition-duration' ) ) . toEqual ( '6s' ) ;
2598
+ expect ( getPossiblyPrefixedStyleValue ( element , 'transition-delay' ) ) . toEqual ( '4s' ) ;
2599
+ expect ( getPossiblyPrefixedStyleValue ( element , 'transition-duration' ) ) . toEqual ( '6s' ) ;
2583
2600
} ) ) ;
2584
2601
} ) ;
2585
2602
@@ -2652,9 +2669,9 @@ describe("ngAnimate $animateCss", function() {
2652
2669
triggerAnimationStartFrame ( ) ;
2653
2670
2654
2671
2655
- expect ( element . css ( prefix + 'animation-delay' ) ) . toEqual ( '50s' ) ;
2656
- expect ( element . css ( prefix + 'animation-duration' ) ) . toEqual ( '5.5s' ) ;
2657
- expect ( element . css ( prefix + 'animation-name' ) ) . toEqual ( 'my_animation' ) ;
2672
+ expect ( getPossiblyPrefixedStyleValue ( element , 'animation-delay' ) ) . toEqual ( '50s' ) ;
2673
+ expect ( getPossiblyPrefixedStyleValue ( element , 'animation-duration' ) ) . toEqual ( '5.5s' ) ;
2674
+ expect ( getPossiblyPrefixedStyleValue ( element , 'animation-name' ) ) . toEqual ( 'my_animation' ) ;
2658
2675
} ) ) ;
2659
2676
2660
2677
it ( "should be able to execute the animation if it is the only provided value" ,
@@ -2669,9 +2686,9 @@ describe("ngAnimate $animateCss", function() {
2669
2686
animator . start ( ) ;
2670
2687
triggerAnimationStartFrame ( ) ;
2671
2688
2672
- expect ( element . css ( prefix + 'animation-delay' ) ) . toEqual ( '10s' ) ;
2673
- expect ( element . css ( prefix + 'animation-duration' ) ) . toEqual ( '5.5s' ) ;
2674
- expect ( element . css ( prefix + 'animation-name' ) ) . toEqual ( 'my_animation' ) ;
2689
+ expect ( getPossiblyPrefixedStyleValue ( element , 'animation-delay' ) ) . toEqual ( '10s' ) ;
2690
+ expect ( getPossiblyPrefixedStyleValue ( element , 'animation-duration' ) ) . toEqual ( '5.5s' ) ;
2691
+ expect ( getPossiblyPrefixedStyleValue ( element , 'animation-name' ) ) . toEqual ( 'my_animation' ) ;
2675
2692
} ) ) ;
2676
2693
} ) ;
2677
2694
@@ -2964,7 +2981,7 @@ describe("ngAnimate $animateCss", function() {
2964
2981
2965
2982
2966
2983
expect ( element . css ( 'transition-duration' ) ) . toMatch ( '10s' ) ;
2967
- expect ( element . css ( prefix + 'animation-duration' ) ) . toEqual ( '10s' ) ;
2984
+ expect ( getPossiblyPrefixedStyleValue ( element , 'animation-duration' ) ) . toEqual ( '10s' ) ;
2968
2985
} ) ) ;
2969
2986
} ) ;
2970
2987
@@ -3004,7 +3021,7 @@ describe("ngAnimate $animateCss", function() {
3004
3021
inject ( function ( $animateCss ) {
3005
3022
3006
3023
ss . addRule ( '.red' , 'transition: 1s linear all;' ) ;
3007
- ss . addRule ( '.blue' , prefix + 'animation:my_keyframe 1s;' ) ;
3024
+ ss . addPossiblyPrefixedRule ( '.blue' , 'animation: 1s my_keyframe ;' ) ;
3008
3025
var easing = 'ease-out' ;
3009
3026
var animator = $animateCss ( element , { addClass : 'red blue' , easing : easing } ) ;
3010
3027
animator . start ( ) ;
0 commit comments