@@ -425,6 +425,16 @@ angular.module('ngAnimate', ['ng'])
425
425
element . data ( NG_ANIMATE_STATE , data ) ;
426
426
}
427
427
428
+ function runAnimationPostDigest ( fn ) {
429
+ var cancelFn ;
430
+ $rootScope . $$postDigest ( function ( ) {
431
+ cancelFn = fn ( ) ;
432
+ } ) ;
433
+ return function ( ) {
434
+ cancelFn && cancelFn ( ) ;
435
+ } ;
436
+ }
437
+
428
438
function lookup ( name ) {
429
439
if ( name ) {
430
440
var matches = [ ] ,
@@ -648,6 +658,7 @@ angular.module('ngAnimate', ['ng'])
648
658
* @param {DOMElement } parentElement the parent element of the element that will be the focus of the enter animation
649
659
* @param {DOMElement } afterElement the sibling element (which is the previous element) of the element that will be the focus of the enter animation
650
660
* @param {function()= } doneCallback the callback function that will be called once the animation is complete
661
+ * @return {function } the animation cancellation function
651
662
*/
652
663
enter : function ( element , parentElement , afterElement , doneCallback ) {
653
664
element = angular . element ( element ) ;
@@ -656,9 +667,8 @@ angular.module('ngAnimate', ['ng'])
656
667
657
668
blockElementAnimations ( element ) ;
658
669
$delegate . enter ( element , parentElement , afterElement ) ;
659
- $rootScope . $$postDigest ( function ( ) {
660
- element = stripCommentsFromElement ( element ) ;
661
- performAnimation ( 'enter' , 'ng-enter' , element , parentElement , afterElement , noop , doneCallback ) ;
670
+ return runAnimationPostDigest ( function ( ) {
671
+ return performAnimation ( 'enter' , 'ng-enter' , stripCommentsFromElement ( element ) , parentElement , afterElement , noop , doneCallback ) ;
662
672
} ) ;
663
673
} ,
664
674
@@ -691,13 +701,16 @@ angular.module('ngAnimate', ['ng'])
691
701
*
692
702
* @param {DOMElement } element the element that will be the focus of the leave animation
693
703
* @param {function()= } doneCallback the callback function that will be called once the animation is complete
704
+ * @return {function } the animation cancellation function
694
705
*/
695
706
leave : function ( element , doneCallback ) {
696
707
element = angular . element ( element ) ;
708
+
697
709
cancelChildAnimations ( element ) ;
698
710
blockElementAnimations ( element ) ;
699
- $rootScope . $$postDigest ( function ( ) {
700
- performAnimation ( 'leave' , 'ng-leave' , stripCommentsFromElement ( element ) , null , null , function ( ) {
711
+ this . enabled ( false , element ) ;
712
+ return runAnimationPostDigest ( function ( ) {
713
+ return performAnimation ( 'leave' , 'ng-leave' , stripCommentsFromElement ( element ) , null , null , function ( ) {
701
714
$delegate . leave ( element ) ;
702
715
} , doneCallback ) ;
703
716
} ) ;
@@ -735,6 +748,7 @@ angular.module('ngAnimate', ['ng'])
735
748
* @param {DOMElement } parentElement the parentElement element of the element that will be the focus of the move animation
736
749
* @param {DOMElement } afterElement the sibling element (which is the previous element) of the element that will be the focus of the move animation
737
750
* @param {function()= } doneCallback the callback function that will be called once the animation is complete
751
+ * @return {function } the animation cancellation function
738
752
*/
739
753
move : function ( element , parentElement , afterElement , doneCallback ) {
740
754
element = angular . element ( element ) ;
@@ -744,9 +758,8 @@ angular.module('ngAnimate', ['ng'])
744
758
cancelChildAnimations ( element ) ;
745
759
blockElementAnimations ( element ) ;
746
760
$delegate . move ( element , parentElement , afterElement ) ;
747
- $rootScope . $$postDigest ( function ( ) {
748
- element = stripCommentsFromElement ( element ) ;
749
- performAnimation ( 'move' , 'ng-move' , element , parentElement , afterElement , noop , doneCallback ) ;
761
+ return runAnimationPostDigest ( function ( ) {
762
+ return performAnimation ( 'move' , 'ng-move' , stripCommentsFromElement ( element ) , parentElement , afterElement , noop , doneCallback ) ;
750
763
} ) ;
751
764
} ,
752
765
@@ -778,11 +791,12 @@ angular.module('ngAnimate', ['ng'])
778
791
* @param {DOMElement } element the element that will be animated
779
792
* @param {string } className the CSS class that will be added to the element and then animated
780
793
* @param {function()= } doneCallback the callback function that will be called once the animation is complete
794
+ * @return {function } the animation cancellation function
781
795
*/
782
796
addClass : function ( element , className , doneCallback ) {
783
797
element = angular . element ( element ) ;
784
798
element = stripCommentsFromElement ( element ) ;
785
- performAnimation ( 'addClass' , className , element , null , null , function ( ) {
799
+ return performAnimation ( 'addClass' , className , element , null , null , function ( ) {
786
800
$delegate . addClass ( element , className ) ;
787
801
} , doneCallback ) ;
788
802
} ,
@@ -815,11 +829,12 @@ angular.module('ngAnimate', ['ng'])
815
829
* @param {DOMElement } element the element that will be animated
816
830
* @param {string } className the CSS class that will be animated and then removed from the element
817
831
* @param {function()= } doneCallback the callback function that will be called once the animation is complete
832
+ * @return {function } the animation cancellation function
818
833
*/
819
834
removeClass : function ( element , className , doneCallback ) {
820
835
element = angular . element ( element ) ;
821
836
element = stripCommentsFromElement ( element ) ;
822
- performAnimation ( 'removeClass' , className , element , null , null , function ( ) {
837
+ return performAnimation ( 'removeClass' , className , element , null , null , function ( ) {
823
838
$delegate . removeClass ( element , className ) ;
824
839
} , doneCallback ) ;
825
840
} ,
@@ -848,13 +863,14 @@ angular.module('ngAnimate', ['ng'])
848
863
* removed from it
849
864
* @param {string } add the CSS classes which will be added to the element
850
865
* @param {string } remove the CSS class which will be removed from the element
851
- * @param {Function = } done the callback function (if provided) that will be fired after the
866
+ * @param {function = } done the callback function (if provided) that will be fired after the
852
867
* CSS classes have been set on the element
868
+ * @return {function } the animation cancellation function
853
869
*/
854
870
setClass : function ( element , add , remove , doneCallback ) {
855
871
element = angular . element ( element ) ;
856
872
element = stripCommentsFromElement ( element ) ;
857
- performAnimation ( 'setClass' , [ add , remove ] , element , null , null , function ( ) {
873
+ return performAnimation ( 'setClass' , [ add , remove ] , element , null , null , function ( ) {
858
874
$delegate . setClass ( element , add , remove ) ;
859
875
} , doneCallback ) ;
860
876
} ,
@@ -905,13 +921,14 @@ angular.module('ngAnimate', ['ng'])
905
921
*/
906
922
function performAnimation ( animationEvent , className , element , parentElement , afterElement , domOperation , doneCallback ) {
907
923
924
+ var noopCancel = noop ;
908
925
var runner = animationRunner ( element , animationEvent , className ) ;
909
926
if ( ! runner ) {
910
927
fireDOMOperation ( ) ;
911
928
fireBeforeCallbackAsync ( ) ;
912
929
fireAfterCallbackAsync ( ) ;
913
930
closeAnimation ( ) ;
914
- return ;
931
+ return noopCancel ;
915
932
}
916
933
917
934
className = runner . className ;
@@ -945,7 +962,7 @@ angular.module('ngAnimate', ['ng'])
945
962
fireBeforeCallbackAsync ( ) ;
946
963
fireAfterCallbackAsync ( ) ;
947
964
closeAnimation ( ) ;
948
- return ;
965
+ return noopCancel ;
949
966
}
950
967
951
968
var skipAnimation = false ;
@@ -993,7 +1010,7 @@ angular.module('ngAnimate', ['ng'])
993
1010
fireBeforeCallbackAsync ( ) ;
994
1011
fireAfterCallbackAsync ( ) ;
995
1012
fireDoneCallbackAsync ( ) ;
996
- return ;
1013
+ return noopCancel ;
997
1014
}
998
1015
999
1016
if ( animationEvent == 'leave' ) {
@@ -1046,6 +1063,8 @@ angular.module('ngAnimate', ['ng'])
1046
1063
}
1047
1064
} ) ;
1048
1065
1066
+ return runner . cancel ;
1067
+
1049
1068
function fireDOMCallback ( animationPhase ) {
1050
1069
var eventName = '$animate:' + animationPhase ;
1051
1070
if ( elementEvents && elementEvents [ eventName ] && elementEvents [ eventName ] . length > 0 ) {
0 commit comments