diff options
| author | Matias Niemelä | 2013-10-10 09:16:19 -0400 |
|---|---|---|
| committer | Misko Hevery | 2013-10-10 17:35:36 -0700 |
| commit | 3f31a7c7691993893f0724076816f6558643bd91 (patch) | |
| tree | 710761f443eb304f5f4b68b6d698466a004dd363 /src | |
| parent | 079dd93991ac79b5f9af6efb7fe2b3600195f10c (diff) | |
| download | angular.js-3f31a7c7691993893f0724076816f6558643bd91.tar.bz2 | |
fix($animate): cancel any ongoing child animations during move and leave animations
Diffstat (limited to 'src')
| -rw-r--r-- | src/ngAnimate/animate.js | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/src/ngAnimate/animate.js b/src/ngAnimate/animate.js index ee637b3b..9b09cad2 100644 --- a/src/ngAnimate/animate.js +++ b/src/ngAnimate/animate.js @@ -200,6 +200,7 @@ angular.module('ngAnimate', ['ng']) var selectors = $animateProvider.$$selectors; var NG_ANIMATE_STATE = '$$ngAnimateState'; + var NG_ANIMATE_CLASS_NAME = 'ng-animate'; var rootAnimateState = {running:true}; $provide.decorator('$animate', ['$delegate', '$injector', '$sniffer', '$rootElement', '$timeout', '$rootScope', function($delegate, $injector, $sniffer, $rootElement, $timeout, $rootScope) { @@ -320,6 +321,7 @@ angular.module('ngAnimate', ['ng']) * @param {function()=} done callback function that will be called once the animation is complete */ leave : function(element, done) { + cancelChildAnimations(element); $rootScope.$$postDigest(function() { performAnimation('leave', 'ng-leave', element, null, null, function() { $delegate.leave(element, done); @@ -358,6 +360,7 @@ angular.module('ngAnimate', ['ng']) * @param {function()=} done callback function that will be called once the animation is complete */ move : function(element, parent, after, done) { + cancelChildAnimations(element); $delegate.move(element, parent, after); $rootScope.$$postDigest(function() { performAnimation('move', 'ng-move', element, null, null, function() { @@ -503,6 +506,10 @@ angular.module('ngAnimate', ['ng']) done:done }); + //the ng-animate class does nothing, but it's here to allow for + //parent animations to find and cancel child animations when needed + element.addClass(NG_ANIMATE_CLASS_NAME); + forEach(animations, function(animation, index) { var fn = function() { progress(index); @@ -519,12 +526,6 @@ angular.module('ngAnimate', ['ng']) } }); - function cancelAnimations(animations) { - var isCancelledFlag = true; - forEach(animations, function(animation) { - (animation.endFn || noop)(isCancelledFlag); - }); - } function progress(index) { animations[index].done = true; @@ -538,11 +539,34 @@ angular.module('ngAnimate', ['ng']) function done() { if(!done.hasBeenRun) { done.hasBeenRun = true; - element.removeData(NG_ANIMATE_STATE); + cleanup(element); (onComplete || noop)(); } } } + + function cancelChildAnimations(element) { + angular.forEach(element[0].querySelectorAll('.' + NG_ANIMATE_CLASS_NAME), function(element) { + element = angular.element(element); + var data = element.data(NG_ANIMATE_STATE); + if(data) { + cancelAnimations(data.animations); + cleanup(element); + } + }); + } + + function cancelAnimations(animations) { + var isCancelledFlag = true; + forEach(animations, function(animation) { + (animation.endFn || noop)(isCancelledFlag); + }); + } + + function cleanup(element) { + element.removeClass(NG_ANIMATE_CLASS_NAME); + element.removeData(NG_ANIMATE_STATE); + } }]); $animateProvider.register('', ['$window', '$sniffer', function($window, $sniffer) { |
