From b9093ad8b22f611a2d4b27c097a5b8c011ecd92f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Thu, 16 Apr 2015 11:33:59 -0700 Subject: [PATCH] fix(ngAnimate): close parent animations only when there are classes to resolve Previously if a parent animation was cancelled then it would not resolve the runner when that happens. This is now fixed in this patch. Another fix in this patch ensures that a parent animation is only cancelled if the animation contains any classes to resolve. This prevents inline animations from being cancelled. --- src/ngAnimate/animateQueue.js | 3 ++- test/ngAnimate/animateSpec.js | 37 +++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/ngAnimate/animateQueue.js b/src/ngAnimate/animateQueue.js index 1b914485edba..00dd4e3e62db 100644 --- a/src/ngAnimate/animateQueue.js +++ b/src/ngAnimate/animateQueue.js @@ -388,6 +388,7 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) { // it, otherwise if it's the same then the end result will be the same too if (animationCancelled || (isStructural && animationDetails.event !== event)) { options.domOperation(); + runner.end(); } return; @@ -482,7 +483,7 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) { // animations to properly function (otherwise any CSS selectors may not work) function examineParentAnimation(node, animationDetails) { // enter/leave/move always have priority - if (animationDetails.structural) return; + if (animationDetails.structural || !hasAnimationClasses(animationDetails.options)) return; if (animationDetails.state === RUNNING_STATE) { animationDetails.runner.end(); diff --git a/test/ngAnimate/animateSpec.js b/test/ngAnimate/animateSpec.js index 5a0d730cf4ea..cf4d4fefd45a 100644 --- a/test/ngAnimate/animateSpec.js +++ b/test/ngAnimate/animateSpec.js @@ -510,16 +510,49 @@ describe("animations", function() { describe('parent animations', function() { it('should immediately end a pre-digest parent class-based animation if a structural child is active', - inject(function($rootScope, $animate) { + inject(function($rootScope, $animate, $$rAF) { parent.append(element); var child = jqLite('
'); - $animate.addClass(parent, 'abc'); + + var itsOver = false; + $animate.addClass(parent, 'abc').done(function() { + itsOver = true; + }); $animate.enter(child, element); + $$rAF.flush(); + + expect(itsOver).toBe(false); $rootScope.$digest(); expect(parent).toHaveClass('abc'); + expect(itsOver).toBe(true); + })); + + it('should not end a pre-digest parent animation if it does not have any classes to add/remove', + inject(function($rootScope, $animate, $$rAF) { + + parent.append(element); + var child = jqLite('
'); + var runner = $animate.animate(parent, + { height:'0px' }, + { height:'100px' }); + + var doneCount = 0; + runner.done(function() { + doneCount++; + }); + + var runner2 = $animate.enter(child, element); + runner2.done(function() { + doneCount++; + }); + + $rootScope.$digest(); + $$rAF.flush(); + + expect(doneCount).toBe(0); })); it('should immediately end a parent class-based animation if a structural child is active',