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

fix($animate): $animate.enabled(false) should disable animations on $animateCss as well #12696

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/ngAnimate/animateCss.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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();
}

Expand Down Expand Up @@ -930,6 +930,6 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
}
}
}
}
};
}];
}];
20 changes: 19 additions & 1 deletion test/ngAnimate/animateCssSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down Expand Up @@ -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('<div></div>');
$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) {

Expand Down