Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 8fc31c2

Browse files
committed
fix($animate): cancel fallback timeout when animation ends normally
1 parent 52ea411 commit 8fc31c2

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)