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

Commit 2efe823

Browse files
committed
fix($animate): ensure blocked keyframe animations are unblocked before the DOM operation
Closes #5106
1 parent a090400 commit 2efe823

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

src/ngAnimate/animate.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,10 @@ angular.module('ngAnimate', ['ng'])
10321032
}
10331033

10341034
function unblockKeyframeAnimations(element) {
1035-
element[0].style[ANIMATION_PROP] = '';
1035+
var node = element[0], prop = ANIMATION_PROP;
1036+
if(node.style[prop] && node.style[prop].length > 0) {
1037+
element[0].style[prop] = '';
1038+
}
10361039
}
10371040

10381041
function animateRun(element, className, activeAnimationComplete) {
@@ -1063,8 +1066,6 @@ angular.module('ngAnimate', ['ng'])
10631066
appliedStyles.push(CSS_PREFIX + 'transition-property');
10641067
appliedStyles.push(CSS_PREFIX + 'transition-duration');
10651068
}
1066-
} else {
1067-
unblockKeyframeAnimations(element);
10681069
}
10691070

10701071
if(ii > 0) {
@@ -1167,6 +1168,7 @@ angular.module('ngAnimate', ['ng'])
11671168
var cancel = preReflowCancellation;
11681169
afterReflow(function() {
11691170
unblockTransitions(element);
1171+
unblockKeyframeAnimations(element);
11701172
//once the reflow is complete then we point cancel to
11711173
//the new cancellation function which will remove all of the
11721174
//animation properties from the active animation
@@ -1232,6 +1234,7 @@ angular.module('ngAnimate', ['ng'])
12321234
if(cancellationMethod) {
12331235
afterReflow(function() {
12341236
unblockTransitions(element);
1237+
unblockKeyframeAnimations(element);
12351238
animationCompleted();
12361239
});
12371240
return cancellationMethod;
@@ -1248,6 +1251,7 @@ angular.module('ngAnimate', ['ng'])
12481251
if(cancellationMethod) {
12491252
afterReflow(function() {
12501253
unblockTransitions(element);
1254+
unblockKeyframeAnimations(element);
12511255
animationCompleted();
12521256
});
12531257
return cancellationMethod;

test/ngAnimate/animateSpec.js

+43
Original file line numberDiff line numberDiff line change
@@ -2771,4 +2771,47 @@ describe("ngAnimate", function() {
27712771

27722772
expect(node.style[animationKey]).not.toContain('none');
27732773
}));
2774+
2775+
it('should block and unblock keyframe animations before the followup JS animation occurs', function() {
2776+
module(function($animateProvider) {
2777+
$animateProvider.register('.special', function($sniffer, $window) {
2778+
var prop = $sniffer.vendorPrefix == 'Webkit' ? 'WebkitAnimation' : 'animation';
2779+
return {
2780+
beforeAddClass : function(element, className, done) {
2781+
expect(element[0].style[prop]).not.toContain('none');
2782+
expect($window.getComputedStyle(element[0])[prop + 'Duration']).toBe('1s');
2783+
done();
2784+
},
2785+
addClass : function(element, className, done) {
2786+
expect(element[0].style[prop]).not.toContain('none');
2787+
expect($window.getComputedStyle(element[0])[prop + 'Duration']).toBe('1s');
2788+
done();
2789+
}
2790+
}
2791+
});
2792+
});
2793+
inject(function($rootScope, $compile, $rootElement, $document, $animate, $sniffer, $timeout, $window) {
2794+
if (!$sniffer.animations) return;
2795+
2796+
$animate.enabled(true);
2797+
2798+
ss.addRule('.special', '-webkit-animation:1s special_animation;' +
2799+
'animation:1s special_animation;');
2800+
2801+
var capturedProperty = 'none';
2802+
2803+
var element = $compile('<div class="special"></div>')($rootScope);
2804+
$rootElement.append(element);
2805+
jqLite($document[0].body).append($rootElement);
2806+
2807+
$animate.addClass(element, 'some-klass');
2808+
2809+
var prop = $sniffer.vendorPrefix == 'Webkit' ? 'WebkitAnimation' : 'animation';
2810+
2811+
expect(element[0].style[prop]).toContain('none');
2812+
expect($window.getComputedStyle(element[0])[prop + 'Duration']).toBe('0s');
2813+
2814+
$timeout.flush();
2815+
});
2816+
});
27742817
});

0 commit comments

Comments
 (0)