From 2aa14f646fda7aeb16c00f25bce8541e96a95080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Thu, 27 Aug 2015 14:17:55 -0700 Subject: [PATCH] fix($animate): `$animate.enabled(false)` should disable animations on $animateCss as well Closes #12696 Closes #12685 --- src/ngAnimate/animateCss.js | 14 +++++++------- test/ngAnimate/animateCssSpec.js | 20 +++++++++++++++++++- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/ngAnimate/animateCss.js b/src/ngAnimate/animateCss.js index 8570ea313798..01140640f041 100644 --- a/src/ngAnimate/animateCss.js +++ b/src/ngAnimate/animateCss.js @@ -328,8 +328,8 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) { var gcsLookup = createLocalCacheLookup(); var gcsStaggerLookup = createLocalCacheLookup(); - this.$get = ['$window', '$$jqLite', '$$AnimateRunner', '$timeout', '$$forceReflow', '$sniffer', '$$rAF', - function($window, $$jqLite, $$AnimateRunner, $timeout, $$forceReflow, $sniffer, $$rAF) { + this.$get = ['$window', '$$jqLite', '$$AnimateRunner', '$timeout', '$$forceReflow', '$sniffer', '$$rAF', '$animate', + function($window, $$jqLite, $$AnimateRunner, $timeout, $$forceReflow, $sniffer, $$rAF, $animate) { var applyAnimationClasses = applyAnimationClassesFactory($$jqLite); @@ -411,8 +411,6 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) { }); } - return init; - function computeTimings(node, className, cacheKey) { var timings = computeCachedCssStyles(node, className, cacheKey, DETECT_CSS_PROPERTIES); var aD = timings.animationDelay; @@ -427,9 +425,11 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) { return timings; } - function init(element, options) { + return function init(element, options) { var node = getDomNode(element); - if (!node || !node.parentNode) { + if (!node + || !node.parentNode + || !$animate.enabled()) { return closeAndReturnNoopAnimator(); } @@ -930,6 +930,6 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) { } } } - } + }; }]; }]; diff --git a/test/ngAnimate/animateCssSpec.js b/test/ngAnimate/animateCssSpec.js index 6a68556e298b..a4071782ab43 100644 --- a/test/ngAnimate/animateCssSpec.js +++ b/test/ngAnimate/animateCssSpec.js @@ -18,9 +18,10 @@ describe("ngAnimate $animateCss", function() { var ss, prefix, triggerAnimationStartFrame; beforeEach(module(function() { - return function($document, $window, $sniffer, $$rAF) { + return function($document, $window, $sniffer, $$rAF, $animate) { prefix = '-' + $sniffer.vendorPrefix.toLowerCase() + '-'; ss = createMockStyleSheet($document, $window); + $animate.enabled(true); triggerAnimationStartFrame = function() { $$rAF.flush(); }; @@ -52,6 +53,23 @@ describe("ngAnimate $animateCss", function() { describe('when active', function() { if (!browserSupportsCssAnimations()) return; + it("should not attempt an animation if animations are globally disabled", + inject(function($animateCss, $animate, $rootElement, $$body) { + + $animate.enabled(false); + + var animator, element = jqLite('
'); + $rootElement.append(element); + $$body.append($rootElement); + + animator = $animateCss(element, { + duration: 10, + to: { 'height': '100px' } + }); + + expect(animator.$$willAnimate).toBeFalsy(); + })); + it("should silently quit the animation and not throw when an element has no parent during preparation", inject(function($animateCss, $rootScope, $document, $rootElement) {