@@ -391,6 +391,16 @@ angular.module('ngAnimate', ['ng'])
391
391
return classNameFilter . test ( className ) ;
392
392
} ;
393
393
394
+ function runAnimationPostDigest ( fn ) {
395
+ var cancelFn ;
396
+ $rootScope . $$postDigest ( function ( ) {
397
+ cancelFn = fn ( ) ;
398
+ } ) ;
399
+ return function ( ) {
400
+ cancelFn && cancelFn ( ) ;
401
+ } ;
402
+ }
403
+
394
404
function lookup ( name ) {
395
405
if ( name ) {
396
406
var matches = [ ] ,
@@ -614,6 +624,7 @@ angular.module('ngAnimate', ['ng'])
614
624
* @param {DOMElement } parentElement the parent element of the element that will be the focus of the enter animation
615
625
* @param {DOMElement } afterElement the sibling element (which is the previous element) of the element that will be the focus of the enter animation
616
626
* @param {function()= } doneCallback the callback function that will be called once the animation is complete
627
+ * @return {function } the animation cancellation function
617
628
*/
618
629
enter : function ( element , parentElement , afterElement , doneCallback ) {
619
630
element = angular . element ( element ) ;
@@ -622,9 +633,8 @@ angular.module('ngAnimate', ['ng'])
622
633
623
634
this . enabled ( false , element ) ;
624
635
$delegate . enter ( element , parentElement , afterElement ) ;
625
- $rootScope . $$postDigest ( function ( ) {
626
- element = stripCommentsFromElement ( element ) ;
627
- performAnimation ( 'enter' , 'ng-enter' , element , parentElement , afterElement , noop , doneCallback ) ;
636
+ return runAnimationPostDigest ( function ( ) {
637
+ return performAnimation ( 'enter' , 'ng-enter' , stripCommentsFromElement ( element ) , parentElement , afterElement , noop , doneCallback ) ;
628
638
} ) ;
629
639
} ,
630
640
@@ -657,13 +667,14 @@ angular.module('ngAnimate', ['ng'])
657
667
*
658
668
* @param {DOMElement } element the element that will be the focus of the leave animation
659
669
* @param {function()= } doneCallback the callback function that will be called once the animation is complete
670
+ * @return {function } the animation cancellation function
660
671
*/
661
672
leave : function ( element , doneCallback ) {
662
673
element = angular . element ( element ) ;
663
674
cancelChildAnimations ( element ) ;
664
675
this . enabled ( false , element ) ;
665
- $rootScope . $$postDigest ( function ( ) {
666
- performAnimation ( 'leave' , 'ng-leave' , stripCommentsFromElement ( element ) , null , null , function ( ) {
676
+ return runAnimationPostDigest ( function ( ) {
677
+ return performAnimation ( 'leave' , 'ng-leave' , stripCommentsFromElement ( element ) , null , null , function ( ) {
667
678
$delegate . leave ( element ) ;
668
679
} , doneCallback ) ;
669
680
} ) ;
@@ -701,6 +712,7 @@ angular.module('ngAnimate', ['ng'])
701
712
* @param {DOMElement } parentElement the parentElement element of the element that will be the focus of the move animation
702
713
* @param {DOMElement } afterElement the sibling element (which is the previous element) of the element that will be the focus of the move animation
703
714
* @param {function()= } doneCallback the callback function that will be called once the animation is complete
715
+ * @return {function } the animation cancellation function
704
716
*/
705
717
move : function ( element , parentElement , afterElement , doneCallback ) {
706
718
element = angular . element ( element ) ;
@@ -710,9 +722,8 @@ angular.module('ngAnimate', ['ng'])
710
722
cancelChildAnimations ( element ) ;
711
723
this . enabled ( false , element ) ;
712
724
$delegate . move ( element , parentElement , afterElement ) ;
713
- $rootScope . $$postDigest ( function ( ) {
714
- element = stripCommentsFromElement ( element ) ;
715
- performAnimation ( 'move' , 'ng-move' , element , parentElement , afterElement , noop , doneCallback ) ;
725
+ return runAnimationPostDigest ( function ( ) {
726
+ return performAnimation ( 'move' , 'ng-move' , stripCommentsFromElement ( element ) , parentElement , afterElement , noop , doneCallback ) ;
716
727
} ) ;
717
728
} ,
718
729
@@ -744,11 +755,12 @@ angular.module('ngAnimate', ['ng'])
744
755
* @param {DOMElement } element the element that will be animated
745
756
* @param {string } className the CSS class that will be added to the element and then animated
746
757
* @param {function()= } doneCallback the callback function that will be called once the animation is complete
758
+ * @return {function } the animation cancellation function
747
759
*/
748
760
addClass : function ( element , className , doneCallback ) {
749
761
element = angular . element ( element ) ;
750
762
element = stripCommentsFromElement ( element ) ;
751
- performAnimation ( 'addClass' , className , element , null , null , function ( ) {
763
+ return performAnimation ( 'addClass' , className , element , null , null , function ( ) {
752
764
$delegate . addClass ( element , className ) ;
753
765
} , doneCallback ) ;
754
766
} ,
@@ -781,11 +793,12 @@ angular.module('ngAnimate', ['ng'])
781
793
* @param {DOMElement } element the element that will be animated
782
794
* @param {string } className the CSS class that will be animated and then removed from the element
783
795
* @param {function()= } doneCallback the callback function that will be called once the animation is complete
796
+ * @return {function } the animation cancellation function
784
797
*/
785
798
removeClass : function ( element , className , doneCallback ) {
786
799
element = angular . element ( element ) ;
787
800
element = stripCommentsFromElement ( element ) ;
788
- performAnimation ( 'removeClass' , className , element , null , null , function ( ) {
801
+ return performAnimation ( 'removeClass' , className , element , null , null , function ( ) {
789
802
$delegate . removeClass ( element , className ) ;
790
803
} , doneCallback ) ;
791
804
} ,
@@ -814,13 +827,14 @@ angular.module('ngAnimate', ['ng'])
814
827
* removed from it
815
828
* @param {string } add the CSS classes which will be added to the element
816
829
* @param {string } remove the CSS class which will be removed from the element
817
- * @param {Function = } done the callback function (if provided) that will be fired after the
830
+ * @param {function = } done the callback function (if provided) that will be fired after the
818
831
* CSS classes have been set on the element
832
+ * @return {function } the animation cancellation function
819
833
*/
820
834
setClass : function ( element , add , remove , doneCallback ) {
821
835
element = angular . element ( element ) ;
822
836
element = stripCommentsFromElement ( element ) ;
823
- performAnimation ( 'setClass' , [ add , remove ] , element , null , null , function ( ) {
837
+ return performAnimation ( 'setClass' , [ add , remove ] , element , null , null , function ( ) {
824
838
$delegate . setClass ( element , add , remove ) ;
825
839
} , doneCallback ) ;
826
840
} ,
@@ -871,13 +885,14 @@ angular.module('ngAnimate', ['ng'])
871
885
*/
872
886
function performAnimation ( animationEvent , className , element , parentElement , afterElement , domOperation , doneCallback ) {
873
887
888
+ var noopCancel = noop ;
874
889
var runner = animationRunner ( element , animationEvent , className ) ;
875
890
if ( ! runner ) {
876
891
fireDOMOperation ( ) ;
877
892
fireBeforeCallbackAsync ( ) ;
878
893
fireAfterCallbackAsync ( ) ;
879
894
closeAnimation ( ) ;
880
- return ;
895
+ return noopCancel ;
881
896
}
882
897
883
898
className = runner . className ;
@@ -908,7 +923,7 @@ angular.module('ngAnimate', ['ng'])
908
923
fireBeforeCallbackAsync ( ) ;
909
924
fireAfterCallbackAsync ( ) ;
910
925
closeAnimation ( ) ;
911
- return ;
926
+ return noopCancel ;
912
927
}
913
928
914
929
var skipAnimation = false ;
@@ -956,7 +971,7 @@ angular.module('ngAnimate', ['ng'])
956
971
fireBeforeCallbackAsync ( ) ;
957
972
fireAfterCallbackAsync ( ) ;
958
973
fireDoneCallbackAsync ( ) ;
959
- return ;
974
+ return noopCancel ;
960
975
}
961
976
962
977
if ( animationEvent == 'leave' ) {
@@ -1009,6 +1024,8 @@ angular.module('ngAnimate', ['ng'])
1009
1024
}
1010
1025
} ) ;
1011
1026
1027
+ return runner . cancel ;
1028
+
1012
1029
function fireDOMCallback ( animationPhase ) {
1013
1030
var eventName = '$animate:' + animationPhase ;
1014
1031
if ( elementEvents && elementEvents [ eventName ] && elementEvents [ eventName ] . length > 0 ) {
0 commit comments