Skip to content

Commit

Permalink
fix($animate): ensure that parallel class-based animations are all ev…
Browse files Browse the repository at this point in the history
…entually closed

When multiple classes are added/removed in parallel then $animate only closes off the
last animation when the fallback timer has expired. Now all animations are closed off.

Fixes angular#7766
  • Loading branch information
matsko committed Jun 10, 2014
1 parent e4419da commit 749610c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/ngAnimate/animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,9 @@ angular.module('ngAnimate', ['ng'])
forEach(elements, function(element) {
var elementData = element.data(NG_ANIMATE_CSS_DATA_KEY);
if(elementData) {
(elementData.closeAnimationFn || noop)();
forEach(elementData.closeAnimationFns, function(fn) {
fn();
});
}
});
}
Expand Down Expand Up @@ -1357,14 +1359,15 @@ angular.module('ngAnimate', ['ng'])
stagger.animationDelay > 0 &&
stagger.animationDuration === 0;

var closeAnimationFns = formerData.closeAnimationFns || [];
element.data(NG_ANIMATE_CSS_DATA_KEY, {
stagger : stagger,
cacheKey : eventCacheKey,
running : formerData.running || 0,
itemIndex : itemIndex,
blockTransition : blockTransition,
blockAnimation : blockAnimation,
closeAnimationFn : noop
closeAnimationFns : closeAnimationFns
});

var node = extractElementNode(element);
Expand Down Expand Up @@ -1456,10 +1459,10 @@ angular.module('ngAnimate', ['ng'])
var css3AnimationEvents = ANIMATIONEND_EVENT + ' ' + TRANSITIONEND_EVENT;

element.on(css3AnimationEvents, onAnimationProgress);
elementData.closeAnimationFn = function() {
elementData.closeAnimationFns.push(function() {
onEnd();
activeAnimationComplete();
};
});

var staggerTime = itemIndex * (Math.max(stagger.animationDelay, stagger.transitionDelay) || 0);
var animationTime = (maxDelay + maxDuration) * CLOSING_TIME_BUFFER;
Expand Down
26 changes: 26 additions & 0 deletions test/ngAnimate/animateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,32 @@ describe("ngAnimate", function() {
});
});

it('should apply a closing timeout to close all parallel class-based animations on the same element',
inject(function($sniffer, $compile, $rootScope, $rootElement, $animate, $timeout) {

if (!$sniffer.transitions) return;

ss.addRule('.base-class', '-webkit-transition:2s linear all;' +
'transition:2s linear all;');

var element = $compile('<div class="base-class"></div>')($rootScope);
$rootElement.append(element);
jqLite($document[0].body).append($rootElement);

$animate.addClass(element, 'one');
$animate.addClass(element, 'two');

$animate.triggerReflow();

$timeout.flush(3000); //2s * 1.5

expect(element.hasClass('one-add')).toBeFalsy();
expect(element.hasClass('one-add-active')).toBeFalsy();
expect(element.hasClass('two-add')).toBeFalsy();
expect(element.hasClass('two-add-active')).toBeFalsy();
expect(element.hasClass('ng-animate')).toBeFalsy();
}));

it("apply a closing timeout with respect to a staggering animation",
inject(function($animate, $rootScope, $compile, $sniffer, $timeout) {

Expand Down

0 comments on commit 749610c

Please sign in to comment.