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

Commit

Permalink
fix($animateCss): don't unregister events when none have been added
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Narretz committed Dec 11, 2015
1 parent e4e5677 commit dc88816
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ngAnimate/animateCss.js
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
}

// Remove the transitionend / animationend listener(s)
if (events) {
if (events && events.length) {
element.off(events.join(' '), onAnimationProgress);
}

Expand Down
33 changes: 33 additions & 0 deletions test/ngAnimate/animateCssSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,39 @@ describe("ngAnimate $animateCss", function() {
expect(elementOffSpy.mostRecentCall.args[0]).toBe(event);
});
});

they("should not add or remove $prop event listeners when no animation styles are detected",
[TRANSITIONEND_EVENT, ANIMATIONEND_EVENT], function(event) {
inject(function($animateCss, $timeout) {

progress = event === TRANSITIONEND_EVENT ? transitionProgress : keyframeProgress;

// Make sure other event listeners are not affected
var otherEndSpy = jasmine.createSpy('otherEndSpy');
element.on(event, otherEndSpy);

expect(elementOnSpy).toHaveBeenCalledOnce();
elementOnSpy.reset();

var animator = $animateCss(element, {
event: 'enter',
structural: true
});

expect(animator.$$willAnimate).toBeFalsy();

// This will close the animation because no styles have been detected
var runner = animator.start();
triggerAnimationStartFrame();

expect(elementOnSpy).not.toHaveBeenCalled();
expect(elementOffSpy).not.toHaveBeenCalled();

progress(element, 10);
expect(otherEndSpy).toHaveBeenCalledOnce();
});
});

});
});

Expand Down

0 comments on commit dc88816

Please sign in to comment.