@@ -48,9 +48,13 @@ angular
48
48
. directive ( 'mdProgressCircular' , MdProgressCircularDirective ) ;
49
49
50
50
/* @ngInject */
51
- function MdProgressCircularDirective ( $$rAF , $ window, $mdProgressCircular , $mdTheming ,
51
+ function MdProgressCircularDirective ( $window , $mdProgressCircular , $mdTheming ,
52
52
$mdUtil , $interval , $log ) {
53
53
54
+ // Note that this shouldn't use use $$rAF, because it can cause an infinite loop
55
+ // in any tests that call $animate.flush.
56
+ var rAF = $window . requestAnimationFrame || angular . noop ;
57
+ var cAF = $window . cancelAnimationFrame || angular . noop ;
54
58
var DEGREE_IN_RADIANS = $window . Math . PI / 180 ;
55
59
var MODE_DETERMINATE = 'determinate' ;
56
60
var MODE_INDETERMINATE = 'indeterminate' ;
@@ -110,8 +114,12 @@ function MdProgressCircularDirective($$rAF, $window, $mdProgressCircular, $mdThe
110
114
startIndeterminateAnimation ( ) ;
111
115
}
112
116
113
- scope . $on ( '$destroy' , function ( ) {
114
- cleanupIndeterminateAnimation ( true ) ;
117
+ scope . $on ( '$destroy' , function ( ) {
118
+ cleanupIndeterminateAnimation ( ) ;
119
+
120
+ if ( lastDrawFrame ) {
121
+ cAF ( lastDrawFrame ) ;
122
+ }
115
123
} ) ;
116
124
117
125
scope . $watchGroup ( [ 'value' , 'mdMode' , function ( ) {
@@ -147,7 +155,7 @@ function MdProgressCircularDirective($$rAF, $window, $mdProgressCircular, $mdThe
147
155
} else {
148
156
var newValue = clamp ( newValues [ 0 ] ) ;
149
157
150
- cleanupIndeterminateAnimation ( true ) ;
158
+ cleanupIndeterminateAnimation ( ) ;
151
159
152
160
element . attr ( 'aria-valuenow' , newValue ) ;
153
161
renderCircle ( clamp ( oldValues [ 0 ] ) , newValue ) ;
@@ -200,7 +208,7 @@ function MdProgressCircularDirective($$rAF, $window, $mdProgressCircular, $mdThe
200
208
if ( animateTo === animateFrom ) {
201
209
path . attr ( 'd' , getSvgArc ( animateTo , diameter , pathDiameter , rotation ) ) ;
202
210
} else {
203
- lastDrawFrame = $$ rAF( function animation ( now ) {
211
+ lastDrawFrame = rAF ( function animation ( now ) {
204
212
var currentTime = $window . Math . max ( 0 , $window . Math . min ( ( now || $mdUtil . now ( ) ) - startTime , animationDuration ) ) ;
205
213
206
214
path . attr ( 'd' , getSvgArc (
@@ -210,11 +218,9 @@ function MdProgressCircularDirective($$rAF, $window, $mdProgressCircular, $mdThe
210
218
rotation
211
219
) ) ;
212
220
213
- lastDrawFrame && lastDrawFrame ( ) ;
214
-
215
221
// Do not allow overlapping animations
216
222
if ( id === lastAnimationId && currentTime < animationDuration ) {
217
- lastDrawFrame = $$ rAF( animation ) ;
223
+ lastDrawFrame = rAF ( animation ) ;
218
224
}
219
225
} ) ;
220
226
}
@@ -256,17 +262,12 @@ function MdProgressCircularDirective($$rAF, $window, $mdProgressCircular, $mdThe
256
262
}
257
263
}
258
264
259
- function cleanupIndeterminateAnimation ( clearLastFrames ) {
265
+ function cleanupIndeterminateAnimation ( ) {
260
266
if ( interval ) {
261
267
$interval . cancel ( interval ) ;
262
268
interval = null ;
263
269
element . removeClass ( INDETERMINATE_CLASS ) ;
264
270
}
265
-
266
- if ( clearLastFrames === true ) {
267
- lastDrawFrame && lastDrawFrame ( ) ;
268
- lastDrawFrame = undefined ;
269
- }
270
271
}
271
272
}
272
273
0 commit comments