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

Commit

Permalink
fix($animate): allow enabled children to animate on disabled parents
Browse files Browse the repository at this point in the history
Prior to this fix if a parent container disabled animations for
itself then no children could be enabled explicity via
`$animate.enabled`. This patch allows for that to work.

Closes #13179
Closes #13695
  • Loading branch information
matsko authored and Narretz committed Jan 9, 2016
1 parent 0afd775 commit 6d85f24
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/ngAnimate/animateQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,7 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
bool = !recordExists;
} else {
// (element, bool) - Element setter
bool = !!bool;
if (!bool) {
disabledElementsLookup.put(node, true);
} else if (recordExists) {
disabledElementsLookup.remove(node);
}
disabledElementsLookup.put(node, !bool);
}
}
}
Expand Down Expand Up @@ -580,6 +575,7 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
var rootElementDetected = isMatchingElement(element, $rootElement);
var parentAnimationDetected = false;
var animateChildren;
var elementDisabled = disabledElementsLookup.get(getDomNode(element));

var parentHost = element.data(NG_ANIMATE_PIN_DATA);
if (parentHost) {
Expand All @@ -604,7 +600,16 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
// therefore we can't allow any animations to take place
// but if a parent animation is class-based then that's ok
if (!parentAnimationDetected) {
parentAnimationDetected = details.structural || disabledElementsLookup.get(parentNode);
var parentElementDisabled = disabledElementsLookup.get(parentNode);

// disable animations if the user hasn't explicitly enabled animations on the
// current element
if (parentElementDisabled === true && elementDisabled !== false) {
elementDisabled = true;
} else if (parentElementDisabled === false) {
elementDisabled = false;
}
parentAnimationDetected = details.structural;
}

if (isUndefined(animateChildren) || animateChildren === true) {
Expand Down Expand Up @@ -639,7 +644,7 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
parentElement = parentElement.parent();
}

var allowAnimation = !parentAnimationDetected || animateChildren;
var allowAnimation = (!parentAnimationDetected || animateChildren) && elementDisabled !== true;
return allowAnimation && rootElementDetected && bodyElementDetected;
}

Expand Down
29 changes: 29 additions & 0 deletions test/ngAnimate/animateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,35 @@ describe("animations", function() {
$rootScope.$digest();
expect(capturedAnimation).toBeTruthy();
}));

it('should run animations on an element and its children if explicitly enabled, even if animations are disabled on the parent',
inject(function($animate, $rootScope) {

var child = jqLite('<div></div>');
element.append(child);
parent.append(element);

$animate.enabled(parent, false);

$animate.addClass(element, 'red');
$rootScope.$digest();
expect(capturedAnimation).toBeFalsy();

$animate.addClass(child, 'red');
$rootScope.$digest();
expect(capturedAnimation).toBeFalsy();

$animate.enabled(element, true);

$animate.addClass(element, 'blue');
$rootScope.$digest();
expect(capturedAnimation).toBeTruthy();
capturedAnimation = null;

$animate.addClass(child, 'blue');
$rootScope.$digest();
expect(capturedAnimation).toBeTruthy();
}));
});

it('should strip all comment nodes from the animation and not issue an animation if not real elements are found',
Expand Down

0 comments on commit 6d85f24

Please sign in to comment.