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

Commit 6818542

Browse files
committed
fix($animate): ensure enable/disable animations work when the document node is used
Closes #4669
1 parent 7484830 commit 6818542

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/ngAnimate/animate.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -705,13 +705,16 @@ angular.module('ngAnimate', ['ng'])
705705
//the element did not reach the root element which means that it
706706
//is not apart of the DOM. Therefore there is no reason to do
707707
//any animations on it
708-
if(parent.length === 0 || parent[0] == $document[0]) return true;
708+
if(parent.length === 0) return true;
709709

710-
var state = parent.data(NG_ANIMATE_STATE);
710+
var isRoot = parent[0] == $rootElement[0];
711+
var state = isRoot ? rootAnimateState : parent.data(NG_ANIMATE_STATE);
711712
if(state && (state.disabled != null || state.running != null)) {
712713
validState = state;
713714
break;
714715
}
716+
717+
if(isRoot) return true;
715718
}
716719
while(parent = parent.parent());
717720

test/ngAnimate/animateSpec.js

+40
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,46 @@ describe("ngAnimate", function() {
120120
expect(count).toBe(0);
121121
});
122122
});
123+
124+
it('should check enable/disable animations up until the $rootElement element', function() {
125+
var rootElm = jqLite('<div></div>');
126+
127+
var captured = false;
128+
module(function($provide, $animateProvider) {
129+
$provide.value('$rootElement', rootElm);
130+
$animateProvider.register('.ani', function() {
131+
return {
132+
addClass : function(element, className, done) {
133+
captured = true;
134+
done();
135+
}
136+
}
137+
});
138+
});
139+
inject(function($animate, $rootElement, $rootScope, $compile, $timeout) {
140+
var initialState;
141+
angular.bootstrap(rootElm, ['ngAnimate']);
142+
143+
$animate.enabled(true);
144+
145+
var element = $compile('<div class="ani"></div>')($rootScope);
146+
rootElm.append(element);
147+
148+
expect(captured).toBe(false);
149+
$animate.addClass(element, 'red');
150+
expect(captured).toBe(true);
151+
152+
captured = false;
153+
$animate.enabled(false);
154+
155+
$animate.addClass(element, 'blue');
156+
expect(captured).toBe(false);
157+
158+
//clean up the mess
159+
$animate.enabled(false, rootElm);
160+
dealoc(rootElm);
161+
});
162+
});
123163
});
124164

125165
describe("with polyfill", function() {

0 commit comments

Comments
 (0)