From 4b6b5382e891af9422cf6c0835779654ea73a32d Mon Sep 17 00:00:00 2001 From: Martin Staffa Date: Tue, 12 Jan 2016 16:00:18 +0100 Subject: [PATCH] fix($animate): don't assume the target of pin() is $rootElement's child --- src/ngAnimate/animateQueue.js | 3 ++- test/ngAnimate/animateSpec.js | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/ngAnimate/animateQueue.js b/src/ngAnimate/animateQueue.js index d69eae33dee7..bf92b55544e6 100644 --- a/src/ngAnimate/animateQueue.js +++ b/src/ngAnimate/animateQueue.js @@ -631,8 +631,9 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) { if (!rootElementDetected) { parentHost = parentElement.data(NG_ANIMATE_PIN_DATA); if (parentHost) { + // The pin target element becomes the parent element parentElement = parentHost; - rootElementDetected = true; + rootElementDetected = isMatchingElement(parentElement, $rootElement); } } } diff --git a/test/ngAnimate/animateSpec.js b/test/ngAnimate/animateSpec.js index d281d0abfe0f..770d4907c694 100644 --- a/test/ngAnimate/animateSpec.js +++ b/test/ngAnimate/animateSpec.js @@ -1543,6 +1543,49 @@ describe("animations", function() { }); }); + 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', + ['same', 'parent', 'grandparent'], + function(elementRelation) { + inject(function($animate, $compile, $document, $rootElement, $rootScope) { + + var pinElement, animateElement, pinTargetElement = jqLite('
'); + + var innerParent = jqLite('
'); + jqLite($document[0].body).append(innerParent); + innerParent.append($rootElement); + + switch (elementRelation) { + case 'same': + pinElement = jqLite('
'); + break; + case 'parent': + pinElement = jqLite('
'); + break; + case 'grandparent': + pinElement = jqLite('
'); + break; + } + + // Append both the pin element and the pinTargetElement outside the app root + jqLite($document[0].body).append(pinElement); + jqLite($document[0].body).append(pinTargetElement); + + animateElement = jqLite($document[0].getElementById('animate')); + + $animate.addClass(animateElement, 'red'); + $rootScope.$digest(); + expect(capturedAnimation).toBeFalsy(); + + $animate.pin(pinElement, pinTargetElement); + + $animate.addClass(animateElement, 'blue'); + $rootScope.$digest(); + expect(capturedAnimation).toBeFalsy(); + + dealoc(pinElement); + }); + }); + it('should adhere to the disabled state of the hosted parent when an element is pinned', inject(function($animate, $compile, $document, $rootElement, $rootScope) {