Skip to content

Commit e9c406b

Browse files
committed
fix($animateCss): cancel fallback timeout when animation ends normally
Previously, css animations would not cancel the timeout when the animation ends normally (calling end explicitly / transitionEnd event). This meant that the timeout callback fn was always called after 150% of the animation time was over. Since the animation was already closed at this point, it would not do any work twice, but simply remove the timer data from the element. This commit changes the behavior to cancel the timeout and remove the data when it is found during animation closing. Closes angular#13787
1 parent 79b6d55 commit e9c406b

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/ngAnimate/animateCss.js

+7
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,13 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
756756
element.off(events.join(' '), onAnimationProgress);
757757
}
758758

759+
//Cancel the fallback closing timeout and remove the timer data
760+
var animationTimerData = element.data(ANIMATE_TIMER_KEY);
761+
if (animationTimerData) {
762+
$timeout.cancel(animationTimerData[0].timer);
763+
element.removeData(ANIMATE_TIMER_KEY);
764+
}
765+
759766
// if the preparation function fails then the promise is not setup
760767
if (runner) {
761768
runner.complete(!rejected);

test/ngAnimate/.jshintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"TRANSITIONEND_EVENT": false,
1313
"TRANSITION_PROP": false,
1414
"ANIMATION_PROP": false,
15-
"ANIMATIONEND_EVENT": false
15+
"ANIMATIONEND_EVENT": false,
16+
"ANIMATE_TIMER_KEY": false
1617
}
1718
}

test/ngAnimate/animateCssSpec.js

+23
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,29 @@ describe("ngAnimate $animateCss", function() {
13091309
expect(getPossiblyPrefixedStyleValue(element, 'transition-delay')).toBeOneOf('', '0s');
13101310
}));
13111311

1312+
1313+
it("should cancel the timeout when the animation is ended normally",
1314+
inject(function($animateCss, $document, $rootElement, $timeout) {
1315+
1316+
ss.addRule('.ng-enter', 'transition:10s linear all;');
1317+
1318+
var element = jqLite('<div></div>');
1319+
$rootElement.append(element);
1320+
jqLite($document[0].body).append($rootElement);
1321+
1322+
var animator = $animateCss(element, { event: 'enter', structural: true });
1323+
animator.start();
1324+
triggerAnimationStartFrame();
1325+
1326+
expect(element).toHaveClass('ng-enter');
1327+
expect(element).toHaveClass('ng-enter-active');
1328+
1329+
animator.end();
1330+
1331+
expect(element.data(ANIMATE_TIMER_KEY)).toBeUndefined();
1332+
expect(function() {$timeout.verifyNoPendingTasks();}).not.toThrow();
1333+
}));
1334+
13121335
});
13131336

13141337
describe("getComputedStyle", function() {

0 commit comments

Comments
 (0)