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

Commit 959f2bb

Browse files
committed
fix($animateCss): only (de)register listeners when events have been added
Previously, when an animation was closed because no animation styles where found, it would call .off() with an empty string as the argument. For both jquery/jqlite this is the same as calling .off() without any argument, which deregisters all event listeners on an element. Closes #13514
1 parent 6a47c0d commit 959f2bb

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

src/ngAnimate/animateCss.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,8 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
749749
options.onDone();
750750
}
751751

752-
// Remove the transitionend / animationend listener(s)
753-
if (events) {
752+
if (events && events.length) {
753+
// Remove the transitionend / animationend listener(s)
754754
element.off(events.join(' '), onAnimationProgress);
755755
}
756756

@@ -960,7 +960,10 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
960960
element.data(ANIMATE_TIMER_KEY, animationsData);
961961
}
962962

963-
element.on(events.join(' '), onAnimationProgress);
963+
if (events.length) {
964+
element.on(events.join(' '), onAnimationProgress);
965+
}
966+
964967
if (options.to) {
965968
if (options.cleanupStyles) {
966969
registerRestorableStyles(restoreStyles, node, Object.keys(options.to));

test/ngAnimate/animateCssSpec.js

+33
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,39 @@ describe("ngAnimate $animateCss", function() {
15021502
expect(elementOffSpy.mostRecentCall.args[0]).toBe(event);
15031503
});
15041504
});
1505+
1506+
they("should not add or remove $prop event listeners when no animation styles are detected",
1507+
[TRANSITIONEND_EVENT, ANIMATIONEND_EVENT], function(event) {
1508+
inject(function($animateCss, $timeout) {
1509+
1510+
progress = event === TRANSITIONEND_EVENT ? transitionProgress : keyframeProgress;
1511+
1512+
// Make sure other event listeners are not affected
1513+
var otherEndSpy = jasmine.createSpy('otherEndSpy');
1514+
element.on(event, otherEndSpy);
1515+
1516+
expect(elementOnSpy).toHaveBeenCalledOnce();
1517+
elementOnSpy.reset();
1518+
1519+
var animator = $animateCss(element, {
1520+
event: 'enter',
1521+
structural: true
1522+
});
1523+
1524+
expect(animator.$$willAnimate).toBeFalsy();
1525+
1526+
// This will close the animation because no styles have been detected
1527+
var runner = animator.start();
1528+
triggerAnimationStartFrame();
1529+
1530+
expect(elementOnSpy).not.toHaveBeenCalled();
1531+
expect(elementOffSpy).not.toHaveBeenCalled();
1532+
1533+
progress(element, 10);
1534+
expect(otherEndSpy).toHaveBeenCalledOnce();
1535+
});
1536+
});
1537+
15051538
});
15061539
});
15071540

0 commit comments

Comments
 (0)