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

Fixes to body element animation #12245

Closed
wants to merge 3 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: 1 addition & 0 deletions angularFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ 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
6 changes: 3 additions & 3 deletions src/ngAnimate/animateCssDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ 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', '$document', '$sniffer',
function($animateCss, $rootScope, $$AnimateRunner, $rootElement, $document, $sniffer) {
this.$get = ['$animateCss', '$rootScope', '$$AnimateRunner', '$rootElement', '$$body', '$sniffer',
function($animateCss, $rootScope, $$AnimateRunner, $rootElement, $$body, $sniffer) {

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

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

var rootBodyElement = jqLite(bodyNode.parentNode === rootNode ? bodyNode : rootNode);
Expand Down
12 changes: 5 additions & 7 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', '$$HashMap',
this.$get = ['$$rAF', '$rootScope', '$rootElement', '$document', '$$body', '$$HashMap',
'$$animation', '$$AnimateRunner', '$templateRequest', '$$jqLite',
function($$rAF, $rootScope, $rootElement, $document, $$HashMap,
function($$rAF, $rootScope, $rootElement, $document, $$body, $$HashMap,
$$animation, $$AnimateRunner, $templateRequest, $$jqLite) {

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

var bodyElement = jqLite($document[0].body);

var callbackRegistry = {};

// remember that the classNameFilter is set during the provider/config
Expand Down Expand Up @@ -524,8 +522,8 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
}

function areAnimationsAllowed(element, parentElement, event) {
var bodyElementDetected = false;
var rootElementDetected = false;
var bodyElementDetected = isMatchingElement(element, $$body) || element[0].nodeName === 'HTML';
var rootElementDetected = isMatchingElement(element, $rootElement);
var parentAnimationDetected = false;
var animateChildren;

Expand Down Expand Up @@ -580,7 +578,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, bodyElement);
bodyElementDetected = isMatchingElement(parentElement, $$body);
}

parentElement = parentElement.parent();
Expand Down
7 changes: 7 additions & 0 deletions src/ngAnimate/body.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

function $$BodyProvider() {
this.$get = ['$document', function($document) {
return jqLite($document[0].body);
}];
}
3 changes: 3 additions & 0 deletions src/ngAnimate/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/* global angularAnimateModule: true,

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

.directive('ngAnimateChildren', $$AnimateChildrenDirective)

.factory('$$rAFMutex', $$rAFMutexFactory)
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, $document, $$rAF) {
inject(function($compile, $rootScope, $browser, $rootElement, $animate, $timeout, $$body, $$rAF) {
$animate.enabled(true);

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

$compile(element)($rootScope);

Expand Down
4 changes: 2 additions & 2 deletions test/ngAnimate/animateCssDriverSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe("ngAnimate $$animateCssDriver", function() {
var from, to, fromAnimation, toAnimation;

beforeEach(module(function() {
return function($rootElement, $document) {
return function($rootElement, $$body) {
from = element;
to = jqLite('<div></div>');
fromAnimation = { element: from, event: 'enter' };
Expand All @@ -127,7 +127,7 @@ describe("ngAnimate $$animateCssDriver", function() {
$rootElement.append(to);

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

Expand Down
Loading