@@ -42,8 +42,7 @@ var ONE_SECOND = 1000;
42
42
var BASE_TEN = 10 ;
43
43
44
44
function computeCSSStyles ( $window , element , properties ) {
45
- var styles = { } ;
46
-
45
+ var styles = Object . create ( null ) ;
47
46
var detectedStyles = $window . getComputedStyle ( element ) || { } ;
48
47
forEach ( properties , function ( style , prop ) {
49
48
var val = detectedStyles [ style ] ;
@@ -61,9 +60,7 @@ function computeCSSStyles($window, element, properties) {
61
60
62
61
function parseMaxTime ( str ) {
63
62
var maxValue = 0 ;
64
- var values = isString ( str ) ?
65
- str . split ( / \s * , \s * / ) :
66
- [ ] ;
63
+ var values = str . split ( / \s * , \s * / ) ;
67
64
forEach ( values , function ( value ) {
68
65
maxValue = Math . max ( parseFloat ( value ) || 0 , maxValue ) ;
69
66
} ) ;
@@ -90,15 +87,15 @@ function getCssDelayStyle(delay, isKeyframeAnimation) {
90
87
return [ prop , delay + 's' ] ;
91
88
}
92
89
93
- function blockTransitions ( node , bool ) {
94
- var value = bool ? 'none' : '' ;
90
+ function blockTransitions ( node , applyBlock ) {
91
+ var value = applyBlock ? 'none' : '' ;
95
92
var key = TRANSITION_PROP + PROPERTY_KEY ;
96
93
applyInlineStyle ( node , key , value ) ;
97
94
return [ key , value ] ;
98
95
}
99
96
100
- function blockAnimations ( node , bool ) {
101
- var value = bool ? 'paused' : '' ;
97
+ function blockAnimations ( node , applyBlock ) {
98
+ var value = applyBlock ? 'paused' : '' ;
102
99
var key = ANIMATION_PROP + ANIMATION_PLAYSTATE_KEY ;
103
100
applyInlineStyle ( node , key , value ) ;
104
101
return [ key , value ] ;
@@ -112,8 +109,8 @@ function applyInlineStyle(node, key, value) {
112
109
node . style [ key ] = value ;
113
110
}
114
111
115
- function LocalCacheLookup ( ) {
116
- var cache = { } ;
112
+ function createLocalCacheLookup ( ) {
113
+ var cache = Object . create ( null ) ;
117
114
return {
118
115
flush : function ( ) {
119
116
cache = { } ;
@@ -131,17 +128,17 @@ function LocalCacheLookup() {
131
128
132
129
put : function ( key , value ) {
133
130
if ( ! cache [ key ] ) {
134
- cache [ key ] = { total : 0 } ;
131
+ cache [ key ] = { total : 1 , value : value } ;
132
+ } else {
133
+ cache [ key ] . total ++ ;
135
134
}
136
- cache [ key ] . total ++ ;
137
- cache [ key ] . value = value ;
138
135
}
139
136
} ;
140
137
}
141
138
142
139
var $AnimateCssProvider = [ '$animateProvider' , function ( $animateProvider ) {
143
- var gcsLookup = new LocalCacheLookup ( ) ;
144
- var gcsStaggerLookup = new LocalCacheLookup ( ) ;
140
+ var gcsLookup = createLocalCacheLookup ( ) ;
141
+ var gcsStaggerLookup = createLocalCacheLookup ( ) ;
145
142
146
143
this . $get = [ '$window' , '$$jqLite' , '$animateRunner' , '$timeout' ,
147
144
'$document' , '$$animateOptions' , '$sniffer' , '$$rAF' ,
@@ -161,8 +158,8 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
161
158
162
159
if ( ! timings ) {
163
160
timings = computeCSSStyles ( $window , node , properties ) ;
164
- if ( timings . animationIterationCount ) {
165
- timings . animationIterationCount = parseInt ( timings . animationIterationCount || 1 , BASE_TEN ) ;
161
+ if ( timings . animationIterationCount === 'infinite' ) {
162
+ timings . animationIterationCount = 1 ;
166
163
}
167
164
}
168
165
@@ -173,12 +170,13 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
173
170
}
174
171
175
172
function computeCachedCSSStaggerStyles ( node , className , cacheKey , properties ) {
176
- var stagger = { } ;
177
- var isRepeated = gcsLookup . count ( cacheKey ) > 0 ;
173
+ var stagger ;
178
174
179
- if ( isRepeated ) {
180
- var staggerCacheKey = cacheKey + '-stagger' ;
181
- stagger = gcsStaggerLookup . get ( staggerCacheKey ) ;
175
+ // if we have one or more existing matches of matching elements
176
+ // containing the same parent + CSS styles (which is how cacheKey works)
177
+ // then staggering is possible
178
+ if ( gcsLookup . count ( cacheKey ) > 0 ) {
179
+ stagger = gcsStaggerLookup . get ( cacheKey ) ;
182
180
183
181
if ( ! stagger ) {
184
182
var staggerClassName = pendClasses ( className , '-stagger' ) ;
@@ -189,18 +187,21 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
189
187
190
188
$$jqLite . removeClass ( node , staggerClassName ) ;
191
189
192
- gcsStaggerLookup . put ( staggerCacheKey , stagger ) ;
190
+ gcsStaggerLookup . put ( cacheKey , stagger ) ;
193
191
}
194
192
}
195
193
196
- return stagger ;
194
+ return stagger || { } ;
197
195
}
198
196
199
- var cancelLastRAFRequest , bod = $document [ 0 ] . body ;
197
+ var bod = $document [ 0 ] . body ;
198
+ var cancelLastRAFRequest ;
199
+ var rafWaitQueue = [ ] ;
200
200
function waitUntilQuiet ( callback ) {
201
201
if ( cancelLastRAFRequest ) {
202
202
cancelLastRAFRequest ( ) ; //cancels the request
203
203
}
204
+ rafWaitQueue . push ( callback ) ;
204
205
cancelLastRAFRequest = $$rAF ( function ( ) {
205
206
cancelLastRAFRequest = null ;
206
207
gcsLookup . flush ( ) ;
@@ -212,7 +213,10 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
212
213
//ensure that the the preparation animation is properly flushed so that
213
214
//the active state picks up from there. DO NOT REMOVE THIS LINE.
214
215
var a = bod . offsetWidth + 1 ;
215
- callback ( ) ;
216
+ forEach ( rafWaitQueue , function ( cb ) {
217
+ cb ( ) ;
218
+ } ) ;
219
+ rafWaitQueue . length = 0 ;
216
220
} ) ;
217
221
}
218
222
@@ -262,7 +266,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
262
266
// class-based animations so that we can avoid applying CSS blocking on
263
267
// the element to allow for normal transitions to work (this is how enter,
264
268
// leave and move can perform the `ng-EVENT` methods without causing an
265
- // unpected transition animation to occur).
269
+ // unexpected transition animation to occur).
266
270
var structural = method &&
267
271
[ ' setClass ' , ' addClass ' , ' removeClass ' ] . indexOf ( ' ' + method + ' ' ) == - 1 ;
268
272
@@ -508,7 +512,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
508
512
509
513
// if the preparation function fails then the promise is not setup
510
514
if ( runner ) {
511
- rejected ? runner . end ( ) : runner . cancel ( ) ;
515
+ runner . complete ( ! rejected ) ;
512
516
}
513
517
}
514
518
@@ -526,16 +530,16 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
526
530
if ( animationClosed ) return ;
527
531
528
532
var startTime , events = [ ] ;
529
- var playPause = function ( bool ) {
533
+ var playPause = function ( playAnimation ) {
530
534
if ( ! animationCompleted ) {
531
- animationPaused = ! bool ;
535
+ animationPaused = ! playAnimation ;
532
536
if ( timings . animationDuration ) {
533
537
var value = blockAnimations ( node , animationPaused ) ;
534
538
animationPaused
535
539
? temporaryStyles . push ( value )
536
540
: removeFromArray ( temporaryStyles , value ) ;
537
541
}
538
- } else if ( animationPaused && bool ) {
542
+ } else if ( animationPaused && playAnimation ) {
539
543
animationPaused = false ;
540
544
close ( ) ;
541
545
}
0 commit comments