forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimate.js
191 lines (178 loc) · 7.83 KB
/
animate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
'use strict';
var $animateMinErr = minErr('$animate');
/**
* @ngdoc object
* @name ng.$animateProvider
*
* @description
* Default implementation of $animate that doesn't perform any animations, instead just synchronously performs DOM
* updates and calls done() callbacks.
*
* In order to enable animations the ngAnimate module has to be loaded.
*
* To see the functional implementation check out src/ngAnimate/animate.js
*/
var $AnimateProvider = ['$provide', function($provide) {
this.$$selectors = {};
/**
* @ngdoc function
* @name ng.$animateProvider#register
* @methodOf ng.$animateProvider
*
* @description
* Registers a new injectable animation factory function. The factory function produces the animation object which
* contains callback functions for each event that is expected to be animated.
*
* * `eventFn`: `function(Element, doneFunction)` The element to animate, the `doneFunction` must be called once the
* element animation is complete. If a function is returned then the animation service will use this function to
* cancel the animation whenever a cancel event is triggered.
*
*
*<pre>
* return {
* eventFn : function(element, done) {
* //code to run the animation
* //once complete, then run done()
* return function cancellationFunction() {
* //code to cancel the animation
* }
* }
* }
*</pre>
*
* @param {string} name The name of the animation.
* @param {function} factory The factory function that will be executed to return the animation object.
*/
this.register = function(name, factory) {
var key = name + '-animation';
if (name && name.charAt(0) != '.') throw $animateMinErr('notcsel',
"Expecting class selector starting with '.' got '{0}'.", name);
this.$$selectors[name.substr(1)] = key;
$provide.factory(key, factory);
};
this.$get = ['$timeout', function($timeout) {
/**
* @ngdoc object
* @name ng.$animate
*
* @description
* The $animate service provides rudimentary DOM manipulation functions to insert, remove and move elements within
* the DOM, as well as adding and removing classes. This service is the core service used by the ngAnimate $animator
* service which provides high-level animation hooks for CSS and JavaScript.
*
* $animate is available in the AngularJS core, however, the ngAnimate module must be included to enable full out
* animation support. Otherwise, $animate will only perform simple DOM manipulation operations.
*
* To learn more about enabling animation support, click here to visit the {@link ngAnimate ngAnimate module page}
* as well as the {@link ngAnimate.$animate ngAnimate $animate service page}.
*/
return {
/**
* @ngdoc function
* @name ng.$animate#enter
* @methodOf ng.$animate
* @function
*
* @description
* Inserts the element into the DOM either after the `after` element or within the `parent` element. Once complete,
* the done() callback will be fired (if provided).
*
* @param {jQuery/jqLite element} element the element which will be inserted into the DOM
* @param {jQuery/jqLite element} parent the parent element which will append the element as a child (if the after element is not present)
* @param {jQuery/jqLite element} after the sibling element which will append the element after itself
* @param {function=} done callback function that will be called after the element has been inserted into the DOM
*/
enter : function(element, parent, after, done) {
var afterNode = after && after[after.length - 1];
var parentNode = parent && parent[0] || afterNode && afterNode.parentNode;
// IE does not like undefined so we have to pass null.
var afterNextSibling = (afterNode && afterNode.nextSibling) || null;
forEach(element, function(node) {
parentNode.insertBefore(node, afterNextSibling);
});
done && $timeout(done, 0, false);
},
/**
* @ngdoc function
* @name ng.$animate#leave
* @methodOf ng.$animate
* @function
*
* @description
* Removes the element from the DOM. Once complete, the done() callback will be fired (if provided).
*
* @param {jQuery/jqLite element} element the element which will be removed from the DOM
* @param {function=} done callback function that will be called after the element has been removed from the DOM
*/
leave : function(element, done) {
element.remove();
done && $timeout(done, 0, false);
},
/**
* @ngdoc function
* @name ng.$animate#move
* @methodOf ng.$animate
* @function
*
* @description
* Moves the position of the provided element within the DOM to be placed either after the `after` element or inside of the `parent` element.
* Once complete, the done() callback will be fired (if provided).
*
* @param {jQuery/jqLite element} element the element which will be moved around within the DOM
* @param {jQuery/jqLite element} parent the parent element where the element will be inserted into (if the after element is not present)
* @param {jQuery/jqLite element} after the sibling element where the element will be positioned next to
* @param {function=} done the callback function (if provided) that will be fired after the element has been moved to its new position
*/
move : function(element, parent, after, done) {
// Do not remove element before insert. Removing will cause data associated with the
// element to be dropped. Insert will implicitly do the remove.
this.enter(element, parent, after, done);
},
/**
* @ngdoc function
* @name ng.$animate#addClass
* @methodOf ng.$animate
* @function
*
* @description
* Adds the provided className CSS class value to the provided element. Once complete, the done() callback will be fired (if provided).
*
* @param {jQuery/jqLite element} element the element which will have the className value added to it
* @param {string} className the CSS class which will be added to the element
* @param {function=} done the callback function (if provided) that will be fired after the className value has been added to the element
*/
addClass : function(element, className, done) {
className = isString(className) ?
className :
isArray(className) ? className.join(' ') : '';
forEach(element, function (element) {
JQLiteAddClass(element, className);
});
done && $timeout(done, 0, false);
},
/**
* @ngdoc function
* @name ng.$animate#removeClass
* @methodOf ng.$animate
* @function
*
* @description
* Removes the provided className CSS class value from the provided element. Once complete, the done() callback will be fired (if provided).
*
* @param {jQuery/jqLite element} element the element which will have the className value removed from it
* @param {string} className the CSS class which will be removed from the element
* @param {function=} done the callback function (if provided) that will be fired after the className value has been removed from the element
*/
removeClass : function(element, className, done) {
className = isString(className) ?
className :
isArray(className) ? className.join(' ') : '';
forEach(element, function (element) {
JQLiteRemoveClass(element, className);
});
done && $timeout(done, 0, false);
},
enabled : noop
};
}];
}];