Skip to content

Commit 031da1f

Browse files
matskoIgorMinar
authored andcommitted
fix($animator): ensure animations are always disabled for an element that is not attached to the DOM
1 parent 14626d0 commit 031da1f

File tree

7 files changed

+62
-33
lines changed

7 files changed

+62
-33
lines changed

docs/component-spec/annotationsSpec.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,21 @@ describe('Docs Annotations', function() {
9191
}
9292
});
9393
});
94-
inject(function($rootScope, $compile, $templateCache) {
94+
inject(function($rootScope, $compile, $templateCache, $rootElement, $animator) {
95+
$animator.enabled(true);
9596
url = '/page.html';
9697
$scope = $rootScope.$new();
9798
parent = angular.element('<div class="parent"></div>');
9899
element = angular.element('<div data-url="' + url + '" foldout></div>');
99-
body.append(parent);
100+
101+
//we're injecting the element to the $rootElement since the changes in
102+
//$animator only detect and perform animations if the root element has
103+
//animations enabled. If the element is not apart of the DOM
104+
//then animations are skipped.
100105
parent.append(element);
106+
$rootElement.append(parent);
107+
body.append($rootElement);
108+
101109
$compile(parent)($scope);
102110
$scope.$apply();
103111
});

src/ng/animator.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,9 @@ var $AnimatorProvider = function() {
290290
if (!parent) {
291291
parent = after ? after.parent() : element.parent();
292292
}
293+
var disabledAnimation = { running : true };
293294
if ((!$sniffer.transitions && !polyfillSetup && !polyfillStart) ||
294-
(parent.inheritedData(NG_ANIMATE_CONTROLLER) || noop).running) {
295+
(parent.inheritedData(NG_ANIMATE_CONTROLLER) || disabledAnimation).running) {
295296
beforeFn(element, parent, after);
296297
afterFn(element, parent, after);
297298
return;

test/ng/directive/ngIfSpec.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,22 @@ describe('ngIf', function () {
7777

7878
describe('ngIf ngAnimate', function () {
7979
var vendorPrefix, window;
80-
var body, element;
80+
var body, element, $rootElement;
8181

8282
function html(html) {
83-
body.html(html);
84-
element = body.children().eq(0);
83+
$rootElement.html(html);
84+
element = $rootElement.children().eq(0);
8585
return element;
8686
}
8787

88-
beforeEach(function() {
88+
beforeEach(module(function() {
8989
// we need to run animation on attached elements;
90-
body = jqLite(document.body);
91-
});
90+
return function(_$rootElement_) {
91+
$rootElement = _$rootElement_;
92+
body = jqLite(document.body);
93+
body.append($rootElement);
94+
};
95+
}));
9296

9397
afterEach(function(){
9498
dealoc(body);

test/ng/directive/ngIncludeSpec.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,11 @@ describe('ngInclude', function() {
299299

300300
describe('ngInclude ngAnimate', function() {
301301
var vendorPrefix, window;
302-
var body, element;
302+
var body, element, $rootElement;
303303

304304
function html(html) {
305-
body.html(html);
306-
element = body.children().eq(0);
305+
$rootElement.html(html);
306+
element = $rootElement.children().eq(0);
307307
return element;
308308
}
309309

@@ -312,10 +312,14 @@ describe('ngInclude ngAnimate', function() {
312312
element.css(vendorPrefix + cssProp, cssValue);
313313
}
314314

315-
beforeEach(function() {
315+
beforeEach(module(function() {
316316
// we need to run animation on attached elements;
317-
body = jqLite(document.body);
318-
});
317+
return function(_$rootElement_) {
318+
$rootElement = _$rootElement_;
319+
body = jqLite(document.body);
320+
body.append($rootElement);
321+
};
322+
}));
319323

320324
afterEach(function(){
321325
dealoc(body);

test/ng/directive/ngRepeatSpec.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -708,11 +708,11 @@ describe('ngRepeat', function() {
708708

709709
describe('ngRepeat ngAnimate', function() {
710710
var vendorPrefix, window;
711-
var body, element;
711+
var body, element, $rootElement;
712712

713713
function html(html) {
714-
body.html(html);
715-
element = body.children().eq(0);
714+
$rootElement.html(html);
715+
element = $rootElement.children().eq(0);
716716
return element;
717717
}
718718

@@ -721,10 +721,14 @@ describe('ngRepeat ngAnimate', function() {
721721
element.css(vendorPrefix + cssProp, cssValue);
722722
}
723723

724-
beforeEach(function() {
724+
beforeEach(module(function() {
725725
// we need to run animation on attached elements;
726-
body = jqLite(document.body);
727-
});
726+
return function(_$rootElement_) {
727+
$rootElement = _$rootElement_;
728+
body = jqLite(document.body);
729+
body.append($rootElement);
730+
};
731+
}));
728732

729733
afterEach(function(){
730734
dealoc(body);

test/ng/directive/ngSwitchSpec.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,22 @@ describe('ngSwitch', function() {
216216

217217
describe('ngSwitch ngAnimate', function() {
218218
var vendorPrefix, window;
219-
var body, element;
219+
var body, element, $rootElement;
220220

221221
function html(html) {
222-
body.html(html);
223-
element = body.children().eq(0);
222+
$rootElement.html(html);
223+
element = $rootElement.children().eq(0);
224224
return element;
225225
}
226226

227-
beforeEach(function() {
227+
beforeEach(module(function() {
228228
// we need to run animation on attached elements;
229-
body = jqLite(document.body);
230-
});
229+
return function(_$rootElement_) {
230+
$rootElement = _$rootElement_;
231+
body = jqLite(document.body);
232+
body.append($rootElement);
233+
};
234+
}));
231235

232236
afterEach(function(){
233237
dealoc(body);

test/ngRoute/directive/ngViewSpec.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,12 @@ describe('ngView', function() {
511511

512512
describe('ngAnimate ', function() {
513513
var window, vendorPrefix;
514-
var body, element;
514+
var body, element, $rootElement;
515515

516516
function html(html) {
517-
body.html(html);
518-
element = body.children().eq(0);
517+
$rootElement.html(html);
518+
body.append($rootElement);
519+
element = $rootElement.children().eq(0);
519520
return element;
520521
}
521522

@@ -524,10 +525,13 @@ describe('ngView', function() {
524525
element.css(vendorPrefix + cssProp, cssValue);
525526
}
526527

527-
beforeEach(function() {
528+
beforeEach(module(function() {
528529
// we need to run animation on attached elements;
529-
body = jqLite(document.body);
530-
});
530+
return function(_$rootElement_) {
531+
$rootElement = _$rootElement_;
532+
body = jqLite(document.body);
533+
};
534+
}));
531535

532536
afterEach(function(){
533537
dealoc(body);

0 commit comments

Comments
 (0)