@@ -317,6 +317,10 @@ angular.module('ngAnimate', ['ng'])
317
317
return classNameFilter . test ( className ) ;
318
318
} ;
319
319
320
+ function async ( fn ) {
321
+ return $timeout ( fn , 0 , false ) ;
322
+ }
323
+
320
324
function lookup ( name ) {
321
325
if ( name ) {
322
326
var matches = [ ] ,
@@ -608,6 +612,8 @@ angular.module('ngAnimate', ['ng'])
608
612
//best to catch this early on to prevent any animation operations from occurring
609
613
if ( ! node || ! isAnimatableClassName ( classes ) ) {
610
614
fireDOMOperation ( ) ;
615
+ fireBeforeCallbackAsync ( ) ;
616
+ fireAfterCallbackAsync ( ) ;
611
617
closeAnimation ( ) ;
612
618
return ;
613
619
}
@@ -627,6 +633,8 @@ angular.module('ngAnimate', ['ng'])
627
633
//NOTE: IE8 + IE9 should close properly (run closeAnimation()) in case a NO animation is not found.
628
634
if ( animationsDisabled ( element , parentElement ) || matches . length === 0 ) {
629
635
fireDOMOperation ( ) ;
636
+ fireBeforeCallbackAsync ( ) ;
637
+ fireAfterCallbackAsync ( ) ;
630
638
closeAnimation ( ) ;
631
639
return ;
632
640
}
@@ -665,6 +673,8 @@ angular.module('ngAnimate', ['ng'])
665
673
//animation do it's thing and close this one early
666
674
if ( animations . length === 0 ) {
667
675
fireDOMOperation ( ) ;
676
+ fireBeforeCallbackAsync ( ) ;
677
+ fireAfterCallbackAsync ( ) ;
668
678
fireDoneCallbackAsync ( ) ;
669
679
return ;
670
680
}
@@ -718,6 +728,8 @@ angular.module('ngAnimate', ['ng'])
718
728
if ( ( animationEvent == 'addClass' && futureClassName . indexOf ( classNameToken ) >= 0 ) ||
719
729
( animationEvent == 'removeClass' && futureClassName . indexOf ( classNameToken ) == - 1 ) ) {
720
730
fireDOMOperation ( ) ;
731
+ fireBeforeCallbackAsync ( ) ;
732
+ fireAfterCallbackAsync ( ) ;
721
733
fireDoneCallbackAsync ( ) ;
722
734
return ;
723
735
}
@@ -758,6 +770,10 @@ angular.module('ngAnimate', ['ng'])
758
770
}
759
771
760
772
function invokeRegisteredAnimationFns ( animations , phase , allAnimationFnsComplete ) {
773
+ phase == 'after' ?
774
+ fireAfterCallbackAsync ( ) :
775
+ fireBeforeCallbackAsync ( ) ;
776
+
761
777
var endFnName = phase + 'End' ;
762
778
forEach ( animations , function ( animation , index ) {
763
779
var animationPhaseCompleted = function ( ) {
@@ -794,8 +810,27 @@ angular.module('ngAnimate', ['ng'])
794
810
}
795
811
}
796
812
813
+ function fireDOMCallback ( animationPhase ) {
814
+ element . triggerHandler ( '$animate:' + animationPhase , {
815
+ event : animationEvent ,
816
+ className : className
817
+ } ) ;
818
+ }
819
+
820
+ function fireBeforeCallbackAsync ( ) {
821
+ async ( function ( ) {
822
+ fireDOMCallback ( 'before' ) ;
823
+ } ) ;
824
+ }
825
+
826
+ function fireAfterCallbackAsync ( ) {
827
+ async ( function ( ) {
828
+ fireDOMCallback ( 'after' ) ;
829
+ } ) ;
830
+ }
831
+
797
832
function fireDoneCallbackAsync ( ) {
798
- doneCallback && $timeout ( doneCallback , 0 , false ) ;
833
+ doneCallback && async ( doneCallback ) ;
799
834
}
800
835
801
836
//it is less complicated to use a flag than managing and cancelling
@@ -819,9 +854,9 @@ angular.module('ngAnimate', ['ng'])
819
854
if ( isClassBased ) {
820
855
cleanup ( element ) ;
821
856
} else {
822
- data . closeAnimationTimeout = $timeout ( function ( ) {
857
+ data . closeAnimationTimeout = async ( function ( ) {
823
858
cleanup ( element ) ;
824
- } , 0 , false ) ;
859
+ } ) ;
825
860
element . data ( NG_ANIMATE_STATE , data ) ;
826
861
}
827
862
}
0 commit comments