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

Commit dc88816

Browse files
committed
fix($animateCss): don't unregister events when none 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 e4e5677 commit dc88816

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/ngAnimate/animateCss.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
750750
}
751751

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

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)