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

Animation Fixes #12881

Closed
wants to merge 2 commits into from
Closed
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
1 change: 0 additions & 1 deletion angularFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ var angularFiles = {
'angularModules': {
'ngAnimate': [
'src/ngAnimate/shared.js',
'src/ngAnimate/body.js',
'src/ngAnimate/rafScheduler.js',
'src/ngAnimate/animateChildrenDirective.js',
'src/ngAnimate/animateCss.js',
Expand Down
17 changes: 13 additions & 4 deletions src/ngAnimate/animateCssDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,25 @@ var $$AnimateCssDriverProvider = ['$$animationProvider', function($$animationPro
var NG_OUT_ANCHOR_CLASS_NAME = 'ng-anchor-out';
var NG_IN_ANCHOR_CLASS_NAME = 'ng-anchor-in';

this.$get = ['$animateCss', '$rootScope', '$$AnimateRunner', '$rootElement', '$$body', '$sniffer', '$$jqLite',
function($animateCss, $rootScope, $$AnimateRunner, $rootElement, $$body, $sniffer, $$jqLite) {
function isDocumentFragment(node) {
return node.parentNode && node.parentNode.nodeType === 11;
}

this.$get = ['$animateCss', '$rootScope', '$$AnimateRunner', '$rootElement', '$sniffer', '$$jqLite', '$document',
function($animateCss, $rootScope, $$AnimateRunner, $rootElement, $sniffer, $$jqLite, $document) {

// only browsers that support these properties can render animations
if (!$sniffer.animations && !$sniffer.transitions) return noop;

var bodyNode = getDomNode($$body);
var bodyNode = $document[0].body;
var rootNode = getDomNode($rootElement);

var rootBodyElement = jqLite(bodyNode.parentNode === rootNode ? bodyNode : rootNode);
var rootBodyElement = jqLite(
// this is to avoid using something that sites outside of the body
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sites? should this be lives or exists?

// we also special case the doc fragement case because our unit test code
// appens the $rootElement to the body after the app has been bootstrapped
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appens -> appends

isDocumentFragment(rootNode) || bodyNode.contains(rootNode) ? rootNode : bodyNode
);

var applyAnimationClasses = applyAnimationClassesFactory($$jqLite);

Expand Down
9 changes: 5 additions & 4 deletions src/ngAnimate/animateQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
return (nO.addClass && nO.addClass === cO.removeClass) || (nO.removeClass && nO.removeClass === cO.addClass);
});

this.$get = ['$$rAF', '$rootScope', '$rootElement', '$document', '$$body', '$$HashMap',
this.$get = ['$$rAF', '$rootScope', '$rootElement', '$document', '$$HashMap',
'$$animation', '$$AnimateRunner', '$templateRequest', '$$jqLite', '$$forceReflow',
function($$rAF, $rootScope, $rootElement, $document, $$body, $$HashMap,
function($$rAF, $rootScope, $rootElement, $document, $$HashMap,
$$animation, $$AnimateRunner, $templateRequest, $$jqLite, $$forceReflow) {

var activeAnimationsLookup = new $$HashMap();
Expand Down Expand Up @@ -502,7 +502,8 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
}

function areAnimationsAllowed(element, parentElement, event) {
var bodyElementDetected = isMatchingElement(element, $$body) || element[0].nodeName === 'HTML';
var bodyElement = jqLite($document[0].body);
var bodyElementDetected = isMatchingElement(element, bodyElement) || element[0].nodeName === 'HTML';
var rootElementDetected = isMatchingElement(element, $rootElement);
var parentAnimationDetected = false;
var animateChildren;
Expand Down Expand Up @@ -558,7 +559,7 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
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
bodyElementDetected = isMatchingElement(parentElement, $$body);
bodyElementDetected = isMatchingElement(parentElement, bodyElement);
}

parentElement = parentElement.parent();
Expand Down
7 changes: 0 additions & 7 deletions src/ngAnimate/body.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/ngAnimate/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/* global angularAnimateModule: true,

$$BodyProvider,
$$AnimateAsyncRunFactory,
$$rAFSchedulerFactory,
$$AnimateChildrenDirective,
Expand Down Expand Up @@ -742,8 +741,6 @@
* Click here {@link ng.$animate to learn more about animations with `$animate`}.
*/
angular.module('ngAnimate', [])
.provider('$$body', $$BodyProvider)

.directive('ngAnimateChildren', $$AnimateChildrenDirective)
.factory('$$rAFScheduler', $$rAFSchedulerFactory)

Expand Down
4 changes: 2 additions & 2 deletions test/ng/directive/ngClassSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,12 +468,12 @@ describe('ngClass animations', function() {
};
});
});
inject(function($compile, $rootScope, $browser, $rootElement, $animate, $timeout, $$body) {
inject(function($compile, $rootScope, $browser, $rootElement, $animate, $document) {
$animate.enabled(true);

$rootScope.val = 'crazy';
element = angular.element('<div ng-class="val"></div>');
$$body.append($rootElement);
jqLite($document[0].body).append($rootElement);

$compile(element)($rootScope);

Expand Down
45 changes: 42 additions & 3 deletions test/ngAnimate/animateCssDriverSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,22 @@ describe("ngAnimate $$animateCssDriver", function() {
var from, to, fromAnimation, toAnimation;

beforeEach(module(function() {
return function($rootElement, $$body) {
return function($rootElement, $document) {
from = element;
to = jqLite('<div></div>');
fromAnimation = { element: from, event: 'enter' };
toAnimation = { element: to, event: 'leave' };
$rootElement.append(from);
$rootElement.append(to);

// we need to do this so that style detection works
$$body.append($rootElement);
var doc = $document[0];

// there is one test in here that expects the rootElement
// to superceed the body node
if (!$rootElement[0].contains(doc.body)) {
// we need to do this so that style detection works
jqLite(doc.body).append($rootElement);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this kind of conditional work in beforeEach makes me feel uncomfortable.
Actually almost all beforeEach blocks in general make me uncomfortable, especially when the spec file has over a thousand lines.
I often find myself looking at a spec that clearly has some magic happening somewhere in the file but there are potentially multiple nested decribe blocks who may or may not provide a beforeEach.
As a general rule I am moving more toward a style of helpers, except for very basic setup like getting hold of injectables.

But anyway, not to worry here on this occasion.

};
}));

Expand Down Expand Up @@ -975,6 +981,39 @@ describe("ngAnimate $$animateCssDriver", function() {

expect(completed).toBe(true);
}));

it("should use <body> as the element container if the rootElement exists outside of the <body> tag", function() {
module(function($provide) {
$provide.factory('$rootElement', function($document) {
return jqLite($document[0].querySelector('html'));
});
});
inject(function($rootElement, $rootScope, $animate, $document) {
ss.addRule('.ending-element', 'width:9999px; height:6666px; display:inline-block;');

var fromAnchor = jqLite('<div></div>');
from.append(fromAnchor);

var toAnchor = jqLite('<div></div>');
to.append(toAnchor);

$rootElement.append(fromAnchor);
$rootElement.append(toAnchor);

var completed = false;
driver({
from: fromAnimation,
to: toAnimation,
anchors: [{
'out': fromAnchor,
'in': toAnchor
}]
}).start();

var clone = captureLog[2].element[0];
expect(clone.parentNode).toBe($document[0].body);
});
});
});
});
});
Loading