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

Commit c3d5e33

Browse files
committed
fix($animate): $animate.enabled(false) should disable animations on $animateCss as well
Closes #12696 Closes #12685
1 parent 2f6b6fb commit c3d5e33

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/ngAnimate/animateCss.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
328328
var gcsLookup = createLocalCacheLookup();
329329
var gcsStaggerLookup = createLocalCacheLookup();
330330

331-
this.$get = ['$window', '$$jqLite', '$$AnimateRunner', '$timeout', '$$forceReflow', '$sniffer', '$$rAF',
332-
function($window, $$jqLite, $$AnimateRunner, $timeout, $$forceReflow, $sniffer, $$rAF) {
331+
this.$get = ['$window', '$$jqLite', '$$AnimateRunner', '$timeout', '$$forceReflow', '$sniffer', '$$rAF', '$animate',
332+
function($window, $$jqLite, $$AnimateRunner, $timeout, $$forceReflow, $sniffer, $$rAF, $animate) {
333333

334334
var applyAnimationClasses = applyAnimationClassesFactory($$jqLite);
335335

@@ -411,8 +411,6 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
411411
});
412412
}
413413

414-
return init;
415-
416414
function computeTimings(node, className, cacheKey) {
417415
var timings = computeCachedCssStyles(node, className, cacheKey, DETECT_CSS_PROPERTIES);
418416
var aD = timings.animationDelay;
@@ -427,9 +425,11 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
427425
return timings;
428426
}
429427

430-
function init(element, options) {
428+
return function init(element, options) {
431429
var node = getDomNode(element);
432-
if (!node || !node.parentNode) {
430+
if (!node
431+
|| !node.parentNode
432+
|| !$animate.enabled()) {
433433
return closeAndReturnNoopAnimator();
434434
}
435435

@@ -930,6 +930,6 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
930930
}
931931
}
932932
}
933-
}
933+
};
934934
}];
935935
}];

test/ngAnimate/animateCssSpec.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ describe("ngAnimate $animateCss", function() {
1818

1919
var ss, prefix, triggerAnimationStartFrame;
2020
beforeEach(module(function() {
21-
return function($document, $window, $sniffer, $$rAF) {
21+
return function($document, $window, $sniffer, $$rAF, $animate) {
2222
prefix = '-' + $sniffer.vendorPrefix.toLowerCase() + '-';
2323
ss = createMockStyleSheet($document, $window);
24+
$animate.enabled(true);
2425
triggerAnimationStartFrame = function() {
2526
$$rAF.flush();
2627
};
@@ -52,6 +53,23 @@ describe("ngAnimate $animateCss", function() {
5253
describe('when active', function() {
5354
if (!browserSupportsCssAnimations()) return;
5455

56+
it("should not attempt an animation if animations are globally disabled",
57+
inject(function($animateCss, $animate, $rootElement, $$body) {
58+
59+
$animate.enabled(false);
60+
61+
var animator, element = jqLite('<div></div>');
62+
$rootElement.append(element);
63+
$$body.append($rootElement);
64+
65+
animator = $animateCss(element, {
66+
duration: 10,
67+
to: { 'height': '100px' }
68+
});
69+
70+
expect(animator.$$willAnimate).toBeFalsy();
71+
}));
72+
5573
it("should silently quit the animation and not throw when an element has no parent during preparation",
5674
inject(function($animateCss, $rootScope, $document, $rootElement) {
5775

0 commit comments

Comments
 (0)