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

Commit 4b6b538

Browse files
committed
fix($animate): don't assume the target of pin() is $rootElement's child
1 parent 52ea411 commit 4b6b538

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/ngAnimate/animateQueue.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,9 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
631631
if (!rootElementDetected) {
632632
parentHost = parentElement.data(NG_ANIMATE_PIN_DATA);
633633
if (parentHost) {
634+
// The pin target element becomes the parent element
634635
parentElement = parentHost;
635-
rootElementDetected = true;
636+
rootElementDetected = isMatchingElement(parentElement, $rootElement);
636637
}
637638
}
638639
}

test/ngAnimate/animateSpec.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,49 @@ describe("animations", function() {
15431543
});
15441544
});
15451545

1546+
they('should not animate an element when the pinned element (which is the $prop element), is pinned to an element that is not a child of the $rootElement',
1547+
['same', 'parent', 'grandparent'],
1548+
function(elementRelation) {
1549+
inject(function($animate, $compile, $document, $rootElement, $rootScope) {
1550+
1551+
var pinElement, animateElement, pinTargetElement = jqLite('<div></div>');
1552+
1553+
var innerParent = jqLite('<div></div>');
1554+
jqLite($document[0].body).append(innerParent);
1555+
innerParent.append($rootElement);
1556+
1557+
switch (elementRelation) {
1558+
case 'same':
1559+
pinElement = jqLite('<div id="animate"></div>');
1560+
break;
1561+
case 'parent':
1562+
pinElement = jqLite('<div><div id="animate"></div></div>');
1563+
break;
1564+
case 'grandparent':
1565+
pinElement = jqLite('<div><div><div id="animate"></div></div></div>');
1566+
break;
1567+
}
1568+
1569+
// Append both the pin element and the pinTargetElement outside the app root
1570+
jqLite($document[0].body).append(pinElement);
1571+
jqLite($document[0].body).append(pinTargetElement);
1572+
1573+
animateElement = jqLite($document[0].getElementById('animate'));
1574+
1575+
$animate.addClass(animateElement, 'red');
1576+
$rootScope.$digest();
1577+
expect(capturedAnimation).toBeFalsy();
1578+
1579+
$animate.pin(pinElement, pinTargetElement);
1580+
1581+
$animate.addClass(animateElement, 'blue');
1582+
$rootScope.$digest();
1583+
expect(capturedAnimation).toBeFalsy();
1584+
1585+
dealoc(pinElement);
1586+
});
1587+
});
1588+
15461589
it('should adhere to the disabled state of the hosted parent when an element is pinned',
15471590
inject(function($animate, $compile, $document, $rootElement, $rootScope) {
15481591

0 commit comments

Comments
 (0)