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

Commit 3c1a460

Browse files
committed
feat($animate): allow $animate to pass custom styles into animations
$animate now supports an optional parameter which provides CSS styling which will be provided into the CSS-based animations as well as any custom animation functions. Once the animation is complete then the styles will be applied directly to the element. If no animation is detected or the `ngAnimate` module is not active then the styles will be applied immediately. BREAKING CHANGE: staggering animations that use transitions will now always block the transition from starting (via `transition: 0s none`) up until the stagger step kicks in. The former behaviour was that the block was removed as soon as the pending class was added. This fix allows for styles to be applied in the pending class without causing an animation to trigger prematurely.
1 parent f6aa1c5 commit 3c1a460

File tree

4 files changed

+540
-64
lines changed

4 files changed

+540
-64
lines changed

src/ng/animate.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ var $AnimateProvider = ['$provide', function($provide) {
9696
return currentDefer.promise;
9797
}
9898

99+
function applyStyles(element, styles) {
100+
if (angular.isObject(styles)) {
101+
element.css(styles.after || styles);
102+
}
103+
}
104+
99105
/**
100106
*
101107
* @ngdoc service
@@ -128,9 +134,11 @@ var $AnimateProvider = ['$provide', function($provide) {
128134
* a child (if the after element is not present)
129135
* @param {DOMElement} after the sibling element which will append the element
130136
* after itself
137+
* @param {object=} styles an optional collection of styles that will be applied to the element.
131138
* @return {Promise} the animation callback promise
132139
*/
133-
enter : function(element, parent, after) {
140+
enter : function(element, parent, after, styles) {
141+
applyStyles(element, styles);
134142
after ? after.after(element)
135143
: parent.prepend(element);
136144
return asyncPromise();
@@ -144,9 +152,10 @@ var $AnimateProvider = ['$provide', function($provide) {
144152
* @description Removes the element from the DOM. When the function is called a promise
145153
* is returned that will be resolved at a later time.
146154
* @param {DOMElement} element the element which will be removed from the DOM
155+
* @param {object=} styles an optional collection of styles that will be applied to the element.
147156
* @return {Promise} the animation callback promise
148157
*/
149-
leave : function(element) {
158+
leave : function(element, styles) {
150159
element.remove();
151160
return asyncPromise();
152161
},
@@ -166,12 +175,13 @@ var $AnimateProvider = ['$provide', function($provide) {
166175
* inserted into (if the after element is not present)
167176
* @param {DOMElement} after the sibling element where the element will be
168177
* positioned next to
178+
* @param {object=} styles an optional collection of styles that will be applied to the element.
169179
* @return {Promise} the animation callback promise
170180
*/
171-
move : function(element, parent, after) {
181+
move : function(element, parent, after, styles) {
172182
// Do not remove element before insert. Removing will cause data associated with the
173183
// element to be dropped. Insert will implicitly do the remove.
174-
return this.enter(element, parent, after);
184+
return this.enter(element, parent, after, styles);
175185
},
176186

177187
/**
@@ -184,15 +194,17 @@ var $AnimateProvider = ['$provide', function($provide) {
184194
* @param {DOMElement} element the element which will have the className value
185195
* added to it
186196
* @param {string} className the CSS class which will be added to the element
197+
* @param {object=} styles an optional collection of styles that will be applied to the element.
187198
* @return {Promise} the animation callback promise
188199
*/
189-
addClass : function(element, className) {
200+
addClass : function(element, className, styles) {
190201
className = !isString(className)
191202
? (isArray(className) ? className.join(' ') : '')
192203
: className;
193204
forEach(element, function (element) {
194205
jqLiteAddClass(element, className);
195206
});
207+
applyStyles(element, styles);
196208
return asyncPromise();
197209
},
198210

@@ -206,15 +218,17 @@ var $AnimateProvider = ['$provide', function($provide) {
206218
* @param {DOMElement} element the element which will have the className value
207219
* removed from it
208220
* @param {string} className the CSS class which will be removed from the element
221+
* @param {object=} styles an optional collection of styles that will be applied to the element.
209222
* @return {Promise} the animation callback promise
210223
*/
211-
removeClass : function(element, className) {
224+
removeClass : function(element, className, styles) {
212225
className = !isString(className)
213226
? (isArray(className) ? className.join(' ') : '')
214227
: className;
215228
forEach(element, function (element) {
216229
jqLiteRemoveClass(element, className);
217230
});
231+
applyStyles(element, styles);
218232
return asyncPromise();
219233
},
220234

@@ -229,11 +243,13 @@ var $AnimateProvider = ['$provide', function($provide) {
229243
* removed from it
230244
* @param {string} add the CSS classes which will be added to the element
231245
* @param {string} remove the CSS class which will be removed from the element
246+
* @param {object=} styles an optional collection of styles that will be applied to the element.
232247
* @return {Promise} the animation callback promise
233248
*/
234-
setClass : function(element, add, remove) {
249+
setClass : function(element, add, remove, styles) {
235250
this.addClass(element, add);
236251
this.removeClass(element, remove);
252+
applyStyles(element, styles);
237253
return asyncPromise();
238254
},
239255

0 commit comments

Comments
 (0)