@@ -268,6 +268,20 @@ angular.module('ngAnimate', ['ng'])
268
268
} ;
269
269
} ] )
270
270
271
+ . factory ( '$$asyncQueueBuffer' , [ '$timeout' , function ( $timeout ) {
272
+ var timer , queue = [ ] ;
273
+ return function ( fn ) {
274
+ $timeout . cancel ( timer ) ;
275
+ queue . push ( fn ) ;
276
+ timer = $timeout ( function ( ) {
277
+ for ( var i = 0 ; i < queue . length ; i ++ ) {
278
+ queue [ i ] ( ) ;
279
+ }
280
+ queue = [ ] ;
281
+ } , 0 , false ) ;
282
+ } ;
283
+ } ] )
284
+
271
285
. config ( [ '$provide' , '$animateProvider' , function ( $provide , $animateProvider ) {
272
286
var noop = angular . noop ;
273
287
var forEach = angular . forEach ;
@@ -291,9 +305,10 @@ angular.module('ngAnimate', ['ng'])
291
305
return extractElementNode ( elm1 ) == extractElementNode ( elm2 ) ;
292
306
}
293
307
294
- $provide . decorator ( '$animate' , [ '$delegate' , '$injector' , '$sniffer' , '$rootElement' , '$timeout ' , '$rootScope' , '$document' ,
295
- function ( $delegate , $injector , $sniffer , $rootElement , $timeout , $rootScope , $document ) {
308
+ $provide . decorator ( '$animate' , [ '$delegate' , '$injector' , '$sniffer' , '$rootElement' , '$$asyncQueueBuffer ' , '$rootScope' , '$document' ,
309
+ function ( $delegate , $injector , $sniffer , $rootElement , $$asyncQueueBuffer , $rootScope , $document ) {
296
310
311
+ var globalAnimationCounter = 0 ;
297
312
$rootElement . data ( NG_ANIMATE_STATE , rootAnimateState ) ;
298
313
299
314
// disable animations during bootstrap, but once we bootstrapped, wait again
@@ -315,10 +330,6 @@ angular.module('ngAnimate', ['ng'])
315
330
return classNameFilter . test ( className ) ;
316
331
} ;
317
332
318
- function async ( fn ) {
319
- return $timeout ( fn , 0 , false ) ;
320
- }
321
-
322
333
function lookup ( name ) {
323
334
if ( name ) {
324
335
var matches = [ ] ,
@@ -685,7 +696,6 @@ angular.module('ngAnimate', ['ng'])
685
696
if ( ngAnimateState . running ) {
686
697
//if an animation is currently running on the element then lets take the steps
687
698
//to cancel that animation and fire any required callbacks
688
- $timeout . cancel ( ngAnimateState . closeAnimationTimeout ) ;
689
699
cleanup ( element ) ;
690
700
cancelAnimations ( ngAnimateState . animations ) ;
691
701
@@ -736,12 +746,15 @@ angular.module('ngAnimate', ['ng'])
736
746
//parent animations to find and cancel child animations when needed
737
747
element . addClass ( NG_ANIMATE_CLASS_NAME ) ;
738
748
749
+ var localAnimationCount = globalAnimationCounter ++ ;
750
+
739
751
element . data ( NG_ANIMATE_STATE , {
740
752
running :true ,
741
753
event :animationEvent ,
742
754
className :className ,
743
755
structural :! isClassBased ,
744
756
animations :animations ,
757
+ index :localAnimationCount ,
745
758
done :onBeforeAnimationsComplete
746
759
} ) ;
747
760
@@ -816,19 +829,19 @@ angular.module('ngAnimate', ['ng'])
816
829
}
817
830
818
831
function fireBeforeCallbackAsync ( ) {
819
- async ( function ( ) {
832
+ $$asyncQueueBuffer ( function ( ) {
820
833
fireDOMCallback ( 'before' ) ;
821
834
} ) ;
822
835
}
823
836
824
837
function fireAfterCallbackAsync ( ) {
825
- async ( function ( ) {
838
+ $$asyncQueueBuffer ( function ( ) {
826
839
fireDOMCallback ( 'after' ) ;
827
840
} ) ;
828
841
}
829
842
830
843
function fireDoneCallbackAsync ( ) {
831
- async ( function ( ) {
844
+ $$asyncQueueBuffer ( function ( ) {
832
845
fireDOMCallback ( 'close' ) ;
833
846
doneCallback && doneCallback ( ) ;
834
847
} ) ;
@@ -855,8 +868,11 @@ angular.module('ngAnimate', ['ng'])
855
868
if ( isClassBased ) {
856
869
cleanup ( element ) ;
857
870
} else {
858
- data . closeAnimationTimeout = async ( function ( ) {
859
- cleanup ( element ) ;
871
+ $$asyncQueueBuffer ( function ( ) {
872
+ var data = element . data ( NG_ANIMATE_STATE ) || { } ;
873
+ if ( localAnimationCount == data . index ) {
874
+ cleanup ( element ) ;
875
+ }
860
876
} ) ;
861
877
element . data ( NG_ANIMATE_STATE , data ) ;
862
878
}
0 commit comments