Skip to content

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 angular#13179
Closes angular#13695
  • Loading branch information
matsko committed Jan 6, 2016
1 parent 495d40d commit 12ab1fa
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/ngAnimate/animateQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,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 @@ -574,6 +569,17 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
var parentAnimationDetected = false;
var animateChildren;

var PARENT_STATE_DISABLED = 1;
var PARENT_STATE_ENABLED = 2;
var parentElementDisabledState = 0;

var elementDisabledStatus = disabledElementsLookup.get(getDomNode(element));
if (elementDisabledStatus === true) {
parentElementDisabledState = PARENT_STATE_DISABLED;
} else if (elementDisabledStatus === false) {
parentElementDisabledState = PARENT_STATE_ENABLED;
}

var parentHost = element.data(NG_ANIMATE_PIN_DATA);
if (parentHost) {
parentElement = parentHost;
Expand All @@ -597,7 +603,15 @@ 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 disabledStatus = disabledElementsLookup.get(parentNode);

// the user has `explicitly` allowed for animations to be enabled on this container
if (disabledStatus === true && parentElementDisabledState != PARENT_STATE_ENABLED) {
parentElementDisabledState = PARENT_STATE_DISABLED;
} else if (disabledStatus === false) {
parentElementDisabledState = PARENT_STATE_ENABLED;
}
parentAnimationDetected = details.structural;
}

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

var allowAnimation = !parentAnimationDetected || animateChildren;
var allowAnimation = (!parentAnimationDetected || animateChildren) && parentElementDisabledState != PARENT_STATE_DISABLED;
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();
}));

iit('should enable animations on the child element if explicitly allowed 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 12ab1fa

Please sign in to comment.