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

Commit e18db78

Browse files
airatomatsko
authored andcommitted
fix($animate): remove the ng-animate className after canceling animation
Closes #7784 Closes #7801 Closes #7894
1 parent ca75279 commit e18db78

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

src/ngAnimate/animate.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -975,10 +975,9 @@ angular.module('ngAnimate', ['ng'])
975975
//cancel all animations when a structural animation takes place
976976
for(var klass in runningAnimations) {
977977
animationsToCancel.push(runningAnimations[klass]);
978-
cleanup(element, klass);
979978
}
980-
runningAnimations = {};
981-
totalActiveAnimations = 0;
979+
ngAnimateState = {};
980+
cleanup(element, true);
982981
}
983982
} else if(lastAnimation.event == 'setClass') {
984983
animationsToCancel.push(lastAnimation);
@@ -1001,6 +1000,9 @@ angular.module('ngAnimate', ['ng'])
10011000
}
10021001
}
10031002

1003+
runningAnimations = ngAnimateState.active || {};
1004+
totalActiveAnimations = ngAnimateState.totalActive || 0;
1005+
10041006
if(runner.isClassBased && !runner.isSetClassOperation && !skipAnimation) {
10051007
skipAnimation = (animationEvent == 'addClass') == element.hasClass(className); //opposite of XOR
10061008
}

test/ngAnimate/animateSpec.js

+40
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,46 @@ describe("ngAnimate", function() {
783783
expect(child.hasClass('animation-cancelled')).toBe(true);
784784
}));
785785

786+
it("should remove the .ng-animate class after the next animation is run which interrupted the last animation", function() {
787+
var addClassDone, removeClassDone,
788+
addClassDoneSpy = jasmine.createSpy(),
789+
removeClassDoneSpy = jasmine.createSpy();
790+
791+
module(function($animateProvider) {
792+
$animateProvider.register('.hide', function() {
793+
return {
794+
addClass : function(element, className, done) {
795+
addClassDone = done;
796+
return addClassDoneSpy;
797+
},
798+
removeClass : function(element, className, done) {
799+
removeClassDone = done;
800+
return removeClassDoneSpy;
801+
}
802+
};
803+
});
804+
});
805+
806+
inject(function($animate, $rootScope, $sniffer, $timeout) {
807+
$animate.addClass(element, 'hide');
808+
809+
expect(element).toHaveClass('ng-animate');
810+
811+
$animate.triggerReflow();
812+
813+
$animate.removeClass(element, 'hide');
814+
expect(addClassDoneSpy).toHaveBeenCalled();
815+
816+
$animate.triggerReflow();
817+
818+
expect(element).toHaveClass('ng-animate');
819+
820+
removeClassDone();
821+
$animate.triggerCallbacks();
822+
823+
expect(element).not.toHaveClass('ng-animate');
824+
});
825+
});
786826

787827
it("should skip a class-based animation if the same element already has an ongoing structural animation",
788828
inject(function($animate, $rootScope, $sniffer, $timeout) {

0 commit comments

Comments
 (0)