Skip to content

Commit

Permalink
fix(ngAnimate): ensure that animations work when the app is bootstrap…
Browse files Browse the repository at this point in the history
…ped on the document node

Closes angular#11574
  • Loading branch information
matsko committed Apr 14, 2015
1 parent 2a156c2 commit 647aad5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/ngAnimate/animateQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,12 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
var animateChildren;

while (parent && parent.length) {
if (!rootElementDetected) {
// angular doesn't want to attempt to animate elements outside of the application
// therefore we need to ensure that the rootElement is an ancestor of the current element
rootElementDetected = isMatchingElement(parent, $rootElement);
}

var parentNode = parent[0];
if (parentNode.nodeType !== ELEMENT_NODE) {
// no point in inspecting the #document element
Expand All @@ -515,12 +521,6 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
// there is no need to continue traversing at this point
if (parentAnimationDetected && animateChildren === false) break;

if (!rootElementDetected) {
// angular doesn't want to attempt to animate elements outside of the application
// therefore we need to ensure that the rootElement is an ancestor of the current element
rootElementDetected = isMatchingElement(parent, $rootElement);
}

if (!bodyElementDetected) {
// we also need to ensure that the element is or will be apart of the body element
// otherwise it is pointless to even issue an animation to be rendered
Expand Down
27 changes: 27 additions & 0 deletions test/ngAnimate/animateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,33 @@ describe("animations", function() {
dealoc(element);
}));

it('should allow animations if the application is bootstrapped on the document node', function() {
var capturedAnimation;

module(function($provide) {
$provide.factory('$rootElement', function($document) {
return $document;
});
$provide.factory('$$animation', function($$AnimateRunner) {
return function() {
capturedAnimation = arguments;
return new $$AnimateRunner();
};
});
});

inject(function($animate, $rootScope, $document) {
$animate.enabled(true);

element = jqLite('<div></div>');

$animate.enter(element, jqLite($document[0].body));
$rootScope.$digest();

expect(capturedAnimation).toBeTruthy();
});
});

describe('during bootstrap', function() {
it('should be enabled only after the first digest is fired and the postDigest queue is empty',
inject(function($animate, $rootScope) {
Expand Down

0 comments on commit 647aad5

Please sign in to comment.