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

fix($animate): allow enabled children to animate on disabled parents #13721

Merged
merged 1 commit into from
Jan 9, 2016
Merged
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
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