material_raingular 0.0.1.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +2 -0
- data/lib/assets/javascripts/ajax_errors.js.coffee +13 -0
- data/lib/assets/javascripts/dateconverter.coffee +23 -0
- data/lib/assets/javascripts/directives/ngauthorize.js.coffee +8 -0
- data/lib/assets/javascripts/directives/ngautocomplete.js.coffee +135 -0
- data/lib/assets/javascripts/directives/ngboolean.js.coffee +34 -0
- data/lib/assets/javascripts/directives/ngchangeonblur.js.coffee +19 -0
- data/lib/assets/javascripts/directives/ngcreate.js.coffee +27 -0
- data/lib/assets/javascripts/directives/ngdestroy.js.coffee +24 -0
- data/lib/assets/javascripts/directives/ngdownload.js.coffee +8 -0
- data/lib/assets/javascripts/directives/ngdrag.js.coffee +122 -0
- data/lib/assets/javascripts/directives/ngfade.js.coffee +21 -0
- data/lib/assets/javascripts/directives/ngload.js.coffee +16 -0
- data/lib/assets/javascripts/directives/ngmatches.js.coffee +14 -0
- data/lib/assets/javascripts/directives/ngpopup.js.coffee +37 -0
- data/lib/assets/javascripts/directives/ngrepeatlist.js.coffee +52 -0
- data/lib/assets/javascripts/directives/ngslide.js.coffee +82 -0
- data/lib/assets/javascripts/directives/ngswipe.js.coffee +60 -0
- data/lib/assets/javascripts/directives/ngupdate.js.coffee +62 -0
- data/lib/assets/javascripts/directives/ngupload.js.coffee +127 -0
- data/lib/assets/javascripts/directives/ngwatchcontent.js.coffee +13 -0
- data/lib/assets/javascripts/directives/ngwatchshow.js.coffee +15 -0
- data/lib/assets/javascripts/directives/table.js.coffee +43 -0
- data/lib/assets/javascripts/directives/textarea.coffee +11 -0
- data/lib/assets/javascripts/directives/video.js.coffee +10 -0
- data/lib/assets/javascripts/factory_name.js.coffee +9 -0
- data/lib/assets/javascripts/material_raingular.js.coffee +17 -0
- data/lib/material_raingular/version.rb +3 -0
- data/lib/material_raingular.rb +8 -0
- data/lib/tasks/material_raingular.rake +42 -0
- data/material_raingular.gemspec +25 -0
- data/vendor/assets/angular/.jshintrc +181 -0
- data/vendor/assets/angular/angular-animate.js +3708 -0
- data/vendor/assets/angular/angular-aria.js +378 -0
- data/vendor/assets/angular/angular-cookies.js +320 -0
- data/vendor/assets/angular/angular-loader.js +429 -0
- data/vendor/assets/angular/angular-material.min.css +6 -0
- data/vendor/assets/angular/angular-material.min.js +14 -0
- data/vendor/assets/angular/angular-message-format.js +980 -0
- data/vendor/assets/angular/angular-messages.js +678 -0
- data/vendor/assets/angular/angular-resource.js +668 -0
- data/vendor/assets/angular/angular-route.js +991 -0
- data/vendor/assets/angular/angular-sanitize.js +683 -0
- data/vendor/assets/angular/angular-touch.js +627 -0
- data/vendor/assets/angular/angular.js +28133 -0
- metadata +139 -0
@@ -0,0 +1,3708 @@
|
|
1
|
+
/**
|
2
|
+
* @license AngularJS v1.4.0
|
3
|
+
* (c) 2010-2015 Google, Inc. http://angularjs.org
|
4
|
+
* License: MIT
|
5
|
+
*/
|
6
|
+
(function(window, angular, undefined) {'use strict';
|
7
|
+
|
8
|
+
/* jshint ignore:start */
|
9
|
+
var noop = angular.noop;
|
10
|
+
var extend = angular.extend;
|
11
|
+
var jqLite = angular.element;
|
12
|
+
var forEach = angular.forEach;
|
13
|
+
var isArray = angular.isArray;
|
14
|
+
var isString = angular.isString;
|
15
|
+
var isObject = angular.isObject;
|
16
|
+
var isUndefined = angular.isUndefined;
|
17
|
+
var isDefined = angular.isDefined;
|
18
|
+
var isFunction = angular.isFunction;
|
19
|
+
var isElement = angular.isElement;
|
20
|
+
|
21
|
+
var ELEMENT_NODE = 1;
|
22
|
+
var COMMENT_NODE = 8;
|
23
|
+
|
24
|
+
var NG_ANIMATE_CLASSNAME = 'ng-animate';
|
25
|
+
var NG_ANIMATE_CHILDREN_DATA = '$$ngAnimateChildren';
|
26
|
+
|
27
|
+
var isPromiseLike = function(p) {
|
28
|
+
return p && p.then ? true : false;
|
29
|
+
}
|
30
|
+
|
31
|
+
function assertArg(arg, name, reason) {
|
32
|
+
if (!arg) {
|
33
|
+
throw ngMinErr('areq', "Argument '{0}' is {1}", (name || '?'), (reason || "required"));
|
34
|
+
}
|
35
|
+
return arg;
|
36
|
+
}
|
37
|
+
|
38
|
+
function mergeClasses(a,b) {
|
39
|
+
if (!a && !b) return '';
|
40
|
+
if (!a) return b;
|
41
|
+
if (!b) return a;
|
42
|
+
if (isArray(a)) a = a.join(' ');
|
43
|
+
if (isArray(b)) b = b.join(' ');
|
44
|
+
return a + ' ' + b;
|
45
|
+
}
|
46
|
+
|
47
|
+
function packageStyles(options) {
|
48
|
+
var styles = {};
|
49
|
+
if (options && (options.to || options.from)) {
|
50
|
+
styles.to = options.to;
|
51
|
+
styles.from = options.from;
|
52
|
+
}
|
53
|
+
return styles;
|
54
|
+
}
|
55
|
+
|
56
|
+
function pendClasses(classes, fix, isPrefix) {
|
57
|
+
var className = '';
|
58
|
+
classes = isArray(classes)
|
59
|
+
? classes
|
60
|
+
: classes && isString(classes) && classes.length
|
61
|
+
? classes.split(/\s+/)
|
62
|
+
: [];
|
63
|
+
forEach(classes, function(klass, i) {
|
64
|
+
if (klass && klass.length > 0) {
|
65
|
+
className += (i > 0) ? ' ' : '';
|
66
|
+
className += isPrefix ? fix + klass
|
67
|
+
: klass + fix;
|
68
|
+
}
|
69
|
+
});
|
70
|
+
return className;
|
71
|
+
}
|
72
|
+
|
73
|
+
function removeFromArray(arr, val) {
|
74
|
+
var index = arr.indexOf(val);
|
75
|
+
if (val >= 0) {
|
76
|
+
arr.splice(index, 1);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
function stripCommentsFromElement(element) {
|
81
|
+
if (element instanceof jqLite) {
|
82
|
+
switch (element.length) {
|
83
|
+
case 0:
|
84
|
+
return [];
|
85
|
+
break;
|
86
|
+
|
87
|
+
case 1:
|
88
|
+
// there is no point of stripping anything if the element
|
89
|
+
// is the only element within the jqLite wrapper.
|
90
|
+
// (it's important that we retain the element instance.)
|
91
|
+
if (element[0].nodeType === ELEMENT_NODE) {
|
92
|
+
return element;
|
93
|
+
}
|
94
|
+
break;
|
95
|
+
|
96
|
+
default:
|
97
|
+
return jqLite(extractElementNode(element));
|
98
|
+
break;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
if (element.nodeType === ELEMENT_NODE) {
|
103
|
+
return jqLite(element);
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
function extractElementNode(element) {
|
108
|
+
if (!element[0]) return element;
|
109
|
+
for (var i = 0; i < element.length; i++) {
|
110
|
+
var elm = element[i];
|
111
|
+
if (elm.nodeType == ELEMENT_NODE) {
|
112
|
+
return elm;
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
function $$addClass($$jqLite, element, className) {
|
118
|
+
forEach(element, function(elm) {
|
119
|
+
$$jqLite.addClass(elm, className);
|
120
|
+
});
|
121
|
+
}
|
122
|
+
|
123
|
+
function $$removeClass($$jqLite, element, className) {
|
124
|
+
forEach(element, function(elm) {
|
125
|
+
$$jqLite.removeClass(elm, className);
|
126
|
+
});
|
127
|
+
}
|
128
|
+
|
129
|
+
function applyAnimationClassesFactory($$jqLite) {
|
130
|
+
return function(element, options) {
|
131
|
+
if (options.addClass) {
|
132
|
+
$$addClass($$jqLite, element, options.addClass);
|
133
|
+
options.addClass = null;
|
134
|
+
}
|
135
|
+
if (options.removeClass) {
|
136
|
+
$$removeClass($$jqLite, element, options.removeClass);
|
137
|
+
options.removeClass = null;
|
138
|
+
}
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
function prepareAnimationOptions(options) {
|
143
|
+
options = options || {};
|
144
|
+
if (!options.$$prepared) {
|
145
|
+
var domOperation = options.domOperation || noop;
|
146
|
+
options.domOperation = function() {
|
147
|
+
options.$$domOperationFired = true;
|
148
|
+
domOperation();
|
149
|
+
domOperation = noop;
|
150
|
+
};
|
151
|
+
options.$$prepared = true;
|
152
|
+
}
|
153
|
+
return options;
|
154
|
+
}
|
155
|
+
|
156
|
+
function applyAnimationStyles(element, options) {
|
157
|
+
applyAnimationFromStyles(element, options);
|
158
|
+
applyAnimationToStyles(element, options);
|
159
|
+
}
|
160
|
+
|
161
|
+
function applyAnimationFromStyles(element, options) {
|
162
|
+
if (options.from) {
|
163
|
+
element.css(options.from);
|
164
|
+
options.from = null;
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
function applyAnimationToStyles(element, options) {
|
169
|
+
if (options.to) {
|
170
|
+
element.css(options.to);
|
171
|
+
options.to = null;
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
function mergeAnimationOptions(element, target, newOptions) {
|
176
|
+
var toAdd = (target.addClass || '') + ' ' + (newOptions.addClass || '');
|
177
|
+
var toRemove = (target.removeClass || '') + ' ' + (newOptions.removeClass || '');
|
178
|
+
var classes = resolveElementClasses(element.attr('class'), toAdd, toRemove);
|
179
|
+
|
180
|
+
extend(target, newOptions);
|
181
|
+
|
182
|
+
if (classes.addClass) {
|
183
|
+
target.addClass = classes.addClass;
|
184
|
+
} else {
|
185
|
+
target.addClass = null;
|
186
|
+
}
|
187
|
+
|
188
|
+
if (classes.removeClass) {
|
189
|
+
target.removeClass = classes.removeClass;
|
190
|
+
} else {
|
191
|
+
target.removeClass = null;
|
192
|
+
}
|
193
|
+
|
194
|
+
return target;
|
195
|
+
}
|
196
|
+
|
197
|
+
function resolveElementClasses(existing, toAdd, toRemove) {
|
198
|
+
var ADD_CLASS = 1;
|
199
|
+
var REMOVE_CLASS = -1;
|
200
|
+
|
201
|
+
var flags = {};
|
202
|
+
existing = splitClassesToLookup(existing);
|
203
|
+
|
204
|
+
toAdd = splitClassesToLookup(toAdd);
|
205
|
+
forEach(toAdd, function(value, key) {
|
206
|
+
flags[key] = ADD_CLASS;
|
207
|
+
});
|
208
|
+
|
209
|
+
toRemove = splitClassesToLookup(toRemove);
|
210
|
+
forEach(toRemove, function(value, key) {
|
211
|
+
flags[key] = flags[key] === ADD_CLASS ? null : REMOVE_CLASS;
|
212
|
+
});
|
213
|
+
|
214
|
+
var classes = {
|
215
|
+
addClass: '',
|
216
|
+
removeClass: ''
|
217
|
+
};
|
218
|
+
|
219
|
+
forEach(flags, function(val, klass) {
|
220
|
+
var prop, allow;
|
221
|
+
if (val === ADD_CLASS) {
|
222
|
+
prop = 'addClass';
|
223
|
+
allow = !existing[klass];
|
224
|
+
} else if (val === REMOVE_CLASS) {
|
225
|
+
prop = 'removeClass';
|
226
|
+
allow = existing[klass];
|
227
|
+
}
|
228
|
+
if (allow) {
|
229
|
+
if (classes[prop].length) {
|
230
|
+
classes[prop] += ' ';
|
231
|
+
}
|
232
|
+
classes[prop] += klass;
|
233
|
+
}
|
234
|
+
});
|
235
|
+
|
236
|
+
function splitClassesToLookup(classes) {
|
237
|
+
if (isString(classes)) {
|
238
|
+
classes = classes.split(' ');
|
239
|
+
}
|
240
|
+
|
241
|
+
var obj = {};
|
242
|
+
forEach(classes, function(klass) {
|
243
|
+
// sometimes the split leaves empty string values
|
244
|
+
// incase extra spaces were applied to the options
|
245
|
+
if (klass.length) {
|
246
|
+
obj[klass] = true;
|
247
|
+
}
|
248
|
+
});
|
249
|
+
return obj;
|
250
|
+
}
|
251
|
+
|
252
|
+
return classes;
|
253
|
+
}
|
254
|
+
|
255
|
+
function getDomNode(element) {
|
256
|
+
return (element instanceof angular.element) ? element[0] : element;
|
257
|
+
}
|
258
|
+
|
259
|
+
var $$rAFSchedulerFactory = ['$$rAF', function($$rAF) {
|
260
|
+
var tickQueue = [];
|
261
|
+
var cancelFn;
|
262
|
+
|
263
|
+
function scheduler(tasks) {
|
264
|
+
// we make a copy since RAFScheduler mutates the state
|
265
|
+
// of the passed in array variable and this would be difficult
|
266
|
+
// to track down on the outside code
|
267
|
+
tickQueue.push([].concat(tasks));
|
268
|
+
nextTick();
|
269
|
+
}
|
270
|
+
|
271
|
+
/* waitUntilQuiet does two things:
|
272
|
+
* 1. It will run the FINAL `fn` value only when an uncancelled RAF has passed through
|
273
|
+
* 2. It will delay the next wave of tasks from running until the quiet `fn` has run.
|
274
|
+
*
|
275
|
+
* The motivation here is that animation code can request more time from the scheduler
|
276
|
+
* before the next wave runs. This allows for certain DOM properties such as classes to
|
277
|
+
* be resolved in time for the next animation to run.
|
278
|
+
*/
|
279
|
+
scheduler.waitUntilQuiet = function(fn) {
|
280
|
+
if (cancelFn) cancelFn();
|
281
|
+
|
282
|
+
cancelFn = $$rAF(function() {
|
283
|
+
cancelFn = null;
|
284
|
+
fn();
|
285
|
+
nextTick();
|
286
|
+
});
|
287
|
+
};
|
288
|
+
|
289
|
+
return scheduler;
|
290
|
+
|
291
|
+
function nextTick() {
|
292
|
+
if (!tickQueue.length) return;
|
293
|
+
|
294
|
+
var updatedQueue = [];
|
295
|
+
for (var i = 0; i < tickQueue.length; i++) {
|
296
|
+
var innerQueue = tickQueue[i];
|
297
|
+
runNextTask(innerQueue);
|
298
|
+
if (innerQueue.length) {
|
299
|
+
updatedQueue.push(innerQueue);
|
300
|
+
}
|
301
|
+
}
|
302
|
+
tickQueue = updatedQueue;
|
303
|
+
|
304
|
+
if (!cancelFn) {
|
305
|
+
$$rAF(function() {
|
306
|
+
if (!cancelFn) nextTick();
|
307
|
+
});
|
308
|
+
}
|
309
|
+
}
|
310
|
+
|
311
|
+
function runNextTask(tasks) {
|
312
|
+
var nextTask = tasks.shift();
|
313
|
+
nextTask();
|
314
|
+
}
|
315
|
+
}];
|
316
|
+
|
317
|
+
var $$AnimateChildrenDirective = [function() {
|
318
|
+
return function(scope, element, attrs) {
|
319
|
+
var val = attrs.ngAnimateChildren;
|
320
|
+
if (angular.isString(val) && val.length === 0) { //empty attribute
|
321
|
+
element.data(NG_ANIMATE_CHILDREN_DATA, true);
|
322
|
+
} else {
|
323
|
+
attrs.$observe('ngAnimateChildren', function(value) {
|
324
|
+
value = value === 'on' || value === 'true';
|
325
|
+
element.data(NG_ANIMATE_CHILDREN_DATA, value);
|
326
|
+
});
|
327
|
+
}
|
328
|
+
};
|
329
|
+
}];
|
330
|
+
|
331
|
+
/**
|
332
|
+
* @ngdoc service
|
333
|
+
* @name $animateCss
|
334
|
+
* @kind object
|
335
|
+
*
|
336
|
+
* @description
|
337
|
+
* The `$animateCss` service is a useful utility to trigger customized CSS-based transitions/keyframes
|
338
|
+
* from a JavaScript-based animation or directly from a directive. The purpose of `$animateCss` is NOT
|
339
|
+
* to side-step how `$animate` and ngAnimate work, but the goal is to allow pre-existing animations or
|
340
|
+
* directives to create more complex animations that can be purely driven using CSS code.
|
341
|
+
*
|
342
|
+
* Note that only browsers that support CSS transitions and/or keyframe animations are capable of
|
343
|
+
* rendering animations triggered via `$animateCss` (bad news for IE9 and lower).
|
344
|
+
*
|
345
|
+
* ## Usage
|
346
|
+
* Once again, `$animateCss` is designed to be used inside of a registered JavaScript animation that
|
347
|
+
* is powered by ngAnimate. It is possible to use `$animateCss` directly inside of a directive, however,
|
348
|
+
* any automatic control over cancelling animations and/or preventing animations from being run on
|
349
|
+
* child elements will not be handled by Angular. For this to work as expected, please use `$animate` to
|
350
|
+
* trigger the animation and then setup a JavaScript animation that injects `$animateCss` to trigger
|
351
|
+
* the CSS animation.
|
352
|
+
*
|
353
|
+
* The example below shows how we can create a folding animation on an element using `ng-if`:
|
354
|
+
*
|
355
|
+
* ```html
|
356
|
+
* <!-- notice the `fold-animation` CSS class -->
|
357
|
+
* <div ng-if="onOff" class="fold-animation">
|
358
|
+
* This element will go BOOM
|
359
|
+
* </div>
|
360
|
+
* <button ng-click="onOff=true">Fold In</button>
|
361
|
+
* ```
|
362
|
+
*
|
363
|
+
* Now we create the **JavaScript animation** that will trigger the CSS transition:
|
364
|
+
*
|
365
|
+
* ```js
|
366
|
+
* ngModule.animation('.fold-animation', ['$animateCss', function($animateCss) {
|
367
|
+
* return {
|
368
|
+
* enter: function(element, doneFn) {
|
369
|
+
* var height = element[0].offsetHeight;
|
370
|
+
* return $animateCss(element, {
|
371
|
+
* from: { height:'0px' },
|
372
|
+
* to: { height:height + 'px' },
|
373
|
+
* duration: 1 // one second
|
374
|
+
* });
|
375
|
+
* }
|
376
|
+
* }
|
377
|
+
* }]);
|
378
|
+
* ```
|
379
|
+
*
|
380
|
+
* ## More Advanced Uses
|
381
|
+
*
|
382
|
+
* `$animateCss` is the underlying code that ngAnimate uses to power **CSS-based animations** behind the scenes. Therefore CSS hooks
|
383
|
+
* like `.ng-EVENT`, `.ng-EVENT-active`, `.ng-EVENT-stagger` are all features that can be triggered using `$animateCss` via JavaScript code.
|
384
|
+
*
|
385
|
+
* This also means that just about any combination of adding classes, removing classes, setting styles, dynamically setting a keyframe animation,
|
386
|
+
* applying a hardcoded duration or delay value, changing the animation easing or applying a stagger animation are all options that work with
|
387
|
+
* `$animateCss`. The service itself is smart enough to figure out the combination of options and examine the element styling properties in order
|
388
|
+
* to provide a working animation that will run in CSS.
|
389
|
+
*
|
390
|
+
* The example below showcases a more advanced version of the `.fold-animation` from the example above:
|
391
|
+
*
|
392
|
+
* ```js
|
393
|
+
* ngModule.animation('.fold-animation', ['$animateCss', function($animateCss) {
|
394
|
+
* return {
|
395
|
+
* enter: function(element, doneFn) {
|
396
|
+
* var height = element[0].offsetHeight;
|
397
|
+
* return $animateCss(element, {
|
398
|
+
* addClass: 'red large-text pulse-twice',
|
399
|
+
* easing: 'ease-out',
|
400
|
+
* from: { height:'0px' },
|
401
|
+
* to: { height:height + 'px' },
|
402
|
+
* duration: 1 // one second
|
403
|
+
* });
|
404
|
+
* }
|
405
|
+
* }
|
406
|
+
* }]);
|
407
|
+
* ```
|
408
|
+
*
|
409
|
+
* Since we're adding/removing CSS classes then the CSS transition will also pick those up:
|
410
|
+
*
|
411
|
+
* ```css
|
412
|
+
* /* since a hardcoded duration value of 1 was provided in the JavaScript animation code,
|
413
|
+
* the CSS classes below will be transitioned despite them being defined as regular CSS classes */
|
414
|
+
* .red { background:red; }
|
415
|
+
* .large-text { font-size:20px; }
|
416
|
+
*
|
417
|
+
* /* we can also use a keyframe animation and $animateCss will make it work alongside the transition */
|
418
|
+
* .pulse-twice {
|
419
|
+
* animation: 0.5s pulse linear 2;
|
420
|
+
* -webkit-animation: 0.5s pulse linear 2;
|
421
|
+
* }
|
422
|
+
*
|
423
|
+
* @keyframes pulse {
|
424
|
+
* from { transform: scale(0.5); }
|
425
|
+
* to { transform: scale(1.5); }
|
426
|
+
* }
|
427
|
+
*
|
428
|
+
* @-webkit-keyframes pulse {
|
429
|
+
* from { -webkit-transform: scale(0.5); }
|
430
|
+
* to { -webkit-transform: scale(1.5); }
|
431
|
+
* }
|
432
|
+
* ```
|
433
|
+
*
|
434
|
+
* Given this complex combination of CSS classes, styles and options, `$animateCss` will figure everything out and make the animation happen.
|
435
|
+
*
|
436
|
+
* ## How the Options are handled
|
437
|
+
*
|
438
|
+
* `$animateCss` is very versatile and intelligent when it comes to figuring out what configurations to apply to the element to ensure the animation
|
439
|
+
* works with the options provided. Say for example we were adding a class that contained a keyframe value and we wanted to also animate some inline
|
440
|
+
* styles using the `from` and `to` properties.
|
441
|
+
*
|
442
|
+
* ```js
|
443
|
+
* var animator = $animateCss(element, {
|
444
|
+
* from: { background:'red' },
|
445
|
+
* to: { background:'blue' }
|
446
|
+
* });
|
447
|
+
* animator.start();
|
448
|
+
* ```
|
449
|
+
*
|
450
|
+
* ```css
|
451
|
+
* .rotating-animation {
|
452
|
+
* animation:0.5s rotate linear;
|
453
|
+
* -webkit-animation:0.5s rotate linear;
|
454
|
+
* }
|
455
|
+
*
|
456
|
+
* @keyframes rotate {
|
457
|
+
* from { transform: rotate(0deg); }
|
458
|
+
* to { transform: rotate(360deg); }
|
459
|
+
* }
|
460
|
+
*
|
461
|
+
* @-webkit-keyframes rotate {
|
462
|
+
* from { -webkit-transform: rotate(0deg); }
|
463
|
+
* to { -webkit-transform: rotate(360deg); }
|
464
|
+
* }
|
465
|
+
* ```
|
466
|
+
*
|
467
|
+
* The missing pieces here are that we do not have a transition set (within the CSS code nor within the `$animateCss` options) and the duration of the animation is
|
468
|
+
* going to be detected from what the keyframe styles on the CSS class are. In this event, `$animateCss` will automatically create an inline transition
|
469
|
+
* style matching the duration detected from the keyframe style (which is present in the CSS class that is being added) and then prepare both the transition
|
470
|
+
* and keyframe animations to run in parallel on the element. Then when the animation is underway the provided `from` and `to` CSS styles will be applied
|
471
|
+
* and spread across the transition and keyframe animation.
|
472
|
+
*
|
473
|
+
* ## What is returned
|
474
|
+
*
|
475
|
+
* `$animateCss` works in two stages: a preparation phase and an animation phase. Therefore when `$animateCss` is first called it will NOT actually
|
476
|
+
* start the animation. All that is going on here is that the element is being prepared for the animation (which means that the generated CSS classes are
|
477
|
+
* added and removed on the element). Once `$animateCss` is called it will return an object with the following properties:
|
478
|
+
*
|
479
|
+
* ```js
|
480
|
+
* var animator = $animateCss(element, { ... });
|
481
|
+
* ```
|
482
|
+
*
|
483
|
+
* Now what do the contents of our `animator` variable look like:
|
484
|
+
*
|
485
|
+
* ```js
|
486
|
+
* {
|
487
|
+
* // starts the animation
|
488
|
+
* start: Function,
|
489
|
+
*
|
490
|
+
* // ends (aborts) the animation
|
491
|
+
* end: Function
|
492
|
+
* }
|
493
|
+
* ```
|
494
|
+
*
|
495
|
+
* To actually start the animation we need to run `animation.start()` which will then return a promise that we can hook into to detect when the animation ends.
|
496
|
+
* If we choose not to run the animation then we MUST run `animation.end()` to perform a cleanup on the element (since some CSS classes and stlyes may have been
|
497
|
+
* applied to the element during the preparation phase). Note that all other properties such as duration, delay, transitions and keyframes are just properties
|
498
|
+
* and that changing them will not reconfigure the parameters of the animation.
|
499
|
+
*
|
500
|
+
* ### runner.done() vs runner.then()
|
501
|
+
* It is documented that `animation.start()` will return a promise object and this is true, however, there is also an additional method available on the
|
502
|
+
* runner called `.done(callbackFn)`. The done method works the same as `.finally(callbackFn)`, however, it does **not trigger a digest to occur**.
|
503
|
+
* Therefore, for performance reasons, it's always best to use `runner.done(callback)` instead of `runner.then()`, `runner.catch()` or `runner.finally()`
|
504
|
+
* unless you really need a digest to kick off afterwards.
|
505
|
+
*
|
506
|
+
* Keep in mind that, to make this easier, ngAnimate has tweaked the JS animations API to recognize when a runner instance is returned from $animateCss
|
507
|
+
* (so there is no need to call `runner.done(doneFn)` inside of your JavaScript animation code). Check the [animation code above](#usage) to see how this works.
|
508
|
+
*
|
509
|
+
* @param {DOMElement} element the element that will be animated
|
510
|
+
* @param {object} options the animation-related options that will be applied during the animation
|
511
|
+
*
|
512
|
+
* * `event` - The DOM event (e.g. enter, leave, move). When used, a generated CSS class of `ng-EVENT` and `ng-EVENT-active` will be applied
|
513
|
+
* to the element during the animation. Multiple events can be provided when spaces are used as a separator. (Note that this will not perform any DOM operation.)
|
514
|
+
* * `easing` - The CSS easing value that will be applied to the transition or keyframe animation (or both).
|
515
|
+
* * `transition` - The raw CSS transition style that will be used (e.g. `1s linear all`).
|
516
|
+
* * `keyframe` - The raw CSS keyframe animation style that will be used (e.g. `1s my_animation linear`).
|
517
|
+
* * `from` - The starting CSS styles (a key/value object) that will be applied at the start of the animation.
|
518
|
+
* * `to` - The ending CSS styles (a key/value object) that will be applied across the animation via a CSS transition.
|
519
|
+
* * `addClass` - A space separated list of CSS classes that will be added to the element and spread across the animation.
|
520
|
+
* * `removeClass` - A space separated list of CSS classes that will be removed from the element and spread across the animation.
|
521
|
+
* * `duration` - A number value representing the total duration of the transition and/or keyframe (note that a value of 1 is 1000ms). If a value of `0`
|
522
|
+
* is provided then the animation will be skipped entirely.
|
523
|
+
* * `delay` - A number value representing the total delay of the transition and/or keyframe (note that a value of 1 is 1000ms). If a value of `true` is
|
524
|
+
* used then whatever delay value is detected from the CSS classes will be mirrored on the elements styles (e.g. by setting delay true then the style value
|
525
|
+
* of the element will be `transition-delay: DETECTED_VALUE`). Using `true` is useful when you want the CSS classes and inline styles to all share the same
|
526
|
+
* CSS delay value.
|
527
|
+
* * `stagger` - A numeric time value representing the delay between successively animated elements
|
528
|
+
* ({@link ngAnimate#css-staggering-animations Click here to learn how CSS-based staggering works in ngAnimate.})
|
529
|
+
* * `staggerIndex` - The numeric index representing the stagger item (e.g. a value of 5 is equal to the sixth item in the stagger; therefore when a
|
530
|
+
* `stagger` option value of `0.1` is used then there will be a stagger delay of `600ms`)
|
531
|
+
* `applyClassesEarly` - Whether or not the classes being added or removed will be used when detecting the animation. This is set by `$animate` when enter/leave/move animations are fired to ensure that the CSS classes are resolved in time. (Note that this will prevent any transitions from occuring on the classes being added and removed.)
|
532
|
+
*
|
533
|
+
* @return {object} an object with start and end methods and details about the animation.
|
534
|
+
*
|
535
|
+
* * `start` - The method to start the animation. This will return a `Promise` when called.
|
536
|
+
* * `end` - This method will cancel the animation and remove all applied CSS classes and styles.
|
537
|
+
*/
|
538
|
+
|
539
|
+
// Detect proper transitionend/animationend event names.
|
540
|
+
var CSS_PREFIX = '', TRANSITION_PROP, TRANSITIONEND_EVENT, ANIMATION_PROP, ANIMATIONEND_EVENT;
|
541
|
+
|
542
|
+
// If unprefixed events are not supported but webkit-prefixed are, use the latter.
|
543
|
+
// Otherwise, just use W3C names, browsers not supporting them at all will just ignore them.
|
544
|
+
// Note: Chrome implements `window.onwebkitanimationend` and doesn't implement `window.onanimationend`
|
545
|
+
// but at the same time dispatches the `animationend` event and not `webkitAnimationEnd`.
|
546
|
+
// Register both events in case `window.onanimationend` is not supported because of that,
|
547
|
+
// do the same for `transitionend` as Safari is likely to exhibit similar behavior.
|
548
|
+
// Also, the only modern browser that uses vendor prefixes for transitions/keyframes is webkit
|
549
|
+
// therefore there is no reason to test anymore for other vendor prefixes:
|
550
|
+
// http://caniuse.com/#search=transition
|
551
|
+
if (window.ontransitionend === undefined && window.onwebkittransitionend !== undefined) {
|
552
|
+
CSS_PREFIX = '-webkit-';
|
553
|
+
TRANSITION_PROP = 'WebkitTransition';
|
554
|
+
TRANSITIONEND_EVENT = 'webkitTransitionEnd transitionend';
|
555
|
+
} else {
|
556
|
+
TRANSITION_PROP = 'transition';
|
557
|
+
TRANSITIONEND_EVENT = 'transitionend';
|
558
|
+
}
|
559
|
+
|
560
|
+
if (window.onanimationend === undefined && window.onwebkitanimationend !== undefined) {
|
561
|
+
CSS_PREFIX = '-webkit-';
|
562
|
+
ANIMATION_PROP = 'WebkitAnimation';
|
563
|
+
ANIMATIONEND_EVENT = 'webkitAnimationEnd animationend';
|
564
|
+
} else {
|
565
|
+
ANIMATION_PROP = 'animation';
|
566
|
+
ANIMATIONEND_EVENT = 'animationend';
|
567
|
+
}
|
568
|
+
|
569
|
+
var DURATION_KEY = 'Duration';
|
570
|
+
var PROPERTY_KEY = 'Property';
|
571
|
+
var DELAY_KEY = 'Delay';
|
572
|
+
var TIMING_KEY = 'TimingFunction';
|
573
|
+
var ANIMATION_ITERATION_COUNT_KEY = 'IterationCount';
|
574
|
+
var ANIMATION_PLAYSTATE_KEY = 'PlayState';
|
575
|
+
var ELAPSED_TIME_MAX_DECIMAL_PLACES = 3;
|
576
|
+
var CLOSING_TIME_BUFFER = 1.5;
|
577
|
+
var ONE_SECOND = 1000;
|
578
|
+
var BASE_TEN = 10;
|
579
|
+
|
580
|
+
var SAFE_FAST_FORWARD_DURATION_VALUE = 9999;
|
581
|
+
|
582
|
+
var ANIMATION_DELAY_PROP = ANIMATION_PROP + DELAY_KEY;
|
583
|
+
var ANIMATION_DURATION_PROP = ANIMATION_PROP + DURATION_KEY;
|
584
|
+
|
585
|
+
var TRANSITION_DELAY_PROP = TRANSITION_PROP + DELAY_KEY;
|
586
|
+
var TRANSITION_DURATION_PROP = TRANSITION_PROP + DURATION_KEY;
|
587
|
+
|
588
|
+
var DETECT_CSS_PROPERTIES = {
|
589
|
+
transitionDuration: TRANSITION_DURATION_PROP,
|
590
|
+
transitionDelay: TRANSITION_DELAY_PROP,
|
591
|
+
transitionProperty: TRANSITION_PROP + PROPERTY_KEY,
|
592
|
+
animationDuration: ANIMATION_DURATION_PROP,
|
593
|
+
animationDelay: ANIMATION_DELAY_PROP,
|
594
|
+
animationIterationCount: ANIMATION_PROP + ANIMATION_ITERATION_COUNT_KEY
|
595
|
+
};
|
596
|
+
|
597
|
+
var DETECT_STAGGER_CSS_PROPERTIES = {
|
598
|
+
transitionDuration: TRANSITION_DURATION_PROP,
|
599
|
+
transitionDelay: TRANSITION_DELAY_PROP,
|
600
|
+
animationDuration: ANIMATION_DURATION_PROP,
|
601
|
+
animationDelay: ANIMATION_DELAY_PROP
|
602
|
+
};
|
603
|
+
|
604
|
+
function computeCssStyles($window, element, properties) {
|
605
|
+
var styles = Object.create(null);
|
606
|
+
var detectedStyles = $window.getComputedStyle(element) || {};
|
607
|
+
forEach(properties, function(formalStyleName, actualStyleName) {
|
608
|
+
var val = detectedStyles[formalStyleName];
|
609
|
+
if (val) {
|
610
|
+
var c = val.charAt(0);
|
611
|
+
|
612
|
+
// only numerical-based values have a negative sign or digit as the first value
|
613
|
+
if (c === '-' || c === '+' || c >= 0) {
|
614
|
+
val = parseMaxTime(val);
|
615
|
+
}
|
616
|
+
|
617
|
+
// by setting this to null in the event that the delay is not set or is set directly as 0
|
618
|
+
// then we can still allow for zegative values to be used later on and not mistake this
|
619
|
+
// value for being greater than any other negative value.
|
620
|
+
if (val === 0) {
|
621
|
+
val = null;
|
622
|
+
}
|
623
|
+
styles[actualStyleName] = val;
|
624
|
+
}
|
625
|
+
});
|
626
|
+
|
627
|
+
return styles;
|
628
|
+
}
|
629
|
+
|
630
|
+
function parseMaxTime(str) {
|
631
|
+
var maxValue = 0;
|
632
|
+
var values = str.split(/\s*,\s*/);
|
633
|
+
forEach(values, function(value) {
|
634
|
+
// it's always safe to consider only second values and omit `ms` values since
|
635
|
+
// getComputedStyle will always handle the conversion for us
|
636
|
+
if (value.charAt(value.length - 1) == 's') {
|
637
|
+
value = value.substring(0, value.length - 1);
|
638
|
+
}
|
639
|
+
value = parseFloat(value) || 0;
|
640
|
+
maxValue = maxValue ? Math.max(value, maxValue) : value;
|
641
|
+
});
|
642
|
+
return maxValue;
|
643
|
+
}
|
644
|
+
|
645
|
+
function truthyTimingValue(val) {
|
646
|
+
return val === 0 || val != null;
|
647
|
+
}
|
648
|
+
|
649
|
+
function getCssTransitionDurationStyle(duration, applyOnlyDuration) {
|
650
|
+
var style = TRANSITION_PROP;
|
651
|
+
var value = duration + 's';
|
652
|
+
if (applyOnlyDuration) {
|
653
|
+
style += DURATION_KEY;
|
654
|
+
} else {
|
655
|
+
value += ' linear all';
|
656
|
+
}
|
657
|
+
return [style, value];
|
658
|
+
}
|
659
|
+
|
660
|
+
function getCssKeyframeDurationStyle(duration) {
|
661
|
+
return [ANIMATION_DURATION_PROP, duration + 's'];
|
662
|
+
}
|
663
|
+
|
664
|
+
function getCssDelayStyle(delay, isKeyframeAnimation) {
|
665
|
+
var prop = isKeyframeAnimation ? ANIMATION_DELAY_PROP : TRANSITION_DELAY_PROP;
|
666
|
+
return [prop, delay + 's'];
|
667
|
+
}
|
668
|
+
|
669
|
+
function blockTransitions(node, duration) {
|
670
|
+
// we use a negative delay value since it performs blocking
|
671
|
+
// yet it doesn't kill any existing transitions running on the
|
672
|
+
// same element which makes this safe for class-based animations
|
673
|
+
var value = duration ? '-' + duration + 's' : '';
|
674
|
+
applyInlineStyle(node, [TRANSITION_DELAY_PROP, value]);
|
675
|
+
return [TRANSITION_DELAY_PROP, value];
|
676
|
+
}
|
677
|
+
|
678
|
+
function blockKeyframeAnimations(node, applyBlock) {
|
679
|
+
var value = applyBlock ? 'paused' : '';
|
680
|
+
var key = ANIMATION_PROP + ANIMATION_PLAYSTATE_KEY;
|
681
|
+
applyInlineStyle(node, [key, value]);
|
682
|
+
return [key, value];
|
683
|
+
}
|
684
|
+
|
685
|
+
function applyInlineStyle(node, styleTuple) {
|
686
|
+
var prop = styleTuple[0];
|
687
|
+
var value = styleTuple[1];
|
688
|
+
node.style[prop] = value;
|
689
|
+
}
|
690
|
+
|
691
|
+
function createLocalCacheLookup() {
|
692
|
+
var cache = Object.create(null);
|
693
|
+
return {
|
694
|
+
flush: function() {
|
695
|
+
cache = Object.create(null);
|
696
|
+
},
|
697
|
+
|
698
|
+
count: function(key) {
|
699
|
+
var entry = cache[key];
|
700
|
+
return entry ? entry.total : 0;
|
701
|
+
},
|
702
|
+
|
703
|
+
get: function(key) {
|
704
|
+
var entry = cache[key];
|
705
|
+
return entry && entry.value;
|
706
|
+
},
|
707
|
+
|
708
|
+
put: function(key, value) {
|
709
|
+
if (!cache[key]) {
|
710
|
+
cache[key] = { total: 1, value: value };
|
711
|
+
} else {
|
712
|
+
cache[key].total++;
|
713
|
+
}
|
714
|
+
}
|
715
|
+
};
|
716
|
+
}
|
717
|
+
|
718
|
+
var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
|
719
|
+
var gcsLookup = createLocalCacheLookup();
|
720
|
+
var gcsStaggerLookup = createLocalCacheLookup();
|
721
|
+
|
722
|
+
this.$get = ['$window', '$$jqLite', '$$AnimateRunner', '$timeout',
|
723
|
+
'$document', '$sniffer', '$$rAFScheduler',
|
724
|
+
function($window, $$jqLite, $$AnimateRunner, $timeout,
|
725
|
+
$document, $sniffer, $$rAFScheduler) {
|
726
|
+
|
727
|
+
var applyAnimationClasses = applyAnimationClassesFactory($$jqLite);
|
728
|
+
|
729
|
+
var parentCounter = 0;
|
730
|
+
function gcsHashFn(node, extraClasses) {
|
731
|
+
var KEY = "$$ngAnimateParentKey";
|
732
|
+
var parentNode = node.parentNode;
|
733
|
+
var parentID = parentNode[KEY] || (parentNode[KEY] = ++parentCounter);
|
734
|
+
return parentID + '-' + node.getAttribute('class') + '-' + extraClasses;
|
735
|
+
}
|
736
|
+
|
737
|
+
function computeCachedCssStyles(node, className, cacheKey, properties) {
|
738
|
+
var timings = gcsLookup.get(cacheKey);
|
739
|
+
|
740
|
+
if (!timings) {
|
741
|
+
timings = computeCssStyles($window, node, properties);
|
742
|
+
if (timings.animationIterationCount === 'infinite') {
|
743
|
+
timings.animationIterationCount = 1;
|
744
|
+
}
|
745
|
+
}
|
746
|
+
|
747
|
+
// we keep putting this in multiple times even though the value and the cacheKey are the same
|
748
|
+
// because we're keeping an interal tally of how many duplicate animations are detected.
|
749
|
+
gcsLookup.put(cacheKey, timings);
|
750
|
+
return timings;
|
751
|
+
}
|
752
|
+
|
753
|
+
function computeCachedCssStaggerStyles(node, className, cacheKey, properties) {
|
754
|
+
var stagger;
|
755
|
+
|
756
|
+
// if we have one or more existing matches of matching elements
|
757
|
+
// containing the same parent + CSS styles (which is how cacheKey works)
|
758
|
+
// then staggering is possible
|
759
|
+
if (gcsLookup.count(cacheKey) > 0) {
|
760
|
+
stagger = gcsStaggerLookup.get(cacheKey);
|
761
|
+
|
762
|
+
if (!stagger) {
|
763
|
+
var staggerClassName = pendClasses(className, '-stagger');
|
764
|
+
|
765
|
+
$$jqLite.addClass(node, staggerClassName);
|
766
|
+
|
767
|
+
stagger = computeCssStyles($window, node, properties);
|
768
|
+
|
769
|
+
// force the conversion of a null value to zero incase not set
|
770
|
+
stagger.animationDuration = Math.max(stagger.animationDuration, 0);
|
771
|
+
stagger.transitionDuration = Math.max(stagger.transitionDuration, 0);
|
772
|
+
|
773
|
+
$$jqLite.removeClass(node, staggerClassName);
|
774
|
+
|
775
|
+
gcsStaggerLookup.put(cacheKey, stagger);
|
776
|
+
}
|
777
|
+
}
|
778
|
+
|
779
|
+
return stagger || {};
|
780
|
+
}
|
781
|
+
|
782
|
+
var bod = getDomNode($document).body;
|
783
|
+
var rafWaitQueue = [];
|
784
|
+
function waitUntilQuiet(callback) {
|
785
|
+
rafWaitQueue.push(callback);
|
786
|
+
$$rAFScheduler.waitUntilQuiet(function() {
|
787
|
+
gcsLookup.flush();
|
788
|
+
gcsStaggerLookup.flush();
|
789
|
+
|
790
|
+
//the line below will force the browser to perform a repaint so
|
791
|
+
//that all the animated elements within the animation frame will
|
792
|
+
//be properly updated and drawn on screen. This is required to
|
793
|
+
//ensure that the preparation animation is properly flushed so that
|
794
|
+
//the active state picks up from there. DO NOT REMOVE THIS LINE.
|
795
|
+
//DO NOT OPTIMIZE THIS LINE. THE MINIFIER WILL REMOVE IT OTHERWISE WHICH
|
796
|
+
//WILL RESULT IN AN UNPREDICTABLE BUG THAT IS VERY HARD TO TRACK DOWN AND
|
797
|
+
//WILL TAKE YEARS AWAY FROM YOUR LIFE.
|
798
|
+
var width = bod.offsetWidth + 1;
|
799
|
+
|
800
|
+
// we use a for loop to ensure that if the queue is changed
|
801
|
+
// during this looping then it will consider new requests
|
802
|
+
for (var i = 0; i < rafWaitQueue.length; i++) {
|
803
|
+
rafWaitQueue[i](width);
|
804
|
+
}
|
805
|
+
rafWaitQueue.length = 0;
|
806
|
+
});
|
807
|
+
}
|
808
|
+
|
809
|
+
return init;
|
810
|
+
|
811
|
+
function computeTimings(node, className, cacheKey) {
|
812
|
+
var timings = computeCachedCssStyles(node, className, cacheKey, DETECT_CSS_PROPERTIES);
|
813
|
+
var aD = timings.animationDelay;
|
814
|
+
var tD = timings.transitionDelay;
|
815
|
+
timings.maxDelay = aD && tD
|
816
|
+
? Math.max(aD, tD)
|
817
|
+
: (aD || tD);
|
818
|
+
timings.maxDuration = Math.max(
|
819
|
+
timings.animationDuration * timings.animationIterationCount,
|
820
|
+
timings.transitionDuration);
|
821
|
+
|
822
|
+
return timings;
|
823
|
+
}
|
824
|
+
|
825
|
+
function init(element, options) {
|
826
|
+
var node = getDomNode(element);
|
827
|
+
options = prepareAnimationOptions(options);
|
828
|
+
|
829
|
+
var temporaryStyles = [];
|
830
|
+
var classes = element.attr('class');
|
831
|
+
var styles = packageStyles(options);
|
832
|
+
var animationClosed;
|
833
|
+
var animationPaused;
|
834
|
+
var animationCompleted;
|
835
|
+
var runner;
|
836
|
+
var runnerHost;
|
837
|
+
var maxDelay;
|
838
|
+
var maxDelayTime;
|
839
|
+
var maxDuration;
|
840
|
+
var maxDurationTime;
|
841
|
+
|
842
|
+
if (options.duration === 0 || (!$sniffer.animations && !$sniffer.transitions)) {
|
843
|
+
return closeAndReturnNoopAnimator();
|
844
|
+
}
|
845
|
+
|
846
|
+
var method = options.event && isArray(options.event)
|
847
|
+
? options.event.join(' ')
|
848
|
+
: options.event;
|
849
|
+
|
850
|
+
var isStructural = method && options.structural;
|
851
|
+
var structuralClassName = '';
|
852
|
+
var addRemoveClassName = '';
|
853
|
+
|
854
|
+
if (isStructural) {
|
855
|
+
structuralClassName = pendClasses(method, 'ng-', true);
|
856
|
+
} else if (method) {
|
857
|
+
structuralClassName = method;
|
858
|
+
}
|
859
|
+
|
860
|
+
if (options.addClass) {
|
861
|
+
addRemoveClassName += pendClasses(options.addClass, '-add');
|
862
|
+
}
|
863
|
+
|
864
|
+
if (options.removeClass) {
|
865
|
+
if (addRemoveClassName.length) {
|
866
|
+
addRemoveClassName += ' ';
|
867
|
+
}
|
868
|
+
addRemoveClassName += pendClasses(options.removeClass, '-remove');
|
869
|
+
}
|
870
|
+
|
871
|
+
// there may be a situation where a structural animation is combined together
|
872
|
+
// with CSS classes that need to resolve before the animation is computed.
|
873
|
+
// However this means that there is no explicit CSS code to block the animation
|
874
|
+
// from happening (by setting 0s none in the class name). If this is the case
|
875
|
+
// we need to apply the classes before the first rAF so we know to continue if
|
876
|
+
// there actually is a detected transition or keyframe animation
|
877
|
+
if (options.applyClassesEarly && addRemoveClassName.length) {
|
878
|
+
applyAnimationClasses(element, options);
|
879
|
+
addRemoveClassName = '';
|
880
|
+
}
|
881
|
+
|
882
|
+
var setupClasses = [structuralClassName, addRemoveClassName].join(' ').trim();
|
883
|
+
var fullClassName = classes + ' ' + setupClasses;
|
884
|
+
var activeClasses = pendClasses(setupClasses, '-active');
|
885
|
+
var hasToStyles = styles.to && Object.keys(styles.to).length > 0;
|
886
|
+
|
887
|
+
// there is no way we can trigger an animation since no styles and
|
888
|
+
// no classes are being applied which would then trigger a transition
|
889
|
+
if (!hasToStyles && !setupClasses) {
|
890
|
+
return closeAndReturnNoopAnimator();
|
891
|
+
}
|
892
|
+
|
893
|
+
var cacheKey, stagger;
|
894
|
+
if (options.stagger > 0) {
|
895
|
+
var staggerVal = parseFloat(options.stagger);
|
896
|
+
stagger = {
|
897
|
+
transitionDelay: staggerVal,
|
898
|
+
animationDelay: staggerVal,
|
899
|
+
transitionDuration: 0,
|
900
|
+
animationDuration: 0
|
901
|
+
};
|
902
|
+
} else {
|
903
|
+
cacheKey = gcsHashFn(node, fullClassName);
|
904
|
+
stagger = computeCachedCssStaggerStyles(node, setupClasses, cacheKey, DETECT_STAGGER_CSS_PROPERTIES);
|
905
|
+
}
|
906
|
+
|
907
|
+
$$jqLite.addClass(element, setupClasses);
|
908
|
+
|
909
|
+
var applyOnlyDuration;
|
910
|
+
|
911
|
+
if (options.transitionStyle) {
|
912
|
+
var transitionStyle = [TRANSITION_PROP, options.transitionStyle];
|
913
|
+
applyInlineStyle(node, transitionStyle);
|
914
|
+
temporaryStyles.push(transitionStyle);
|
915
|
+
}
|
916
|
+
|
917
|
+
if (options.duration >= 0) {
|
918
|
+
applyOnlyDuration = node.style[TRANSITION_PROP].length > 0;
|
919
|
+
var durationStyle = getCssTransitionDurationStyle(options.duration, applyOnlyDuration);
|
920
|
+
|
921
|
+
// we set the duration so that it will be picked up by getComputedStyle later
|
922
|
+
applyInlineStyle(node, durationStyle);
|
923
|
+
temporaryStyles.push(durationStyle);
|
924
|
+
}
|
925
|
+
|
926
|
+
if (options.keyframeStyle) {
|
927
|
+
var keyframeStyle = [ANIMATION_PROP, options.keyframeStyle];
|
928
|
+
applyInlineStyle(node, keyframeStyle);
|
929
|
+
temporaryStyles.push(keyframeStyle);
|
930
|
+
}
|
931
|
+
|
932
|
+
var itemIndex = stagger
|
933
|
+
? options.staggerIndex >= 0
|
934
|
+
? options.staggerIndex
|
935
|
+
: gcsLookup.count(cacheKey)
|
936
|
+
: 0;
|
937
|
+
|
938
|
+
var isFirst = itemIndex === 0;
|
939
|
+
|
940
|
+
// this is a pre-emptive way of forcing the setup classes to be added and applied INSTANTLY
|
941
|
+
// without causing any combination of transitions to kick in. By adding a negative delay value
|
942
|
+
// it forces the setup class' transition to end immediately. We later then remove the negative
|
943
|
+
// transition delay to allow for the transition to naturally do it's thing. The beauty here is
|
944
|
+
// that if there is no transition defined then nothing will happen and this will also allow
|
945
|
+
// other transitions to be stacked on top of each other without any chopping them out.
|
946
|
+
if (isFirst) {
|
947
|
+
blockTransitions(node, SAFE_FAST_FORWARD_DURATION_VALUE);
|
948
|
+
}
|
949
|
+
|
950
|
+
var timings = computeTimings(node, fullClassName, cacheKey);
|
951
|
+
var relativeDelay = timings.maxDelay;
|
952
|
+
maxDelay = Math.max(relativeDelay, 0);
|
953
|
+
maxDuration = timings.maxDuration;
|
954
|
+
|
955
|
+
var flags = {};
|
956
|
+
flags.hasTransitions = timings.transitionDuration > 0;
|
957
|
+
flags.hasAnimations = timings.animationDuration > 0;
|
958
|
+
flags.hasTransitionAll = flags.hasTransitions && timings.transitionProperty == 'all';
|
959
|
+
flags.applyTransitionDuration = hasToStyles && (
|
960
|
+
(flags.hasTransitions && !flags.hasTransitionAll)
|
961
|
+
|| (flags.hasAnimations && !flags.hasTransitions));
|
962
|
+
flags.applyAnimationDuration = options.duration && flags.hasAnimations;
|
963
|
+
flags.applyTransitionDelay = truthyTimingValue(options.delay) && (flags.applyTransitionDuration || flags.hasTransitions);
|
964
|
+
flags.applyAnimationDelay = truthyTimingValue(options.delay) && flags.hasAnimations;
|
965
|
+
flags.recalculateTimingStyles = addRemoveClassName.length > 0;
|
966
|
+
|
967
|
+
if (flags.applyTransitionDuration || flags.applyAnimationDuration) {
|
968
|
+
maxDuration = options.duration ? parseFloat(options.duration) : maxDuration;
|
969
|
+
|
970
|
+
if (flags.applyTransitionDuration) {
|
971
|
+
flags.hasTransitions = true;
|
972
|
+
timings.transitionDuration = maxDuration;
|
973
|
+
applyOnlyDuration = node.style[TRANSITION_PROP + PROPERTY_KEY].length > 0;
|
974
|
+
temporaryStyles.push(getCssTransitionDurationStyle(maxDuration, applyOnlyDuration));
|
975
|
+
}
|
976
|
+
|
977
|
+
if (flags.applyAnimationDuration) {
|
978
|
+
flags.hasAnimations = true;
|
979
|
+
timings.animationDuration = maxDuration;
|
980
|
+
temporaryStyles.push(getCssKeyframeDurationStyle(maxDuration));
|
981
|
+
}
|
982
|
+
}
|
983
|
+
|
984
|
+
if (maxDuration === 0 && !flags.recalculateTimingStyles) {
|
985
|
+
return closeAndReturnNoopAnimator();
|
986
|
+
}
|
987
|
+
|
988
|
+
// we need to recalculate the delay value since we used a pre-emptive negative
|
989
|
+
// delay value and the delay value is required for the final event checking. This
|
990
|
+
// property will ensure that this will happen after the RAF phase has passed.
|
991
|
+
if (options.duration == null && timings.transitionDuration > 0) {
|
992
|
+
flags.recalculateTimingStyles = flags.recalculateTimingStyles || isFirst;
|
993
|
+
}
|
994
|
+
|
995
|
+
maxDelayTime = maxDelay * ONE_SECOND;
|
996
|
+
maxDurationTime = maxDuration * ONE_SECOND;
|
997
|
+
if (!options.skipBlocking) {
|
998
|
+
flags.blockTransition = timings.transitionDuration > 0;
|
999
|
+
flags.blockKeyframeAnimation = timings.animationDuration > 0 &&
|
1000
|
+
stagger.animationDelay > 0 &&
|
1001
|
+
stagger.animationDuration === 0;
|
1002
|
+
}
|
1003
|
+
|
1004
|
+
applyAnimationFromStyles(element, options);
|
1005
|
+
if (!flags.blockTransition) {
|
1006
|
+
blockTransitions(node, false);
|
1007
|
+
}
|
1008
|
+
|
1009
|
+
applyBlocking(maxDuration);
|
1010
|
+
|
1011
|
+
// TODO(matsko): for 1.5 change this code to have an animator object for better debugging
|
1012
|
+
return {
|
1013
|
+
$$willAnimate: true,
|
1014
|
+
end: endFn,
|
1015
|
+
start: function() {
|
1016
|
+
if (animationClosed) return;
|
1017
|
+
|
1018
|
+
runnerHost = {
|
1019
|
+
end: endFn,
|
1020
|
+
cancel: cancelFn,
|
1021
|
+
resume: null, //this will be set during the start() phase
|
1022
|
+
pause: null
|
1023
|
+
};
|
1024
|
+
|
1025
|
+
runner = new $$AnimateRunner(runnerHost);
|
1026
|
+
|
1027
|
+
waitUntilQuiet(start);
|
1028
|
+
|
1029
|
+
// we don't have access to pause/resume the animation
|
1030
|
+
// since it hasn't run yet. AnimateRunner will therefore
|
1031
|
+
// set noop functions for resume and pause and they will
|
1032
|
+
// later be overridden once the animation is triggered
|
1033
|
+
return runner;
|
1034
|
+
}
|
1035
|
+
};
|
1036
|
+
|
1037
|
+
function endFn() {
|
1038
|
+
close();
|
1039
|
+
}
|
1040
|
+
|
1041
|
+
function cancelFn() {
|
1042
|
+
close(true);
|
1043
|
+
}
|
1044
|
+
|
1045
|
+
function close(rejected) { // jshint ignore:line
|
1046
|
+
// if the promise has been called already then we shouldn't close
|
1047
|
+
// the animation again
|
1048
|
+
if (animationClosed || (animationCompleted && animationPaused)) return;
|
1049
|
+
animationClosed = true;
|
1050
|
+
animationPaused = false;
|
1051
|
+
|
1052
|
+
$$jqLite.removeClass(element, setupClasses);
|
1053
|
+
$$jqLite.removeClass(element, activeClasses);
|
1054
|
+
|
1055
|
+
blockKeyframeAnimations(node, false);
|
1056
|
+
blockTransitions(node, false);
|
1057
|
+
|
1058
|
+
forEach(temporaryStyles, function(entry) {
|
1059
|
+
// There is only one way to remove inline style properties entirely from elements.
|
1060
|
+
// By using `removeProperty` this works, but we need to convert camel-cased CSS
|
1061
|
+
// styles down to hyphenated values.
|
1062
|
+
node.style[entry[0]] = '';
|
1063
|
+
});
|
1064
|
+
|
1065
|
+
applyAnimationClasses(element, options);
|
1066
|
+
applyAnimationStyles(element, options);
|
1067
|
+
|
1068
|
+
// the reason why we have this option is to allow a synchronous closing callback
|
1069
|
+
// that is fired as SOON as the animation ends (when the CSS is removed) or if
|
1070
|
+
// the animation never takes off at all. A good example is a leave animation since
|
1071
|
+
// the element must be removed just after the animation is over or else the element
|
1072
|
+
// will appear on screen for one animation frame causing an overbearing flicker.
|
1073
|
+
if (options.onDone) {
|
1074
|
+
options.onDone();
|
1075
|
+
}
|
1076
|
+
|
1077
|
+
// if the preparation function fails then the promise is not setup
|
1078
|
+
if (runner) {
|
1079
|
+
runner.complete(!rejected);
|
1080
|
+
}
|
1081
|
+
}
|
1082
|
+
|
1083
|
+
function applyBlocking(duration) {
|
1084
|
+
if (flags.blockTransition) {
|
1085
|
+
blockTransitions(node, duration);
|
1086
|
+
}
|
1087
|
+
|
1088
|
+
if (flags.blockKeyframeAnimation) {
|
1089
|
+
blockKeyframeAnimations(node, !!duration);
|
1090
|
+
}
|
1091
|
+
}
|
1092
|
+
|
1093
|
+
function closeAndReturnNoopAnimator() {
|
1094
|
+
runner = new $$AnimateRunner({
|
1095
|
+
end: endFn,
|
1096
|
+
cancel: cancelFn
|
1097
|
+
});
|
1098
|
+
|
1099
|
+
close();
|
1100
|
+
|
1101
|
+
return {
|
1102
|
+
$$willAnimate: false,
|
1103
|
+
start: function() {
|
1104
|
+
return runner;
|
1105
|
+
},
|
1106
|
+
end: endFn
|
1107
|
+
};
|
1108
|
+
}
|
1109
|
+
|
1110
|
+
function start() {
|
1111
|
+
if (animationClosed) return;
|
1112
|
+
|
1113
|
+
var startTime, events = [];
|
1114
|
+
|
1115
|
+
// even though we only pause keyframe animations here the pause flag
|
1116
|
+
// will still happen when transitions are used. Only the transition will
|
1117
|
+
// not be paused since that is not possible. If the animation ends when
|
1118
|
+
// paused then it will not complete until unpaused or cancelled.
|
1119
|
+
var playPause = function(playAnimation) {
|
1120
|
+
if (!animationCompleted) {
|
1121
|
+
animationPaused = !playAnimation;
|
1122
|
+
if (timings.animationDuration) {
|
1123
|
+
var value = blockKeyframeAnimations(node, animationPaused);
|
1124
|
+
animationPaused
|
1125
|
+
? temporaryStyles.push(value)
|
1126
|
+
: removeFromArray(temporaryStyles, value);
|
1127
|
+
}
|
1128
|
+
} else if (animationPaused && playAnimation) {
|
1129
|
+
animationPaused = false;
|
1130
|
+
close();
|
1131
|
+
}
|
1132
|
+
};
|
1133
|
+
|
1134
|
+
// checking the stagger duration prevents an accidently cascade of the CSS delay style
|
1135
|
+
// being inherited from the parent. If the transition duration is zero then we can safely
|
1136
|
+
// rely that the delay value is an intential stagger delay style.
|
1137
|
+
var maxStagger = itemIndex > 0
|
1138
|
+
&& ((timings.transitionDuration && stagger.transitionDuration === 0) ||
|
1139
|
+
(timings.animationDuration && stagger.animationDuration === 0))
|
1140
|
+
&& Math.max(stagger.animationDelay, stagger.transitionDelay);
|
1141
|
+
if (maxStagger) {
|
1142
|
+
$timeout(triggerAnimationStart,
|
1143
|
+
Math.floor(maxStagger * itemIndex * ONE_SECOND),
|
1144
|
+
false);
|
1145
|
+
} else {
|
1146
|
+
triggerAnimationStart();
|
1147
|
+
}
|
1148
|
+
|
1149
|
+
// this will decorate the existing promise runner with pause/resume methods
|
1150
|
+
runnerHost.resume = function() {
|
1151
|
+
playPause(true);
|
1152
|
+
};
|
1153
|
+
|
1154
|
+
runnerHost.pause = function() {
|
1155
|
+
playPause(false);
|
1156
|
+
};
|
1157
|
+
|
1158
|
+
function triggerAnimationStart() {
|
1159
|
+
// just incase a stagger animation kicks in when the animation
|
1160
|
+
// itself was cancelled entirely
|
1161
|
+
if (animationClosed) return;
|
1162
|
+
|
1163
|
+
applyBlocking(false);
|
1164
|
+
|
1165
|
+
forEach(temporaryStyles, function(entry) {
|
1166
|
+
var key = entry[0];
|
1167
|
+
var value = entry[1];
|
1168
|
+
node.style[key] = value;
|
1169
|
+
});
|
1170
|
+
|
1171
|
+
applyAnimationClasses(element, options);
|
1172
|
+
$$jqLite.addClass(element, activeClasses);
|
1173
|
+
|
1174
|
+
if (flags.recalculateTimingStyles) {
|
1175
|
+
fullClassName = node.className + ' ' + setupClasses;
|
1176
|
+
cacheKey = gcsHashFn(node, fullClassName);
|
1177
|
+
|
1178
|
+
timings = computeTimings(node, fullClassName, cacheKey);
|
1179
|
+
relativeDelay = timings.maxDelay;
|
1180
|
+
maxDelay = Math.max(relativeDelay, 0);
|
1181
|
+
maxDuration = timings.maxDuration;
|
1182
|
+
|
1183
|
+
if (maxDuration === 0) {
|
1184
|
+
close();
|
1185
|
+
return;
|
1186
|
+
}
|
1187
|
+
|
1188
|
+
flags.hasTransitions = timings.transitionDuration > 0;
|
1189
|
+
flags.hasAnimations = timings.animationDuration > 0;
|
1190
|
+
}
|
1191
|
+
|
1192
|
+
if (flags.applyTransitionDelay || flags.applyAnimationDelay) {
|
1193
|
+
relativeDelay = typeof options.delay !== "boolean" && truthyTimingValue(options.delay)
|
1194
|
+
? parseFloat(options.delay)
|
1195
|
+
: relativeDelay;
|
1196
|
+
|
1197
|
+
maxDelay = Math.max(relativeDelay, 0);
|
1198
|
+
|
1199
|
+
var delayStyle;
|
1200
|
+
if (flags.applyTransitionDelay) {
|
1201
|
+
timings.transitionDelay = relativeDelay;
|
1202
|
+
delayStyle = getCssDelayStyle(relativeDelay);
|
1203
|
+
temporaryStyles.push(delayStyle);
|
1204
|
+
node.style[delayStyle[0]] = delayStyle[1];
|
1205
|
+
}
|
1206
|
+
|
1207
|
+
if (flags.applyAnimationDelay) {
|
1208
|
+
timings.animationDelay = relativeDelay;
|
1209
|
+
delayStyle = getCssDelayStyle(relativeDelay, true);
|
1210
|
+
temporaryStyles.push(delayStyle);
|
1211
|
+
node.style[delayStyle[0]] = delayStyle[1];
|
1212
|
+
}
|
1213
|
+
}
|
1214
|
+
|
1215
|
+
maxDelayTime = maxDelay * ONE_SECOND;
|
1216
|
+
maxDurationTime = maxDuration * ONE_SECOND;
|
1217
|
+
|
1218
|
+
if (options.easing) {
|
1219
|
+
var easeProp, easeVal = options.easing;
|
1220
|
+
if (flags.hasTransitions) {
|
1221
|
+
easeProp = TRANSITION_PROP + TIMING_KEY;
|
1222
|
+
temporaryStyles.push([easeProp, easeVal]);
|
1223
|
+
node.style[easeProp] = easeVal;
|
1224
|
+
}
|
1225
|
+
if (flags.hasAnimations) {
|
1226
|
+
easeProp = ANIMATION_PROP + TIMING_KEY;
|
1227
|
+
temporaryStyles.push([easeProp, easeVal]);
|
1228
|
+
node.style[easeProp] = easeVal;
|
1229
|
+
}
|
1230
|
+
}
|
1231
|
+
|
1232
|
+
if (timings.transitionDuration) {
|
1233
|
+
events.push(TRANSITIONEND_EVENT);
|
1234
|
+
}
|
1235
|
+
|
1236
|
+
if (timings.animationDuration) {
|
1237
|
+
events.push(ANIMATIONEND_EVENT);
|
1238
|
+
}
|
1239
|
+
|
1240
|
+
startTime = Date.now();
|
1241
|
+
element.on(events.join(' '), onAnimationProgress);
|
1242
|
+
$timeout(onAnimationExpired, maxDelayTime + CLOSING_TIME_BUFFER * maxDurationTime);
|
1243
|
+
|
1244
|
+
applyAnimationToStyles(element, options);
|
1245
|
+
}
|
1246
|
+
|
1247
|
+
function onAnimationExpired() {
|
1248
|
+
// although an expired animation is a failed animation, getting to
|
1249
|
+
// this outcome is very easy if the CSS code screws up. Therefore we
|
1250
|
+
// should still continue normally as if the animation completed correctly.
|
1251
|
+
close();
|
1252
|
+
}
|
1253
|
+
|
1254
|
+
function onAnimationProgress(event) {
|
1255
|
+
event.stopPropagation();
|
1256
|
+
var ev = event.originalEvent || event;
|
1257
|
+
var timeStamp = ev.$manualTimeStamp || ev.timeStamp || Date.now();
|
1258
|
+
|
1259
|
+
/* Firefox (or possibly just Gecko) likes to not round values up
|
1260
|
+
* when a ms measurement is used for the animation */
|
1261
|
+
var elapsedTime = parseFloat(ev.elapsedTime.toFixed(ELAPSED_TIME_MAX_DECIMAL_PLACES));
|
1262
|
+
|
1263
|
+
/* $manualTimeStamp is a mocked timeStamp value which is set
|
1264
|
+
* within browserTrigger(). This is only here so that tests can
|
1265
|
+
* mock animations properly. Real events fallback to event.timeStamp,
|
1266
|
+
* or, if they don't, then a timeStamp is automatically created for them.
|
1267
|
+
* We're checking to see if the timeStamp surpasses the expected delay,
|
1268
|
+
* but we're using elapsedTime instead of the timeStamp on the 2nd
|
1269
|
+
* pre-condition since animations sometimes close off early */
|
1270
|
+
if (Math.max(timeStamp - startTime, 0) >= maxDelayTime && elapsedTime >= maxDuration) {
|
1271
|
+
// we set this flag to ensure that if the transition is paused then, when resumed,
|
1272
|
+
// the animation will automatically close itself since transitions cannot be paused.
|
1273
|
+
animationCompleted = true;
|
1274
|
+
close();
|
1275
|
+
}
|
1276
|
+
}
|
1277
|
+
}
|
1278
|
+
}
|
1279
|
+
}];
|
1280
|
+
}];
|
1281
|
+
|
1282
|
+
var $$AnimateCssDriverProvider = ['$$animationProvider', function($$animationProvider) {
|
1283
|
+
$$animationProvider.drivers.push('$$animateCssDriver');
|
1284
|
+
|
1285
|
+
var NG_ANIMATE_SHIM_CLASS_NAME = 'ng-animate-shim';
|
1286
|
+
var NG_ANIMATE_ANCHOR_CLASS_NAME = 'ng-anchor';
|
1287
|
+
|
1288
|
+
var NG_OUT_ANCHOR_CLASS_NAME = 'ng-anchor-out';
|
1289
|
+
var NG_IN_ANCHOR_CLASS_NAME = 'ng-anchor-in';
|
1290
|
+
|
1291
|
+
this.$get = ['$animateCss', '$rootScope', '$$AnimateRunner', '$rootElement', '$document', '$sniffer',
|
1292
|
+
function($animateCss, $rootScope, $$AnimateRunner, $rootElement, $document, $sniffer) {
|
1293
|
+
|
1294
|
+
// only browsers that support these properties can render animations
|
1295
|
+
if (!$sniffer.animations && !$sniffer.transitions) return noop;
|
1296
|
+
|
1297
|
+
var bodyNode = getDomNode($document).body;
|
1298
|
+
var rootNode = getDomNode($rootElement);
|
1299
|
+
|
1300
|
+
var rootBodyElement = jqLite(bodyNode.parentNode === rootNode ? bodyNode : rootNode);
|
1301
|
+
|
1302
|
+
return function initDriverFn(animationDetails) {
|
1303
|
+
return animationDetails.from && animationDetails.to
|
1304
|
+
? prepareFromToAnchorAnimation(animationDetails.from,
|
1305
|
+
animationDetails.to,
|
1306
|
+
animationDetails.classes,
|
1307
|
+
animationDetails.anchors)
|
1308
|
+
: prepareRegularAnimation(animationDetails);
|
1309
|
+
};
|
1310
|
+
|
1311
|
+
function filterCssClasses(classes) {
|
1312
|
+
//remove all the `ng-` stuff
|
1313
|
+
return classes.replace(/\bng-\S+\b/g, '');
|
1314
|
+
}
|
1315
|
+
|
1316
|
+
function getUniqueValues(a, b) {
|
1317
|
+
if (isString(a)) a = a.split(' ');
|
1318
|
+
if (isString(b)) b = b.split(' ');
|
1319
|
+
return a.filter(function(val) {
|
1320
|
+
return b.indexOf(val) === -1;
|
1321
|
+
}).join(' ');
|
1322
|
+
}
|
1323
|
+
|
1324
|
+
function prepareAnchoredAnimation(classes, outAnchor, inAnchor) {
|
1325
|
+
var clone = jqLite(getDomNode(outAnchor).cloneNode(true));
|
1326
|
+
var startingClasses = filterCssClasses(getClassVal(clone));
|
1327
|
+
|
1328
|
+
outAnchor.addClass(NG_ANIMATE_SHIM_CLASS_NAME);
|
1329
|
+
inAnchor.addClass(NG_ANIMATE_SHIM_CLASS_NAME);
|
1330
|
+
|
1331
|
+
clone.addClass(NG_ANIMATE_ANCHOR_CLASS_NAME);
|
1332
|
+
|
1333
|
+
rootBodyElement.append(clone);
|
1334
|
+
|
1335
|
+
var animatorIn, animatorOut = prepareOutAnimation();
|
1336
|
+
|
1337
|
+
// the user may not end up using the `out` animation and
|
1338
|
+
// only making use of the `in` animation or vice-versa.
|
1339
|
+
// In either case we should allow this and not assume the
|
1340
|
+
// animation is over unless both animations are not used.
|
1341
|
+
if (!animatorOut) {
|
1342
|
+
animatorIn = prepareInAnimation();
|
1343
|
+
if (!animatorIn) {
|
1344
|
+
return end();
|
1345
|
+
}
|
1346
|
+
}
|
1347
|
+
|
1348
|
+
var startingAnimator = animatorOut || animatorIn;
|
1349
|
+
|
1350
|
+
return {
|
1351
|
+
start: function() {
|
1352
|
+
var runner;
|
1353
|
+
|
1354
|
+
var currentAnimation = startingAnimator.start();
|
1355
|
+
currentAnimation.done(function() {
|
1356
|
+
currentAnimation = null;
|
1357
|
+
if (!animatorIn) {
|
1358
|
+
animatorIn = prepareInAnimation();
|
1359
|
+
if (animatorIn) {
|
1360
|
+
currentAnimation = animatorIn.start();
|
1361
|
+
currentAnimation.done(function() {
|
1362
|
+
currentAnimation = null;
|
1363
|
+
end();
|
1364
|
+
runner.complete();
|
1365
|
+
});
|
1366
|
+
return currentAnimation;
|
1367
|
+
}
|
1368
|
+
}
|
1369
|
+
// in the event that there is no `in` animation
|
1370
|
+
end();
|
1371
|
+
runner.complete();
|
1372
|
+
});
|
1373
|
+
|
1374
|
+
runner = new $$AnimateRunner({
|
1375
|
+
end: endFn,
|
1376
|
+
cancel: endFn
|
1377
|
+
});
|
1378
|
+
|
1379
|
+
return runner;
|
1380
|
+
|
1381
|
+
function endFn() {
|
1382
|
+
if (currentAnimation) {
|
1383
|
+
currentAnimation.end();
|
1384
|
+
}
|
1385
|
+
}
|
1386
|
+
}
|
1387
|
+
};
|
1388
|
+
|
1389
|
+
function calculateAnchorStyles(anchor) {
|
1390
|
+
var styles = {};
|
1391
|
+
|
1392
|
+
var coords = getDomNode(anchor).getBoundingClientRect();
|
1393
|
+
|
1394
|
+
// we iterate directly since safari messes up and doesn't return
|
1395
|
+
// all the keys for the coods object when iterated
|
1396
|
+
forEach(['width','height','top','left'], function(key) {
|
1397
|
+
var value = coords[key];
|
1398
|
+
switch (key) {
|
1399
|
+
case 'top':
|
1400
|
+
value += bodyNode.scrollTop;
|
1401
|
+
break;
|
1402
|
+
case 'left':
|
1403
|
+
value += bodyNode.scrollLeft;
|
1404
|
+
break;
|
1405
|
+
}
|
1406
|
+
styles[key] = Math.floor(value) + 'px';
|
1407
|
+
});
|
1408
|
+
return styles;
|
1409
|
+
}
|
1410
|
+
|
1411
|
+
function prepareOutAnimation() {
|
1412
|
+
var animator = $animateCss(clone, {
|
1413
|
+
addClass: NG_OUT_ANCHOR_CLASS_NAME,
|
1414
|
+
delay: true,
|
1415
|
+
from: calculateAnchorStyles(outAnchor)
|
1416
|
+
});
|
1417
|
+
|
1418
|
+
// read the comment within `prepareRegularAnimation` to understand
|
1419
|
+
// why this check is necessary
|
1420
|
+
return animator.$$willAnimate ? animator : null;
|
1421
|
+
}
|
1422
|
+
|
1423
|
+
function getClassVal(element) {
|
1424
|
+
return element.attr('class') || '';
|
1425
|
+
}
|
1426
|
+
|
1427
|
+
function prepareInAnimation() {
|
1428
|
+
var endingClasses = filterCssClasses(getClassVal(inAnchor));
|
1429
|
+
var toAdd = getUniqueValues(endingClasses, startingClasses);
|
1430
|
+
var toRemove = getUniqueValues(startingClasses, endingClasses);
|
1431
|
+
|
1432
|
+
var animator = $animateCss(clone, {
|
1433
|
+
to: calculateAnchorStyles(inAnchor),
|
1434
|
+
addClass: NG_IN_ANCHOR_CLASS_NAME + ' ' + toAdd,
|
1435
|
+
removeClass: NG_OUT_ANCHOR_CLASS_NAME + ' ' + toRemove,
|
1436
|
+
delay: true
|
1437
|
+
});
|
1438
|
+
|
1439
|
+
// read the comment within `prepareRegularAnimation` to understand
|
1440
|
+
// why this check is necessary
|
1441
|
+
return animator.$$willAnimate ? animator : null;
|
1442
|
+
}
|
1443
|
+
|
1444
|
+
function end() {
|
1445
|
+
clone.remove();
|
1446
|
+
outAnchor.removeClass(NG_ANIMATE_SHIM_CLASS_NAME);
|
1447
|
+
inAnchor.removeClass(NG_ANIMATE_SHIM_CLASS_NAME);
|
1448
|
+
}
|
1449
|
+
}
|
1450
|
+
|
1451
|
+
function prepareFromToAnchorAnimation(from, to, classes, anchors) {
|
1452
|
+
var fromAnimation = prepareRegularAnimation(from);
|
1453
|
+
var toAnimation = prepareRegularAnimation(to);
|
1454
|
+
|
1455
|
+
var anchorAnimations = [];
|
1456
|
+
forEach(anchors, function(anchor) {
|
1457
|
+
var outElement = anchor['out'];
|
1458
|
+
var inElement = anchor['in'];
|
1459
|
+
var animator = prepareAnchoredAnimation(classes, outElement, inElement);
|
1460
|
+
if (animator) {
|
1461
|
+
anchorAnimations.push(animator);
|
1462
|
+
}
|
1463
|
+
});
|
1464
|
+
|
1465
|
+
// no point in doing anything when there are no elements to animate
|
1466
|
+
if (!fromAnimation && !toAnimation && anchorAnimations.length === 0) return;
|
1467
|
+
|
1468
|
+
return {
|
1469
|
+
start: function() {
|
1470
|
+
var animationRunners = [];
|
1471
|
+
|
1472
|
+
if (fromAnimation) {
|
1473
|
+
animationRunners.push(fromAnimation.start());
|
1474
|
+
}
|
1475
|
+
|
1476
|
+
if (toAnimation) {
|
1477
|
+
animationRunners.push(toAnimation.start());
|
1478
|
+
}
|
1479
|
+
|
1480
|
+
forEach(anchorAnimations, function(animation) {
|
1481
|
+
animationRunners.push(animation.start());
|
1482
|
+
});
|
1483
|
+
|
1484
|
+
var runner = new $$AnimateRunner({
|
1485
|
+
end: endFn,
|
1486
|
+
cancel: endFn // CSS-driven animations cannot be cancelled, only ended
|
1487
|
+
});
|
1488
|
+
|
1489
|
+
$$AnimateRunner.all(animationRunners, function(status) {
|
1490
|
+
runner.complete(status);
|
1491
|
+
});
|
1492
|
+
|
1493
|
+
return runner;
|
1494
|
+
|
1495
|
+
function endFn() {
|
1496
|
+
forEach(animationRunners, function(runner) {
|
1497
|
+
runner.end();
|
1498
|
+
});
|
1499
|
+
}
|
1500
|
+
}
|
1501
|
+
};
|
1502
|
+
}
|
1503
|
+
|
1504
|
+
function prepareRegularAnimation(animationDetails) {
|
1505
|
+
var element = animationDetails.element;
|
1506
|
+
var options = animationDetails.options || {};
|
1507
|
+
|
1508
|
+
if (animationDetails.structural) {
|
1509
|
+
// structural animations ensure that the CSS classes are always applied
|
1510
|
+
// before the detection starts.
|
1511
|
+
options.structural = options.applyClassesEarly = true;
|
1512
|
+
|
1513
|
+
// we special case the leave animation since we want to ensure that
|
1514
|
+
// the element is removed as soon as the animation is over. Otherwise
|
1515
|
+
// a flicker might appear or the element may not be removed at all
|
1516
|
+
options.event = animationDetails.event;
|
1517
|
+
if (options.event === 'leave') {
|
1518
|
+
options.onDone = options.domOperation;
|
1519
|
+
}
|
1520
|
+
} else {
|
1521
|
+
options.event = null;
|
1522
|
+
}
|
1523
|
+
|
1524
|
+
var animator = $animateCss(element, options);
|
1525
|
+
|
1526
|
+
// the driver lookup code inside of $$animation attempts to spawn a
|
1527
|
+
// driver one by one until a driver returns a.$$willAnimate animator object.
|
1528
|
+
// $animateCss will always return an object, however, it will pass in
|
1529
|
+
// a flag as a hint as to whether an animation was detected or not
|
1530
|
+
return animator.$$willAnimate ? animator : null;
|
1531
|
+
}
|
1532
|
+
}];
|
1533
|
+
}];
|
1534
|
+
|
1535
|
+
// TODO(matsko): use caching here to speed things up for detection
|
1536
|
+
// TODO(matsko): add documentation
|
1537
|
+
// by the time...
|
1538
|
+
|
1539
|
+
var $$AnimateJsProvider = ['$animateProvider', function($animateProvider) {
|
1540
|
+
this.$get = ['$injector', '$$AnimateRunner', '$$rAFMutex', '$$jqLite',
|
1541
|
+
function($injector, $$AnimateRunner, $$rAFMutex, $$jqLite) {
|
1542
|
+
|
1543
|
+
var applyAnimationClasses = applyAnimationClassesFactory($$jqLite);
|
1544
|
+
// $animateJs(element, 'enter');
|
1545
|
+
return function(element, event, classes, options) {
|
1546
|
+
// the `classes` argument is optional and if it is not used
|
1547
|
+
// then the classes will be resolved from the element's className
|
1548
|
+
// property as well as options.addClass/options.removeClass.
|
1549
|
+
if (arguments.length === 3 && isObject(classes)) {
|
1550
|
+
options = classes;
|
1551
|
+
classes = null;
|
1552
|
+
}
|
1553
|
+
|
1554
|
+
options = prepareAnimationOptions(options);
|
1555
|
+
if (!classes) {
|
1556
|
+
classes = element.attr('class') || '';
|
1557
|
+
if (options.addClass) {
|
1558
|
+
classes += ' ' + options.addClass;
|
1559
|
+
}
|
1560
|
+
if (options.removeClass) {
|
1561
|
+
classes += ' ' + options.removeClass;
|
1562
|
+
}
|
1563
|
+
}
|
1564
|
+
|
1565
|
+
var classesToAdd = options.addClass;
|
1566
|
+
var classesToRemove = options.removeClass;
|
1567
|
+
|
1568
|
+
// the lookupAnimations function returns a series of animation objects that are
|
1569
|
+
// matched up with one or more of the CSS classes. These animation objects are
|
1570
|
+
// defined via the module.animation factory function. If nothing is detected then
|
1571
|
+
// we don't return anything which then makes $animation query the next driver.
|
1572
|
+
var animations = lookupAnimations(classes);
|
1573
|
+
var before, after;
|
1574
|
+
if (animations.length) {
|
1575
|
+
var afterFn, beforeFn;
|
1576
|
+
if (event == 'leave') {
|
1577
|
+
beforeFn = 'leave';
|
1578
|
+
afterFn = 'afterLeave'; // TODO(matsko): get rid of this
|
1579
|
+
} else {
|
1580
|
+
beforeFn = 'before' + event.charAt(0).toUpperCase() + event.substr(1);
|
1581
|
+
afterFn = event;
|
1582
|
+
}
|
1583
|
+
|
1584
|
+
if (event !== 'enter' && event !== 'move') {
|
1585
|
+
before = packageAnimations(element, event, options, animations, beforeFn);
|
1586
|
+
}
|
1587
|
+
after = packageAnimations(element, event, options, animations, afterFn);
|
1588
|
+
}
|
1589
|
+
|
1590
|
+
// no matching animations
|
1591
|
+
if (!before && !after) return;
|
1592
|
+
|
1593
|
+
function applyOptions() {
|
1594
|
+
options.domOperation();
|
1595
|
+
applyAnimationClasses(element, options);
|
1596
|
+
}
|
1597
|
+
|
1598
|
+
return {
|
1599
|
+
start: function() {
|
1600
|
+
var closeActiveAnimations;
|
1601
|
+
var chain = [];
|
1602
|
+
|
1603
|
+
if (before) {
|
1604
|
+
chain.push(function(fn) {
|
1605
|
+
closeActiveAnimations = before(fn);
|
1606
|
+
});
|
1607
|
+
}
|
1608
|
+
|
1609
|
+
if (chain.length) {
|
1610
|
+
chain.push(function(fn) {
|
1611
|
+
applyOptions();
|
1612
|
+
fn(true);
|
1613
|
+
});
|
1614
|
+
} else {
|
1615
|
+
applyOptions();
|
1616
|
+
}
|
1617
|
+
|
1618
|
+
if (after) {
|
1619
|
+
chain.push(function(fn) {
|
1620
|
+
closeActiveAnimations = after(fn);
|
1621
|
+
});
|
1622
|
+
}
|
1623
|
+
|
1624
|
+
var animationClosed = false;
|
1625
|
+
var runner = new $$AnimateRunner({
|
1626
|
+
end: function() {
|
1627
|
+
endAnimations();
|
1628
|
+
},
|
1629
|
+
cancel: function() {
|
1630
|
+
endAnimations(true);
|
1631
|
+
}
|
1632
|
+
});
|
1633
|
+
|
1634
|
+
$$AnimateRunner.chain(chain, onComplete);
|
1635
|
+
return runner;
|
1636
|
+
|
1637
|
+
function onComplete(success) {
|
1638
|
+
animationClosed = true;
|
1639
|
+
applyOptions();
|
1640
|
+
applyAnimationStyles(element, options);
|
1641
|
+
runner.complete(success);
|
1642
|
+
}
|
1643
|
+
|
1644
|
+
function endAnimations(cancelled) {
|
1645
|
+
if (!animationClosed) {
|
1646
|
+
(closeActiveAnimations || noop)(cancelled);
|
1647
|
+
onComplete(cancelled);
|
1648
|
+
}
|
1649
|
+
}
|
1650
|
+
}
|
1651
|
+
};
|
1652
|
+
|
1653
|
+
function executeAnimationFn(fn, element, event, options, onDone) {
|
1654
|
+
var args;
|
1655
|
+
switch (event) {
|
1656
|
+
case 'animate':
|
1657
|
+
args = [element, options.from, options.to, onDone];
|
1658
|
+
break;
|
1659
|
+
|
1660
|
+
case 'setClass':
|
1661
|
+
args = [element, classesToAdd, classesToRemove, onDone];
|
1662
|
+
break;
|
1663
|
+
|
1664
|
+
case 'addClass':
|
1665
|
+
args = [element, classesToAdd, onDone];
|
1666
|
+
break;
|
1667
|
+
|
1668
|
+
case 'removeClass':
|
1669
|
+
args = [element, classesToRemove, onDone];
|
1670
|
+
break;
|
1671
|
+
|
1672
|
+
default:
|
1673
|
+
args = [element, onDone];
|
1674
|
+
break;
|
1675
|
+
}
|
1676
|
+
|
1677
|
+
args.push(options);
|
1678
|
+
|
1679
|
+
var value = fn.apply(fn, args);
|
1680
|
+
if (value) {
|
1681
|
+
if (isFunction(value.start)) {
|
1682
|
+
value = value.start();
|
1683
|
+
}
|
1684
|
+
|
1685
|
+
if (value instanceof $$AnimateRunner) {
|
1686
|
+
value.done(onDone);
|
1687
|
+
} else if (isFunction(value)) {
|
1688
|
+
// optional onEnd / onCancel callback
|
1689
|
+
return value;
|
1690
|
+
}
|
1691
|
+
}
|
1692
|
+
|
1693
|
+
return noop;
|
1694
|
+
}
|
1695
|
+
|
1696
|
+
function groupEventedAnimations(element, event, options, animations, fnName) {
|
1697
|
+
var operations = [];
|
1698
|
+
forEach(animations, function(ani) {
|
1699
|
+
var animation = ani[fnName];
|
1700
|
+
if (!animation) return;
|
1701
|
+
|
1702
|
+
// note that all of these animations will run in parallel
|
1703
|
+
operations.push(function() {
|
1704
|
+
var runner;
|
1705
|
+
var endProgressCb;
|
1706
|
+
|
1707
|
+
var resolved = false;
|
1708
|
+
var onAnimationComplete = function(rejected) {
|
1709
|
+
if (!resolved) {
|
1710
|
+
resolved = true;
|
1711
|
+
(endProgressCb || noop)(rejected);
|
1712
|
+
runner.complete(!rejected);
|
1713
|
+
}
|
1714
|
+
};
|
1715
|
+
|
1716
|
+
runner = new $$AnimateRunner({
|
1717
|
+
end: function() {
|
1718
|
+
onAnimationComplete();
|
1719
|
+
},
|
1720
|
+
cancel: function() {
|
1721
|
+
onAnimationComplete(true);
|
1722
|
+
}
|
1723
|
+
});
|
1724
|
+
|
1725
|
+
endProgressCb = executeAnimationFn(animation, element, event, options, function(result) {
|
1726
|
+
var cancelled = result === false;
|
1727
|
+
onAnimationComplete(cancelled);
|
1728
|
+
});
|
1729
|
+
|
1730
|
+
return runner;
|
1731
|
+
});
|
1732
|
+
});
|
1733
|
+
|
1734
|
+
return operations;
|
1735
|
+
}
|
1736
|
+
|
1737
|
+
function packageAnimations(element, event, options, animations, fnName) {
|
1738
|
+
var operations = groupEventedAnimations(element, event, options, animations, fnName);
|
1739
|
+
if (operations.length === 0) {
|
1740
|
+
var a,b;
|
1741
|
+
if (fnName === 'beforeSetClass') {
|
1742
|
+
a = groupEventedAnimations(element, 'removeClass', options, animations, 'beforeRemoveClass');
|
1743
|
+
b = groupEventedAnimations(element, 'addClass', options, animations, 'beforeAddClass');
|
1744
|
+
} else if (fnName === 'setClass') {
|
1745
|
+
a = groupEventedAnimations(element, 'removeClass', options, animations, 'removeClass');
|
1746
|
+
b = groupEventedAnimations(element, 'addClass', options, animations, 'addClass');
|
1747
|
+
}
|
1748
|
+
|
1749
|
+
if (a) {
|
1750
|
+
operations = operations.concat(a);
|
1751
|
+
}
|
1752
|
+
if (b) {
|
1753
|
+
operations = operations.concat(b);
|
1754
|
+
}
|
1755
|
+
}
|
1756
|
+
|
1757
|
+
if (operations.length === 0) return;
|
1758
|
+
|
1759
|
+
// TODO(matsko): add documentation
|
1760
|
+
return function startAnimation(callback) {
|
1761
|
+
var runners = [];
|
1762
|
+
if (operations.length) {
|
1763
|
+
forEach(operations, function(animateFn) {
|
1764
|
+
runners.push(animateFn());
|
1765
|
+
});
|
1766
|
+
}
|
1767
|
+
|
1768
|
+
runners.length ? $$AnimateRunner.all(runners, callback) : callback();
|
1769
|
+
|
1770
|
+
return function endFn(reject) {
|
1771
|
+
forEach(runners, function(runner) {
|
1772
|
+
reject ? runner.cancel() : runner.end();
|
1773
|
+
});
|
1774
|
+
};
|
1775
|
+
};
|
1776
|
+
}
|
1777
|
+
};
|
1778
|
+
|
1779
|
+
function lookupAnimations(classes) {
|
1780
|
+
classes = isArray(classes) ? classes : classes.split(' ');
|
1781
|
+
var matches = [], flagMap = {};
|
1782
|
+
for (var i=0; i < classes.length; i++) {
|
1783
|
+
var klass = classes[i],
|
1784
|
+
animationFactory = $animateProvider.$$registeredAnimations[klass];
|
1785
|
+
if (animationFactory && !flagMap[klass]) {
|
1786
|
+
matches.push($injector.get(animationFactory));
|
1787
|
+
flagMap[klass] = true;
|
1788
|
+
}
|
1789
|
+
}
|
1790
|
+
return matches;
|
1791
|
+
}
|
1792
|
+
}];
|
1793
|
+
}];
|
1794
|
+
|
1795
|
+
var $$AnimateJsDriverProvider = ['$$animationProvider', function($$animationProvider) {
|
1796
|
+
$$animationProvider.drivers.push('$$animateJsDriver');
|
1797
|
+
this.$get = ['$$animateJs', '$$AnimateRunner', function($$animateJs, $$AnimateRunner) {
|
1798
|
+
return function initDriverFn(animationDetails) {
|
1799
|
+
if (animationDetails.from && animationDetails.to) {
|
1800
|
+
var fromAnimation = prepareAnimation(animationDetails.from);
|
1801
|
+
var toAnimation = prepareAnimation(animationDetails.to);
|
1802
|
+
if (!fromAnimation && !toAnimation) return;
|
1803
|
+
|
1804
|
+
return {
|
1805
|
+
start: function() {
|
1806
|
+
var animationRunners = [];
|
1807
|
+
|
1808
|
+
if (fromAnimation) {
|
1809
|
+
animationRunners.push(fromAnimation.start());
|
1810
|
+
}
|
1811
|
+
|
1812
|
+
if (toAnimation) {
|
1813
|
+
animationRunners.push(toAnimation.start());
|
1814
|
+
}
|
1815
|
+
|
1816
|
+
$$AnimateRunner.all(animationRunners, done);
|
1817
|
+
|
1818
|
+
var runner = new $$AnimateRunner({
|
1819
|
+
end: endFnFactory(),
|
1820
|
+
cancel: endFnFactory()
|
1821
|
+
});
|
1822
|
+
|
1823
|
+
return runner;
|
1824
|
+
|
1825
|
+
function endFnFactory() {
|
1826
|
+
return function() {
|
1827
|
+
forEach(animationRunners, function(runner) {
|
1828
|
+
// at this point we cannot cancel animations for groups just yet. 1.5+
|
1829
|
+
runner.end();
|
1830
|
+
});
|
1831
|
+
};
|
1832
|
+
}
|
1833
|
+
|
1834
|
+
function done(status) {
|
1835
|
+
runner.complete(status);
|
1836
|
+
}
|
1837
|
+
}
|
1838
|
+
};
|
1839
|
+
} else {
|
1840
|
+
return prepareAnimation(animationDetails);
|
1841
|
+
}
|
1842
|
+
};
|
1843
|
+
|
1844
|
+
function prepareAnimation(animationDetails) {
|
1845
|
+
// TODO(matsko): make sure to check for grouped animations and delegate down to normal animations
|
1846
|
+
var element = animationDetails.element;
|
1847
|
+
var event = animationDetails.event;
|
1848
|
+
var options = animationDetails.options;
|
1849
|
+
var classes = animationDetails.classes;
|
1850
|
+
return $$animateJs(element, event, classes, options);
|
1851
|
+
}
|
1852
|
+
}];
|
1853
|
+
}];
|
1854
|
+
|
1855
|
+
var NG_ANIMATE_ATTR_NAME = 'data-ng-animate';
|
1856
|
+
var NG_ANIMATE_PIN_DATA = '$ngAnimatePin';
|
1857
|
+
var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
|
1858
|
+
var PRE_DIGEST_STATE = 1;
|
1859
|
+
var RUNNING_STATE = 2;
|
1860
|
+
|
1861
|
+
var rules = this.rules = {
|
1862
|
+
skip: [],
|
1863
|
+
cancel: [],
|
1864
|
+
join: []
|
1865
|
+
};
|
1866
|
+
|
1867
|
+
function isAllowed(ruleType, element, currentAnimation, previousAnimation) {
|
1868
|
+
return rules[ruleType].some(function(fn) {
|
1869
|
+
return fn(element, currentAnimation, previousAnimation);
|
1870
|
+
});
|
1871
|
+
}
|
1872
|
+
|
1873
|
+
function hasAnimationClasses(options, and) {
|
1874
|
+
options = options || {};
|
1875
|
+
var a = (options.addClass || '').length > 0;
|
1876
|
+
var b = (options.removeClass || '').length > 0;
|
1877
|
+
return and ? a && b : a || b;
|
1878
|
+
}
|
1879
|
+
|
1880
|
+
rules.join.push(function(element, newAnimation, currentAnimation) {
|
1881
|
+
// if the new animation is class-based then we can just tack that on
|
1882
|
+
return !newAnimation.structural && hasAnimationClasses(newAnimation.options);
|
1883
|
+
});
|
1884
|
+
|
1885
|
+
rules.skip.push(function(element, newAnimation, currentAnimation) {
|
1886
|
+
// there is no need to animate anything if no classes are being added and
|
1887
|
+
// there is no structural animation that will be triggered
|
1888
|
+
return !newAnimation.structural && !hasAnimationClasses(newAnimation.options);
|
1889
|
+
});
|
1890
|
+
|
1891
|
+
rules.skip.push(function(element, newAnimation, currentAnimation) {
|
1892
|
+
// why should we trigger a new structural animation if the element will
|
1893
|
+
// be removed from the DOM anyway?
|
1894
|
+
return currentAnimation.event == 'leave' && newAnimation.structural;
|
1895
|
+
});
|
1896
|
+
|
1897
|
+
rules.skip.push(function(element, newAnimation, currentAnimation) {
|
1898
|
+
// if there is a current animation then skip the class-based animation
|
1899
|
+
return currentAnimation.structural && !newAnimation.structural;
|
1900
|
+
});
|
1901
|
+
|
1902
|
+
rules.cancel.push(function(element, newAnimation, currentAnimation) {
|
1903
|
+
// there can never be two structural animations running at the same time
|
1904
|
+
return currentAnimation.structural && newAnimation.structural;
|
1905
|
+
});
|
1906
|
+
|
1907
|
+
rules.cancel.push(function(element, newAnimation, currentAnimation) {
|
1908
|
+
// if the previous animation is already running, but the new animation will
|
1909
|
+
// be triggered, but the new animation is structural
|
1910
|
+
return currentAnimation.state === RUNNING_STATE && newAnimation.structural;
|
1911
|
+
});
|
1912
|
+
|
1913
|
+
rules.cancel.push(function(element, newAnimation, currentAnimation) {
|
1914
|
+
var nO = newAnimation.options;
|
1915
|
+
var cO = currentAnimation.options;
|
1916
|
+
|
1917
|
+
// if the exact same CSS class is added/removed then it's safe to cancel it
|
1918
|
+
return (nO.addClass && nO.addClass === cO.removeClass) || (nO.removeClass && nO.removeClass === cO.addClass);
|
1919
|
+
});
|
1920
|
+
|
1921
|
+
this.$get = ['$$rAF', '$rootScope', '$rootElement', '$document', '$$HashMap',
|
1922
|
+
'$$animation', '$$AnimateRunner', '$templateRequest', '$$jqLite',
|
1923
|
+
function($$rAF, $rootScope, $rootElement, $document, $$HashMap,
|
1924
|
+
$$animation, $$AnimateRunner, $templateRequest, $$jqLite) {
|
1925
|
+
|
1926
|
+
var activeAnimationsLookup = new $$HashMap();
|
1927
|
+
var disabledElementsLookup = new $$HashMap();
|
1928
|
+
|
1929
|
+
var animationsEnabled = null;
|
1930
|
+
|
1931
|
+
// Wait until all directive and route-related templates are downloaded and
|
1932
|
+
// compiled. The $templateRequest.totalPendingRequests variable keeps track of
|
1933
|
+
// all of the remote templates being currently downloaded. If there are no
|
1934
|
+
// templates currently downloading then the watcher will still fire anyway.
|
1935
|
+
var deregisterWatch = $rootScope.$watch(
|
1936
|
+
function() { return $templateRequest.totalPendingRequests === 0; },
|
1937
|
+
function(isEmpty) {
|
1938
|
+
if (!isEmpty) return;
|
1939
|
+
deregisterWatch();
|
1940
|
+
|
1941
|
+
// Now that all templates have been downloaded, $animate will wait until
|
1942
|
+
// the post digest queue is empty before enabling animations. By having two
|
1943
|
+
// calls to $postDigest calls we can ensure that the flag is enabled at the
|
1944
|
+
// very end of the post digest queue. Since all of the animations in $animate
|
1945
|
+
// use $postDigest, it's important that the code below executes at the end.
|
1946
|
+
// This basically means that the page is fully downloaded and compiled before
|
1947
|
+
// any animations are triggered.
|
1948
|
+
$rootScope.$$postDigest(function() {
|
1949
|
+
$rootScope.$$postDigest(function() {
|
1950
|
+
// we check for null directly in the event that the application already called
|
1951
|
+
// .enabled() with whatever arguments that it provided it with
|
1952
|
+
if (animationsEnabled === null) {
|
1953
|
+
animationsEnabled = true;
|
1954
|
+
}
|
1955
|
+
});
|
1956
|
+
});
|
1957
|
+
}
|
1958
|
+
);
|
1959
|
+
|
1960
|
+
var bodyElement = jqLite($document[0].body);
|
1961
|
+
|
1962
|
+
var callbackRegistry = {};
|
1963
|
+
|
1964
|
+
// remember that the classNameFilter is set during the provider/config
|
1965
|
+
// stage therefore we can optimize here and setup a helper function
|
1966
|
+
var classNameFilter = $animateProvider.classNameFilter();
|
1967
|
+
var isAnimatableClassName = !classNameFilter
|
1968
|
+
? function() { return true; }
|
1969
|
+
: function(className) {
|
1970
|
+
return classNameFilter.test(className);
|
1971
|
+
};
|
1972
|
+
|
1973
|
+
var applyAnimationClasses = applyAnimationClassesFactory($$jqLite);
|
1974
|
+
|
1975
|
+
function normalizeAnimationOptions(element, options) {
|
1976
|
+
return mergeAnimationOptions(element, options, {});
|
1977
|
+
}
|
1978
|
+
|
1979
|
+
function findCallbacks(element, event) {
|
1980
|
+
var targetNode = getDomNode(element);
|
1981
|
+
|
1982
|
+
var matches = [];
|
1983
|
+
var entries = callbackRegistry[event];
|
1984
|
+
if (entries) {
|
1985
|
+
forEach(entries, function(entry) {
|
1986
|
+
if (entry.node.contains(targetNode)) {
|
1987
|
+
matches.push(entry.callback);
|
1988
|
+
}
|
1989
|
+
});
|
1990
|
+
}
|
1991
|
+
|
1992
|
+
return matches;
|
1993
|
+
}
|
1994
|
+
|
1995
|
+
function triggerCallback(event, element, phase, data) {
|
1996
|
+
$$rAF(function() {
|
1997
|
+
forEach(findCallbacks(element, event), function(callback) {
|
1998
|
+
callback(element, phase, data);
|
1999
|
+
});
|
2000
|
+
});
|
2001
|
+
}
|
2002
|
+
|
2003
|
+
return {
|
2004
|
+
on: function(event, container, callback) {
|
2005
|
+
var node = extractElementNode(container);
|
2006
|
+
callbackRegistry[event] = callbackRegistry[event] || [];
|
2007
|
+
callbackRegistry[event].push({
|
2008
|
+
node: node,
|
2009
|
+
callback: callback
|
2010
|
+
});
|
2011
|
+
},
|
2012
|
+
|
2013
|
+
off: function(event, container, callback) {
|
2014
|
+
var entries = callbackRegistry[event];
|
2015
|
+
if (!entries) return;
|
2016
|
+
|
2017
|
+
callbackRegistry[event] = arguments.length === 1
|
2018
|
+
? null
|
2019
|
+
: filterFromRegistry(entries, container, callback);
|
2020
|
+
|
2021
|
+
function filterFromRegistry(list, matchContainer, matchCallback) {
|
2022
|
+
var containerNode = extractElementNode(matchContainer);
|
2023
|
+
return list.filter(function(entry) {
|
2024
|
+
var isMatch = entry.node === containerNode &&
|
2025
|
+
(!matchCallback || entry.callback === matchCallback);
|
2026
|
+
return !isMatch;
|
2027
|
+
});
|
2028
|
+
}
|
2029
|
+
},
|
2030
|
+
|
2031
|
+
pin: function(element, parentElement) {
|
2032
|
+
assertArg(isElement(element), 'element', 'not an element');
|
2033
|
+
assertArg(isElement(parentElement), 'parentElement', 'not an element');
|
2034
|
+
element.data(NG_ANIMATE_PIN_DATA, parentElement);
|
2035
|
+
},
|
2036
|
+
|
2037
|
+
push: function(element, event, options, domOperation) {
|
2038
|
+
options = options || {};
|
2039
|
+
options.domOperation = domOperation;
|
2040
|
+
return queueAnimation(element, event, options);
|
2041
|
+
},
|
2042
|
+
|
2043
|
+
// this method has four signatures:
|
2044
|
+
// () - global getter
|
2045
|
+
// (bool) - global setter
|
2046
|
+
// (element) - element getter
|
2047
|
+
// (element, bool) - element setter<F37>
|
2048
|
+
enabled: function(element, bool) {
|
2049
|
+
var argCount = arguments.length;
|
2050
|
+
|
2051
|
+
if (argCount === 0) {
|
2052
|
+
// () - Global getter
|
2053
|
+
bool = !!animationsEnabled;
|
2054
|
+
} else {
|
2055
|
+
var hasElement = isElement(element);
|
2056
|
+
|
2057
|
+
if (!hasElement) {
|
2058
|
+
// (bool) - Global setter
|
2059
|
+
bool = animationsEnabled = !!element;
|
2060
|
+
} else {
|
2061
|
+
var node = getDomNode(element);
|
2062
|
+
var recordExists = disabledElementsLookup.get(node);
|
2063
|
+
|
2064
|
+
if (argCount === 1) {
|
2065
|
+
// (element) - Element getter
|
2066
|
+
bool = !recordExists;
|
2067
|
+
} else {
|
2068
|
+
// (element, bool) - Element setter
|
2069
|
+
bool = !!bool;
|
2070
|
+
if (!bool) {
|
2071
|
+
disabledElementsLookup.put(node, true);
|
2072
|
+
} else if (recordExists) {
|
2073
|
+
disabledElementsLookup.remove(node);
|
2074
|
+
}
|
2075
|
+
}
|
2076
|
+
}
|
2077
|
+
}
|
2078
|
+
|
2079
|
+
return bool;
|
2080
|
+
}
|
2081
|
+
};
|
2082
|
+
|
2083
|
+
function queueAnimation(element, event, options) {
|
2084
|
+
var node, parent;
|
2085
|
+
element = stripCommentsFromElement(element);
|
2086
|
+
if (element) {
|
2087
|
+
node = getDomNode(element);
|
2088
|
+
parent = element.parent();
|
2089
|
+
}
|
2090
|
+
|
2091
|
+
options = prepareAnimationOptions(options);
|
2092
|
+
|
2093
|
+
// we create a fake runner with a working promise.
|
2094
|
+
// These methods will become available after the digest has passed
|
2095
|
+
var runner = new $$AnimateRunner();
|
2096
|
+
|
2097
|
+
// there are situations where a directive issues an animation for
|
2098
|
+
// a jqLite wrapper that contains only comment nodes... If this
|
2099
|
+
// happens then there is no way we can perform an animation
|
2100
|
+
if (!node) {
|
2101
|
+
close();
|
2102
|
+
return runner;
|
2103
|
+
}
|
2104
|
+
|
2105
|
+
if (isArray(options.addClass)) {
|
2106
|
+
options.addClass = options.addClass.join(' ');
|
2107
|
+
}
|
2108
|
+
|
2109
|
+
if (isArray(options.removeClass)) {
|
2110
|
+
options.removeClass = options.removeClass.join(' ');
|
2111
|
+
}
|
2112
|
+
|
2113
|
+
if (options.from && !isObject(options.from)) {
|
2114
|
+
options.from = null;
|
2115
|
+
}
|
2116
|
+
|
2117
|
+
if (options.to && !isObject(options.to)) {
|
2118
|
+
options.to = null;
|
2119
|
+
}
|
2120
|
+
|
2121
|
+
var className = [node.className, options.addClass, options.removeClass].join(' ');
|
2122
|
+
if (!isAnimatableClassName(className)) {
|
2123
|
+
close();
|
2124
|
+
return runner;
|
2125
|
+
}
|
2126
|
+
|
2127
|
+
var isStructural = ['enter', 'move', 'leave'].indexOf(event) >= 0;
|
2128
|
+
|
2129
|
+
// this is a hard disable of all animations for the application or on
|
2130
|
+
// the element itself, therefore there is no need to continue further
|
2131
|
+
// past this point if not enabled
|
2132
|
+
var skipAnimations = !animationsEnabled || disabledElementsLookup.get(node);
|
2133
|
+
var existingAnimation = (!skipAnimations && activeAnimationsLookup.get(node)) || {};
|
2134
|
+
var hasExistingAnimation = !!existingAnimation.state;
|
2135
|
+
|
2136
|
+
// there is no point in traversing the same collection of parent ancestors if a followup
|
2137
|
+
// animation will be run on the same element that already did all that checking work
|
2138
|
+
if (!skipAnimations && (!hasExistingAnimation || existingAnimation.state != PRE_DIGEST_STATE)) {
|
2139
|
+
skipAnimations = !areAnimationsAllowed(element, parent, event);
|
2140
|
+
}
|
2141
|
+
|
2142
|
+
if (skipAnimations) {
|
2143
|
+
close();
|
2144
|
+
return runner;
|
2145
|
+
}
|
2146
|
+
|
2147
|
+
if (isStructural) {
|
2148
|
+
closeChildAnimations(element);
|
2149
|
+
}
|
2150
|
+
|
2151
|
+
var newAnimation = {
|
2152
|
+
structural: isStructural,
|
2153
|
+
element: element,
|
2154
|
+
event: event,
|
2155
|
+
close: close,
|
2156
|
+
options: options,
|
2157
|
+
runner: runner
|
2158
|
+
};
|
2159
|
+
|
2160
|
+
if (hasExistingAnimation) {
|
2161
|
+
var skipAnimationFlag = isAllowed('skip', element, newAnimation, existingAnimation);
|
2162
|
+
if (skipAnimationFlag) {
|
2163
|
+
if (existingAnimation.state === RUNNING_STATE) {
|
2164
|
+
close();
|
2165
|
+
return runner;
|
2166
|
+
} else {
|
2167
|
+
mergeAnimationOptions(element, existingAnimation.options, options);
|
2168
|
+
return existingAnimation.runner;
|
2169
|
+
}
|
2170
|
+
}
|
2171
|
+
|
2172
|
+
var cancelAnimationFlag = isAllowed('cancel', element, newAnimation, existingAnimation);
|
2173
|
+
if (cancelAnimationFlag) {
|
2174
|
+
if (existingAnimation.state === RUNNING_STATE) {
|
2175
|
+
// this will end the animation right away and it is safe
|
2176
|
+
// to do so since the animation is already running and the
|
2177
|
+
// runner callback code will run in async
|
2178
|
+
existingAnimation.runner.end();
|
2179
|
+
} else if (existingAnimation.structural) {
|
2180
|
+
// this means that the animation is queued into a digest, but
|
2181
|
+
// hasn't started yet. Therefore it is safe to run the close
|
2182
|
+
// method which will call the runner methods in async.
|
2183
|
+
existingAnimation.close();
|
2184
|
+
} else {
|
2185
|
+
// this will merge the existing animation options into this new follow-up animation
|
2186
|
+
mergeAnimationOptions(element, newAnimation.options, existingAnimation.options);
|
2187
|
+
}
|
2188
|
+
} else {
|
2189
|
+
// a joined animation means that this animation will take over the existing one
|
2190
|
+
// so an example would involve a leave animation taking over an enter. Then when
|
2191
|
+
// the postDigest kicks in the enter will be ignored.
|
2192
|
+
var joinAnimationFlag = isAllowed('join', element, newAnimation, existingAnimation);
|
2193
|
+
if (joinAnimationFlag) {
|
2194
|
+
if (existingAnimation.state === RUNNING_STATE) {
|
2195
|
+
normalizeAnimationOptions(element, options);
|
2196
|
+
} else {
|
2197
|
+
event = newAnimation.event = existingAnimation.event;
|
2198
|
+
options = mergeAnimationOptions(element, existingAnimation.options, newAnimation.options);
|
2199
|
+
return runner;
|
2200
|
+
}
|
2201
|
+
}
|
2202
|
+
}
|
2203
|
+
} else {
|
2204
|
+
// normalization in this case means that it removes redundant CSS classes that
|
2205
|
+
// already exist (addClass) or do not exist (removeClass) on the element
|
2206
|
+
normalizeAnimationOptions(element, options);
|
2207
|
+
}
|
2208
|
+
|
2209
|
+
// when the options are merged and cleaned up we may end up not having to do
|
2210
|
+
// an animation at all, therefore we should check this before issuing a post
|
2211
|
+
// digest callback. Structural animations will always run no matter what.
|
2212
|
+
var isValidAnimation = newAnimation.structural;
|
2213
|
+
if (!isValidAnimation) {
|
2214
|
+
// animate (from/to) can be quickly checked first, otherwise we check if any classes are present
|
2215
|
+
isValidAnimation = (newAnimation.event === 'animate' && Object.keys(newAnimation.options.to || {}).length > 0)
|
2216
|
+
|| hasAnimationClasses(newAnimation.options);
|
2217
|
+
}
|
2218
|
+
|
2219
|
+
if (!isValidAnimation) {
|
2220
|
+
close();
|
2221
|
+
clearElementAnimationState(element);
|
2222
|
+
return runner;
|
2223
|
+
}
|
2224
|
+
|
2225
|
+
if (isStructural) {
|
2226
|
+
closeParentClassBasedAnimations(parent);
|
2227
|
+
}
|
2228
|
+
|
2229
|
+
// the counter keeps track of cancelled animations
|
2230
|
+
var counter = (existingAnimation.counter || 0) + 1;
|
2231
|
+
newAnimation.counter = counter;
|
2232
|
+
|
2233
|
+
markElementAnimationState(element, PRE_DIGEST_STATE, newAnimation);
|
2234
|
+
|
2235
|
+
$rootScope.$$postDigest(function() {
|
2236
|
+
var animationDetails = activeAnimationsLookup.get(node);
|
2237
|
+
var animationCancelled = !animationDetails;
|
2238
|
+
animationDetails = animationDetails || {};
|
2239
|
+
|
2240
|
+
// if addClass/removeClass is called before something like enter then the
|
2241
|
+
// registered parent element may not be present. The code below will ensure
|
2242
|
+
// that a final value for parent element is obtained
|
2243
|
+
var parentElement = element.parent() || [];
|
2244
|
+
|
2245
|
+
// animate/structural/class-based animations all have requirements. Otherwise there
|
2246
|
+
// is no point in performing an animation. The parent node must also be set.
|
2247
|
+
var isValidAnimation = parentElement.length > 0
|
2248
|
+
&& (animationDetails.event === 'animate'
|
2249
|
+
|| animationDetails.structural
|
2250
|
+
|| hasAnimationClasses(animationDetails.options));
|
2251
|
+
|
2252
|
+
// this means that the previous animation was cancelled
|
2253
|
+
// even if the follow-up animation is the same event
|
2254
|
+
if (animationCancelled || animationDetails.counter !== counter || !isValidAnimation) {
|
2255
|
+
// if another animation did not take over then we need
|
2256
|
+
// to make sure that the domOperation and options are
|
2257
|
+
// handled accordingly
|
2258
|
+
if (animationCancelled) {
|
2259
|
+
applyAnimationClasses(element, options);
|
2260
|
+
applyAnimationStyles(element, options);
|
2261
|
+
}
|
2262
|
+
|
2263
|
+
// if the event changed from something like enter to leave then we do
|
2264
|
+
// it, otherwise if it's the same then the end result will be the same too
|
2265
|
+
if (animationCancelled || (isStructural && animationDetails.event !== event)) {
|
2266
|
+
options.domOperation();
|
2267
|
+
runner.end();
|
2268
|
+
}
|
2269
|
+
|
2270
|
+
// in the event that the element animation was not cancelled or a follow-up animation
|
2271
|
+
// isn't allowed to animate from here then we need to clear the state of the element
|
2272
|
+
// so that any future animations won't read the expired animation data.
|
2273
|
+
if (!isValidAnimation) {
|
2274
|
+
clearElementAnimationState(element);
|
2275
|
+
}
|
2276
|
+
|
2277
|
+
return;
|
2278
|
+
}
|
2279
|
+
|
2280
|
+
// this combined multiple class to addClass / removeClass into a setClass event
|
2281
|
+
// so long as a structural event did not take over the animation
|
2282
|
+
event = !animationDetails.structural && hasAnimationClasses(animationDetails.options, true)
|
2283
|
+
? 'setClass'
|
2284
|
+
: animationDetails.event;
|
2285
|
+
|
2286
|
+
if (animationDetails.structural) {
|
2287
|
+
closeParentClassBasedAnimations(parentElement);
|
2288
|
+
}
|
2289
|
+
|
2290
|
+
markElementAnimationState(element, RUNNING_STATE);
|
2291
|
+
var realRunner = $$animation(element, event, animationDetails.options);
|
2292
|
+
realRunner.done(function(status) {
|
2293
|
+
close(!status);
|
2294
|
+
var animationDetails = activeAnimationsLookup.get(node);
|
2295
|
+
if (animationDetails && animationDetails.counter === counter) {
|
2296
|
+
clearElementAnimationState(getDomNode(element));
|
2297
|
+
}
|
2298
|
+
notifyProgress(runner, event, 'close', {});
|
2299
|
+
});
|
2300
|
+
|
2301
|
+
// this will update the runner's flow-control events based on
|
2302
|
+
// the `realRunner` object.
|
2303
|
+
runner.setHost(realRunner);
|
2304
|
+
notifyProgress(runner, event, 'start', {});
|
2305
|
+
});
|
2306
|
+
|
2307
|
+
return runner;
|
2308
|
+
|
2309
|
+
function notifyProgress(runner, event, phase, data) {
|
2310
|
+
triggerCallback(event, element, phase, data);
|
2311
|
+
runner.progress(event, phase, data);
|
2312
|
+
}
|
2313
|
+
|
2314
|
+
function close(reject) { // jshint ignore:line
|
2315
|
+
applyAnimationClasses(element, options);
|
2316
|
+
applyAnimationStyles(element, options);
|
2317
|
+
options.domOperation();
|
2318
|
+
runner.complete(!reject);
|
2319
|
+
}
|
2320
|
+
}
|
2321
|
+
|
2322
|
+
function closeChildAnimations(element) {
|
2323
|
+
var node = getDomNode(element);
|
2324
|
+
var children = node.querySelectorAll('[' + NG_ANIMATE_ATTR_NAME + ']');
|
2325
|
+
forEach(children, function(child) {
|
2326
|
+
var state = parseInt(child.getAttribute(NG_ANIMATE_ATTR_NAME));
|
2327
|
+
var animationDetails = activeAnimationsLookup.get(child);
|
2328
|
+
switch (state) {
|
2329
|
+
case RUNNING_STATE:
|
2330
|
+
animationDetails.runner.end();
|
2331
|
+
/* falls through */
|
2332
|
+
case PRE_DIGEST_STATE:
|
2333
|
+
if (animationDetails) {
|
2334
|
+
activeAnimationsLookup.remove(child);
|
2335
|
+
}
|
2336
|
+
break;
|
2337
|
+
}
|
2338
|
+
});
|
2339
|
+
}
|
2340
|
+
|
2341
|
+
function clearElementAnimationState(element) {
|
2342
|
+
var node = getDomNode(element);
|
2343
|
+
node.removeAttribute(NG_ANIMATE_ATTR_NAME);
|
2344
|
+
activeAnimationsLookup.remove(node);
|
2345
|
+
}
|
2346
|
+
|
2347
|
+
function isMatchingElement(nodeOrElmA, nodeOrElmB) {
|
2348
|
+
return getDomNode(nodeOrElmA) === getDomNode(nodeOrElmB);
|
2349
|
+
}
|
2350
|
+
|
2351
|
+
function closeParentClassBasedAnimations(startingElement) {
|
2352
|
+
var parentNode = getDomNode(startingElement);
|
2353
|
+
do {
|
2354
|
+
if (!parentNode || parentNode.nodeType !== ELEMENT_NODE) break;
|
2355
|
+
|
2356
|
+
var animationDetails = activeAnimationsLookup.get(parentNode);
|
2357
|
+
if (animationDetails) {
|
2358
|
+
examineParentAnimation(parentNode, animationDetails);
|
2359
|
+
}
|
2360
|
+
|
2361
|
+
parentNode = parentNode.parentNode;
|
2362
|
+
} while (true);
|
2363
|
+
|
2364
|
+
// since animations are detected from CSS classes, we need to flush all parent
|
2365
|
+
// class-based animations so that the parent classes are all present for child
|
2366
|
+
// animations to properly function (otherwise any CSS selectors may not work)
|
2367
|
+
function examineParentAnimation(node, animationDetails) {
|
2368
|
+
// enter/leave/move always have priority
|
2369
|
+
if (animationDetails.structural || !hasAnimationClasses(animationDetails.options)) return;
|
2370
|
+
|
2371
|
+
if (animationDetails.state === RUNNING_STATE) {
|
2372
|
+
animationDetails.runner.end();
|
2373
|
+
}
|
2374
|
+
clearElementAnimationState(node);
|
2375
|
+
}
|
2376
|
+
}
|
2377
|
+
|
2378
|
+
function areAnimationsAllowed(element, parentElement, event) {
|
2379
|
+
var bodyElementDetected = false;
|
2380
|
+
var rootElementDetected = false;
|
2381
|
+
var parentAnimationDetected = false;
|
2382
|
+
var animateChildren;
|
2383
|
+
|
2384
|
+
var parentHost = element.data(NG_ANIMATE_PIN_DATA);
|
2385
|
+
if (parentHost) {
|
2386
|
+
parentElement = parentHost;
|
2387
|
+
}
|
2388
|
+
|
2389
|
+
while (parentElement && parentElement.length) {
|
2390
|
+
if (!rootElementDetected) {
|
2391
|
+
// angular doesn't want to attempt to animate elements outside of the application
|
2392
|
+
// therefore we need to ensure that the rootElement is an ancestor of the current element
|
2393
|
+
rootElementDetected = isMatchingElement(parentElement, $rootElement);
|
2394
|
+
}
|
2395
|
+
|
2396
|
+
var parentNode = parentElement[0];
|
2397
|
+
if (parentNode.nodeType !== ELEMENT_NODE) {
|
2398
|
+
// no point in inspecting the #document element
|
2399
|
+
break;
|
2400
|
+
}
|
2401
|
+
|
2402
|
+
var details = activeAnimationsLookup.get(parentNode) || {};
|
2403
|
+
// either an enter, leave or move animation will commence
|
2404
|
+
// therefore we can't allow any animations to take place
|
2405
|
+
// but if a parent animation is class-based then that's ok
|
2406
|
+
if (!parentAnimationDetected) {
|
2407
|
+
parentAnimationDetected = details.structural || disabledElementsLookup.get(parentNode);
|
2408
|
+
}
|
2409
|
+
|
2410
|
+
if (isUndefined(animateChildren) || animateChildren === true) {
|
2411
|
+
var value = parentElement.data(NG_ANIMATE_CHILDREN_DATA);
|
2412
|
+
if (isDefined(value)) {
|
2413
|
+
animateChildren = value;
|
2414
|
+
}
|
2415
|
+
}
|
2416
|
+
|
2417
|
+
// there is no need to continue traversing at this point
|
2418
|
+
if (parentAnimationDetected && animateChildren === false) break;
|
2419
|
+
|
2420
|
+
if (!rootElementDetected) {
|
2421
|
+
// angular doesn't want to attempt to animate elements outside of the application
|
2422
|
+
// therefore we need to ensure that the rootElement is an ancestor of the current element
|
2423
|
+
rootElementDetected = isMatchingElement(parentElement, $rootElement);
|
2424
|
+
if (!rootElementDetected) {
|
2425
|
+
parentHost = parentElement.data(NG_ANIMATE_PIN_DATA);
|
2426
|
+
if (parentHost) {
|
2427
|
+
parentElement = parentHost;
|
2428
|
+
}
|
2429
|
+
}
|
2430
|
+
}
|
2431
|
+
|
2432
|
+
if (!bodyElementDetected) {
|
2433
|
+
// we also need to ensure that the element is or will be apart of the body element
|
2434
|
+
// otherwise it is pointless to even issue an animation to be rendered
|
2435
|
+
bodyElementDetected = isMatchingElement(parentElement, bodyElement);
|
2436
|
+
}
|
2437
|
+
|
2438
|
+
parentElement = parentElement.parent();
|
2439
|
+
}
|
2440
|
+
|
2441
|
+
var allowAnimation = !parentAnimationDetected || animateChildren;
|
2442
|
+
return allowAnimation && rootElementDetected && bodyElementDetected;
|
2443
|
+
}
|
2444
|
+
|
2445
|
+
function markElementAnimationState(element, state, details) {
|
2446
|
+
details = details || {};
|
2447
|
+
details.state = state;
|
2448
|
+
|
2449
|
+
var node = getDomNode(element);
|
2450
|
+
node.setAttribute(NG_ANIMATE_ATTR_NAME, state);
|
2451
|
+
|
2452
|
+
var oldValue = activeAnimationsLookup.get(node);
|
2453
|
+
var newValue = oldValue
|
2454
|
+
? extend(oldValue, details)
|
2455
|
+
: details;
|
2456
|
+
activeAnimationsLookup.put(node, newValue);
|
2457
|
+
}
|
2458
|
+
}];
|
2459
|
+
}];
|
2460
|
+
|
2461
|
+
var $$rAFMutexFactory = ['$$rAF', function($$rAF) {
|
2462
|
+
return function() {
|
2463
|
+
var passed = false;
|
2464
|
+
$$rAF(function() {
|
2465
|
+
passed = true;
|
2466
|
+
});
|
2467
|
+
return function(fn) {
|
2468
|
+
passed ? fn() : $$rAF(fn);
|
2469
|
+
};
|
2470
|
+
};
|
2471
|
+
}];
|
2472
|
+
|
2473
|
+
var $$AnimateRunnerFactory = ['$q', '$$rAFMutex', function($q, $$rAFMutex) {
|
2474
|
+
var INITIAL_STATE = 0;
|
2475
|
+
var DONE_PENDING_STATE = 1;
|
2476
|
+
var DONE_COMPLETE_STATE = 2;
|
2477
|
+
|
2478
|
+
AnimateRunner.chain = function(chain, callback) {
|
2479
|
+
var index = 0;
|
2480
|
+
|
2481
|
+
next();
|
2482
|
+
function next() {
|
2483
|
+
if (index === chain.length) {
|
2484
|
+
callback(true);
|
2485
|
+
return;
|
2486
|
+
}
|
2487
|
+
|
2488
|
+
chain[index](function(response) {
|
2489
|
+
if (response === false) {
|
2490
|
+
callback(false);
|
2491
|
+
return;
|
2492
|
+
}
|
2493
|
+
index++;
|
2494
|
+
next();
|
2495
|
+
});
|
2496
|
+
}
|
2497
|
+
};
|
2498
|
+
|
2499
|
+
AnimateRunner.all = function(runners, callback) {
|
2500
|
+
var count = 0;
|
2501
|
+
var status = true;
|
2502
|
+
forEach(runners, function(runner) {
|
2503
|
+
runner.done(onProgress);
|
2504
|
+
});
|
2505
|
+
|
2506
|
+
function onProgress(response) {
|
2507
|
+
status = status && response;
|
2508
|
+
if (++count === runners.length) {
|
2509
|
+
callback(status);
|
2510
|
+
}
|
2511
|
+
}
|
2512
|
+
};
|
2513
|
+
|
2514
|
+
function AnimateRunner(host) {
|
2515
|
+
this.setHost(host);
|
2516
|
+
|
2517
|
+
this._doneCallbacks = [];
|
2518
|
+
this._runInAnimationFrame = $$rAFMutex();
|
2519
|
+
this._state = 0;
|
2520
|
+
}
|
2521
|
+
|
2522
|
+
AnimateRunner.prototype = {
|
2523
|
+
setHost: function(host) {
|
2524
|
+
this.host = host || {};
|
2525
|
+
},
|
2526
|
+
|
2527
|
+
done: function(fn) {
|
2528
|
+
if (this._state === DONE_COMPLETE_STATE) {
|
2529
|
+
fn();
|
2530
|
+
} else {
|
2531
|
+
this._doneCallbacks.push(fn);
|
2532
|
+
}
|
2533
|
+
},
|
2534
|
+
|
2535
|
+
progress: noop,
|
2536
|
+
|
2537
|
+
getPromise: function() {
|
2538
|
+
if (!this.promise) {
|
2539
|
+
var self = this;
|
2540
|
+
this.promise = $q(function(resolve, reject) {
|
2541
|
+
self.done(function(status) {
|
2542
|
+
status === false ? reject() : resolve();
|
2543
|
+
});
|
2544
|
+
});
|
2545
|
+
}
|
2546
|
+
return this.promise;
|
2547
|
+
},
|
2548
|
+
|
2549
|
+
then: function(resolveHandler, rejectHandler) {
|
2550
|
+
return this.getPromise().then(resolveHandler, rejectHandler);
|
2551
|
+
},
|
2552
|
+
|
2553
|
+
'catch': function(handler) {
|
2554
|
+
return this.getPromise()['catch'](handler);
|
2555
|
+
},
|
2556
|
+
|
2557
|
+
'finally': function(handler) {
|
2558
|
+
return this.getPromise()['finally'](handler);
|
2559
|
+
},
|
2560
|
+
|
2561
|
+
pause: function() {
|
2562
|
+
if (this.host.pause) {
|
2563
|
+
this.host.pause();
|
2564
|
+
}
|
2565
|
+
},
|
2566
|
+
|
2567
|
+
resume: function() {
|
2568
|
+
if (this.host.resume) {
|
2569
|
+
this.host.resume();
|
2570
|
+
}
|
2571
|
+
},
|
2572
|
+
|
2573
|
+
end: function() {
|
2574
|
+
if (this.host.end) {
|
2575
|
+
this.host.end();
|
2576
|
+
}
|
2577
|
+
this._resolve(true);
|
2578
|
+
},
|
2579
|
+
|
2580
|
+
cancel: function() {
|
2581
|
+
if (this.host.cancel) {
|
2582
|
+
this.host.cancel();
|
2583
|
+
}
|
2584
|
+
this._resolve(false);
|
2585
|
+
},
|
2586
|
+
|
2587
|
+
complete: function(response) {
|
2588
|
+
var self = this;
|
2589
|
+
if (self._state === INITIAL_STATE) {
|
2590
|
+
self._state = DONE_PENDING_STATE;
|
2591
|
+
self._runInAnimationFrame(function() {
|
2592
|
+
self._resolve(response);
|
2593
|
+
});
|
2594
|
+
}
|
2595
|
+
},
|
2596
|
+
|
2597
|
+
_resolve: function(response) {
|
2598
|
+
if (this._state !== DONE_COMPLETE_STATE) {
|
2599
|
+
forEach(this._doneCallbacks, function(fn) {
|
2600
|
+
fn(response);
|
2601
|
+
});
|
2602
|
+
this._doneCallbacks.length = 0;
|
2603
|
+
this._state = DONE_COMPLETE_STATE;
|
2604
|
+
}
|
2605
|
+
}
|
2606
|
+
};
|
2607
|
+
|
2608
|
+
return AnimateRunner;
|
2609
|
+
}];
|
2610
|
+
|
2611
|
+
var $$AnimationProvider = ['$animateProvider', function($animateProvider) {
|
2612
|
+
var NG_ANIMATE_REF_ATTR = 'ng-animate-ref';
|
2613
|
+
|
2614
|
+
var drivers = this.drivers = [];
|
2615
|
+
|
2616
|
+
var RUNNER_STORAGE_KEY = '$$animationRunner';
|
2617
|
+
|
2618
|
+
function setRunner(element, runner) {
|
2619
|
+
element.data(RUNNER_STORAGE_KEY, runner);
|
2620
|
+
}
|
2621
|
+
|
2622
|
+
function removeRunner(element) {
|
2623
|
+
element.removeData(RUNNER_STORAGE_KEY);
|
2624
|
+
}
|
2625
|
+
|
2626
|
+
function getRunner(element) {
|
2627
|
+
return element.data(RUNNER_STORAGE_KEY);
|
2628
|
+
}
|
2629
|
+
|
2630
|
+
this.$get = ['$$jqLite', '$rootScope', '$injector', '$$AnimateRunner', '$$rAFScheduler',
|
2631
|
+
function($$jqLite, $rootScope, $injector, $$AnimateRunner, $$rAFScheduler) {
|
2632
|
+
|
2633
|
+
var animationQueue = [];
|
2634
|
+
var applyAnimationClasses = applyAnimationClassesFactory($$jqLite);
|
2635
|
+
|
2636
|
+
var totalPendingClassBasedAnimations = 0;
|
2637
|
+
var totalActiveClassBasedAnimations = 0;
|
2638
|
+
var classBasedAnimationsQueue = [];
|
2639
|
+
|
2640
|
+
// TODO(matsko): document the signature in a better way
|
2641
|
+
return function(element, event, options) {
|
2642
|
+
options = prepareAnimationOptions(options);
|
2643
|
+
var isStructural = ['enter', 'move', 'leave'].indexOf(event) >= 0;
|
2644
|
+
|
2645
|
+
// there is no animation at the current moment, however
|
2646
|
+
// these runner methods will get later updated with the
|
2647
|
+
// methods leading into the driver's end/cancel methods
|
2648
|
+
// for now they just stop the animation from starting
|
2649
|
+
var runner = new $$AnimateRunner({
|
2650
|
+
end: function() { close(); },
|
2651
|
+
cancel: function() { close(true); }
|
2652
|
+
});
|
2653
|
+
|
2654
|
+
if (!drivers.length) {
|
2655
|
+
close();
|
2656
|
+
return runner;
|
2657
|
+
}
|
2658
|
+
|
2659
|
+
setRunner(element, runner);
|
2660
|
+
|
2661
|
+
var classes = mergeClasses(element.attr('class'), mergeClasses(options.addClass, options.removeClass));
|
2662
|
+
var tempClasses = options.tempClasses;
|
2663
|
+
if (tempClasses) {
|
2664
|
+
classes += ' ' + tempClasses;
|
2665
|
+
options.tempClasses = null;
|
2666
|
+
}
|
2667
|
+
|
2668
|
+
var classBasedIndex;
|
2669
|
+
if (!isStructural) {
|
2670
|
+
classBasedIndex = totalPendingClassBasedAnimations;
|
2671
|
+
totalPendingClassBasedAnimations += 1;
|
2672
|
+
}
|
2673
|
+
|
2674
|
+
animationQueue.push({
|
2675
|
+
// this data is used by the postDigest code and passed into
|
2676
|
+
// the driver step function
|
2677
|
+
element: element,
|
2678
|
+
classes: classes,
|
2679
|
+
event: event,
|
2680
|
+
classBasedIndex: classBasedIndex,
|
2681
|
+
structural: isStructural,
|
2682
|
+
options: options,
|
2683
|
+
beforeStart: beforeStart,
|
2684
|
+
close: close
|
2685
|
+
});
|
2686
|
+
|
2687
|
+
element.on('$destroy', handleDestroyedElement);
|
2688
|
+
|
2689
|
+
// we only want there to be one function called within the post digest
|
2690
|
+
// block. This way we can group animations for all the animations that
|
2691
|
+
// were apart of the same postDigest flush call.
|
2692
|
+
if (animationQueue.length > 1) return runner;
|
2693
|
+
|
2694
|
+
$rootScope.$$postDigest(function() {
|
2695
|
+
totalActiveClassBasedAnimations = totalPendingClassBasedAnimations;
|
2696
|
+
totalPendingClassBasedAnimations = 0;
|
2697
|
+
classBasedAnimationsQueue.length = 0;
|
2698
|
+
|
2699
|
+
var animations = [];
|
2700
|
+
forEach(animationQueue, function(entry) {
|
2701
|
+
// the element was destroyed early on which removed the runner
|
2702
|
+
// form its storage. This means we can't animate this element
|
2703
|
+
// at all and it already has been closed due to destruction.
|
2704
|
+
if (getRunner(entry.element)) {
|
2705
|
+
animations.push(entry);
|
2706
|
+
}
|
2707
|
+
});
|
2708
|
+
|
2709
|
+
// now any future animations will be in another postDigest
|
2710
|
+
animationQueue.length = 0;
|
2711
|
+
|
2712
|
+
forEach(groupAnimations(animations), function(animationEntry) {
|
2713
|
+
if (animationEntry.structural) {
|
2714
|
+
triggerAnimationStart();
|
2715
|
+
} else {
|
2716
|
+
classBasedAnimationsQueue.push({
|
2717
|
+
node: getDomNode(animationEntry.element),
|
2718
|
+
fn: triggerAnimationStart
|
2719
|
+
});
|
2720
|
+
|
2721
|
+
if (animationEntry.classBasedIndex === totalActiveClassBasedAnimations - 1) {
|
2722
|
+
// we need to sort each of the animations in order of parent to child
|
2723
|
+
// relationships. This ensures that the child classes are applied at the
|
2724
|
+
// right time.
|
2725
|
+
classBasedAnimationsQueue = classBasedAnimationsQueue.sort(function(a,b) {
|
2726
|
+
return b.node.contains(a.node);
|
2727
|
+
}).map(function(entry) {
|
2728
|
+
return entry.fn;
|
2729
|
+
});
|
2730
|
+
|
2731
|
+
$$rAFScheduler(classBasedAnimationsQueue);
|
2732
|
+
}
|
2733
|
+
}
|
2734
|
+
|
2735
|
+
function triggerAnimationStart() {
|
2736
|
+
// it's important that we apply the `ng-animate` CSS class and the
|
2737
|
+
// temporary classes before we do any driver invoking since these
|
2738
|
+
// CSS classes may be required for proper CSS detection.
|
2739
|
+
animationEntry.beforeStart();
|
2740
|
+
|
2741
|
+
var startAnimationFn, closeFn = animationEntry.close;
|
2742
|
+
|
2743
|
+
// in the event that the element was removed before the digest runs or
|
2744
|
+
// during the RAF sequencing then we should not trigger the animation.
|
2745
|
+
var targetElement = animationEntry.anchors
|
2746
|
+
? (animationEntry.from.element || animationEntry.to.element)
|
2747
|
+
: animationEntry.element;
|
2748
|
+
|
2749
|
+
if (getRunner(targetElement)) {
|
2750
|
+
var operation = invokeFirstDriver(animationEntry);
|
2751
|
+
if (operation) {
|
2752
|
+
startAnimationFn = operation.start;
|
2753
|
+
}
|
2754
|
+
}
|
2755
|
+
|
2756
|
+
if (!startAnimationFn) {
|
2757
|
+
closeFn();
|
2758
|
+
} else {
|
2759
|
+
var animationRunner = startAnimationFn();
|
2760
|
+
animationRunner.done(function(status) {
|
2761
|
+
closeFn(!status);
|
2762
|
+
});
|
2763
|
+
updateAnimationRunners(animationEntry, animationRunner);
|
2764
|
+
}
|
2765
|
+
}
|
2766
|
+
});
|
2767
|
+
});
|
2768
|
+
|
2769
|
+
return runner;
|
2770
|
+
|
2771
|
+
// TODO(matsko): change to reference nodes
|
2772
|
+
function getAnchorNodes(node) {
|
2773
|
+
var SELECTOR = '[' + NG_ANIMATE_REF_ATTR + ']';
|
2774
|
+
var items = node.hasAttribute(NG_ANIMATE_REF_ATTR)
|
2775
|
+
? [node]
|
2776
|
+
: node.querySelectorAll(SELECTOR);
|
2777
|
+
var anchors = [];
|
2778
|
+
forEach(items, function(node) {
|
2779
|
+
var attr = node.getAttribute(NG_ANIMATE_REF_ATTR);
|
2780
|
+
if (attr && attr.length) {
|
2781
|
+
anchors.push(node);
|
2782
|
+
}
|
2783
|
+
});
|
2784
|
+
return anchors;
|
2785
|
+
}
|
2786
|
+
|
2787
|
+
function groupAnimations(animations) {
|
2788
|
+
var preparedAnimations = [];
|
2789
|
+
var refLookup = {};
|
2790
|
+
forEach(animations, function(animation, index) {
|
2791
|
+
var element = animation.element;
|
2792
|
+
var node = getDomNode(element);
|
2793
|
+
var event = animation.event;
|
2794
|
+
var enterOrMove = ['enter', 'move'].indexOf(event) >= 0;
|
2795
|
+
var anchorNodes = animation.structural ? getAnchorNodes(node) : [];
|
2796
|
+
|
2797
|
+
if (anchorNodes.length) {
|
2798
|
+
var direction = enterOrMove ? 'to' : 'from';
|
2799
|
+
|
2800
|
+
forEach(anchorNodes, function(anchor) {
|
2801
|
+
var key = anchor.getAttribute(NG_ANIMATE_REF_ATTR);
|
2802
|
+
refLookup[key] = refLookup[key] || {};
|
2803
|
+
refLookup[key][direction] = {
|
2804
|
+
animationID: index,
|
2805
|
+
element: jqLite(anchor)
|
2806
|
+
};
|
2807
|
+
});
|
2808
|
+
} else {
|
2809
|
+
preparedAnimations.push(animation);
|
2810
|
+
}
|
2811
|
+
});
|
2812
|
+
|
2813
|
+
var usedIndicesLookup = {};
|
2814
|
+
var anchorGroups = {};
|
2815
|
+
forEach(refLookup, function(operations, key) {
|
2816
|
+
var from = operations.from;
|
2817
|
+
var to = operations.to;
|
2818
|
+
|
2819
|
+
if (!from || !to) {
|
2820
|
+
// only one of these is set therefore we can't have an
|
2821
|
+
// anchor animation since all three pieces are required
|
2822
|
+
var index = from ? from.animationID : to.animationID;
|
2823
|
+
var indexKey = index.toString();
|
2824
|
+
if (!usedIndicesLookup[indexKey]) {
|
2825
|
+
usedIndicesLookup[indexKey] = true;
|
2826
|
+
preparedAnimations.push(animations[index]);
|
2827
|
+
}
|
2828
|
+
return;
|
2829
|
+
}
|
2830
|
+
|
2831
|
+
var fromAnimation = animations[from.animationID];
|
2832
|
+
var toAnimation = animations[to.animationID];
|
2833
|
+
var lookupKey = from.animationID.toString();
|
2834
|
+
if (!anchorGroups[lookupKey]) {
|
2835
|
+
var group = anchorGroups[lookupKey] = {
|
2836
|
+
structural: true,
|
2837
|
+
beforeStart: function() {
|
2838
|
+
fromAnimation.beforeStart();
|
2839
|
+
toAnimation.beforeStart();
|
2840
|
+
},
|
2841
|
+
close: function() {
|
2842
|
+
fromAnimation.close();
|
2843
|
+
toAnimation.close();
|
2844
|
+
},
|
2845
|
+
classes: cssClassesIntersection(fromAnimation.classes, toAnimation.classes),
|
2846
|
+
from: fromAnimation,
|
2847
|
+
to: toAnimation,
|
2848
|
+
anchors: [] // TODO(matsko): change to reference nodes
|
2849
|
+
};
|
2850
|
+
|
2851
|
+
// the anchor animations require that the from and to elements both have at least
|
2852
|
+
// one shared CSS class which effictively marries the two elements together to use
|
2853
|
+
// the same animation driver and to properly sequence the anchor animation.
|
2854
|
+
if (group.classes.length) {
|
2855
|
+
preparedAnimations.push(group);
|
2856
|
+
} else {
|
2857
|
+
preparedAnimations.push(fromAnimation);
|
2858
|
+
preparedAnimations.push(toAnimation);
|
2859
|
+
}
|
2860
|
+
}
|
2861
|
+
|
2862
|
+
anchorGroups[lookupKey].anchors.push({
|
2863
|
+
'out': from.element, 'in': to.element
|
2864
|
+
});
|
2865
|
+
});
|
2866
|
+
|
2867
|
+
return preparedAnimations;
|
2868
|
+
}
|
2869
|
+
|
2870
|
+
function cssClassesIntersection(a,b) {
|
2871
|
+
a = a.split(' ');
|
2872
|
+
b = b.split(' ');
|
2873
|
+
var matches = [];
|
2874
|
+
|
2875
|
+
for (var i = 0; i < a.length; i++) {
|
2876
|
+
var aa = a[i];
|
2877
|
+
if (aa.substring(0,3) === 'ng-') continue;
|
2878
|
+
|
2879
|
+
for (var j = 0; j < b.length; j++) {
|
2880
|
+
if (aa === b[j]) {
|
2881
|
+
matches.push(aa);
|
2882
|
+
break;
|
2883
|
+
}
|
2884
|
+
}
|
2885
|
+
}
|
2886
|
+
|
2887
|
+
return matches.join(' ');
|
2888
|
+
}
|
2889
|
+
|
2890
|
+
function invokeFirstDriver(animationDetails) {
|
2891
|
+
// we loop in reverse order since the more general drivers (like CSS and JS)
|
2892
|
+
// may attempt more elements, but custom drivers are more particular
|
2893
|
+
for (var i = drivers.length - 1; i >= 0; i--) {
|
2894
|
+
var driverName = drivers[i];
|
2895
|
+
if (!$injector.has(driverName)) continue; // TODO(matsko): remove this check
|
2896
|
+
|
2897
|
+
var factory = $injector.get(driverName);
|
2898
|
+
var driver = factory(animationDetails);
|
2899
|
+
if (driver) {
|
2900
|
+
return driver;
|
2901
|
+
}
|
2902
|
+
}
|
2903
|
+
}
|
2904
|
+
|
2905
|
+
function beforeStart() {
|
2906
|
+
element.addClass(NG_ANIMATE_CLASSNAME);
|
2907
|
+
if (tempClasses) {
|
2908
|
+
$$jqLite.addClass(element, tempClasses);
|
2909
|
+
}
|
2910
|
+
}
|
2911
|
+
|
2912
|
+
function updateAnimationRunners(animation, newRunner) {
|
2913
|
+
if (animation.from && animation.to) {
|
2914
|
+
update(animation.from.element);
|
2915
|
+
update(animation.to.element);
|
2916
|
+
} else {
|
2917
|
+
update(animation.element);
|
2918
|
+
}
|
2919
|
+
|
2920
|
+
function update(element) {
|
2921
|
+
getRunner(element).setHost(newRunner);
|
2922
|
+
}
|
2923
|
+
}
|
2924
|
+
|
2925
|
+
function handleDestroyedElement() {
|
2926
|
+
var runner = getRunner(element);
|
2927
|
+
if (runner && (event !== 'leave' || !options.$$domOperationFired)) {
|
2928
|
+
runner.end();
|
2929
|
+
}
|
2930
|
+
}
|
2931
|
+
|
2932
|
+
function close(rejected) { // jshint ignore:line
|
2933
|
+
element.off('$destroy', handleDestroyedElement);
|
2934
|
+
removeRunner(element);
|
2935
|
+
|
2936
|
+
applyAnimationClasses(element, options);
|
2937
|
+
applyAnimationStyles(element, options);
|
2938
|
+
options.domOperation();
|
2939
|
+
|
2940
|
+
if (tempClasses) {
|
2941
|
+
$$jqLite.removeClass(element, tempClasses);
|
2942
|
+
}
|
2943
|
+
|
2944
|
+
element.removeClass(NG_ANIMATE_CLASSNAME);
|
2945
|
+
runner.complete(!rejected);
|
2946
|
+
}
|
2947
|
+
};
|
2948
|
+
}];
|
2949
|
+
}];
|
2950
|
+
|
2951
|
+
/* global angularAnimateModule: true,
|
2952
|
+
|
2953
|
+
$$rAFMutexFactory,
|
2954
|
+
$$rAFSchedulerFactory,
|
2955
|
+
$$AnimateChildrenDirective,
|
2956
|
+
$$AnimateRunnerFactory,
|
2957
|
+
$$AnimateQueueProvider,
|
2958
|
+
$$AnimationProvider,
|
2959
|
+
$AnimateCssProvider,
|
2960
|
+
$$AnimateCssDriverProvider,
|
2961
|
+
$$AnimateJsProvider,
|
2962
|
+
$$AnimateJsDriverProvider,
|
2963
|
+
*/
|
2964
|
+
|
2965
|
+
/**
|
2966
|
+
* @ngdoc module
|
2967
|
+
* @name ngAnimate
|
2968
|
+
* @description
|
2969
|
+
*
|
2970
|
+
* The `ngAnimate` module provides support for CSS-based animations (keyframes and transitions) as well as JavaScript-based animations via
|
2971
|
+
* callback hooks. Animations are not enabled by default, however, by including `ngAnimate` then the animation hooks are enabled for an Angular app.
|
2972
|
+
*
|
2973
|
+
* <div doc-module-components="ngAnimate"></div>
|
2974
|
+
*
|
2975
|
+
* # Usage
|
2976
|
+
* Simply put, there are two ways to make use of animations when ngAnimate is used: by using **CSS** and **JavaScript**. The former works purely based
|
2977
|
+
* using CSS (by using matching CSS selectors/styles) and the latter triggers animations that are registered via `module.animation()`. For
|
2978
|
+
* both CSS and JS animations the sole requirement is to have a matching `CSS class` that exists both in the registered animation and within
|
2979
|
+
* the HTML element that the animation will be triggered on.
|
2980
|
+
*
|
2981
|
+
* ## Directive Support
|
2982
|
+
* The following directives are "animation aware":
|
2983
|
+
*
|
2984
|
+
* | Directive | Supported Animations |
|
2985
|
+
* |----------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------|
|
2986
|
+
* | {@link ng.directive:ngRepeat#animations ngRepeat} | enter, leave and move |
|
2987
|
+
* | {@link ngRoute.directive:ngView#animations ngView} | enter and leave |
|
2988
|
+
* | {@link ng.directive:ngInclude#animations ngInclude} | enter and leave |
|
2989
|
+
* | {@link ng.directive:ngSwitch#animations ngSwitch} | enter and leave |
|
2990
|
+
* | {@link ng.directive:ngIf#animations ngIf} | enter and leave |
|
2991
|
+
* | {@link ng.directive:ngClass#animations ngClass} | add and remove (the CSS class(es) present) |
|
2992
|
+
* | {@link ng.directive:ngShow#animations ngShow} & {@link ng.directive:ngHide#animations ngHide} | add and remove (the ng-hide class value) |
|
2993
|
+
* | {@link ng.directive:form#animation-hooks form} & {@link ng.directive:ngModel#animation-hooks ngModel} | add and remove (dirty, pristine, valid, invalid & all other validations) |
|
2994
|
+
* | {@link module:ngMessages#animations ngMessages} | add and remove (ng-active & ng-inactive) |
|
2995
|
+
* | {@link module:ngMessages#animations ngMessage} | enter and leave |
|
2996
|
+
*
|
2997
|
+
* (More information can be found by visiting each the documentation associated with each directive.)
|
2998
|
+
*
|
2999
|
+
* ## CSS-based Animations
|
3000
|
+
*
|
3001
|
+
* CSS-based animations with ngAnimate are unique since they require no JavaScript code at all. By using a CSS class that we reference between our HTML
|
3002
|
+
* and CSS code we can create an animation that will be picked up by Angular when an the underlying directive performs an operation.
|
3003
|
+
*
|
3004
|
+
* The example below shows how an `enter` animation can be made possible on a element using `ng-if`:
|
3005
|
+
*
|
3006
|
+
* ```html
|
3007
|
+
* <div ng-if="bool" class="fade">
|
3008
|
+
* Fade me in out
|
3009
|
+
* </div>
|
3010
|
+
* <button ng-click="bool=true">Fade In!</button>
|
3011
|
+
* <button ng-click="bool=false">Fade Out!</button>
|
3012
|
+
* ```
|
3013
|
+
*
|
3014
|
+
* Notice the CSS class **fade**? We can now create the CSS transition code that references this class:
|
3015
|
+
*
|
3016
|
+
* ```css
|
3017
|
+
* /* The starting CSS styles for the enter animation */
|
3018
|
+
* .fade.ng-enter {
|
3019
|
+
* transition:0.5s linear all;
|
3020
|
+
* opacity:0;
|
3021
|
+
* }
|
3022
|
+
*
|
3023
|
+
* /* The starting CSS styles for the enter animation */
|
3024
|
+
* .fade.ng-enter.ng-enter-active {
|
3025
|
+
* opacity:1;
|
3026
|
+
* }
|
3027
|
+
* ```
|
3028
|
+
*
|
3029
|
+
* The key thing to remember here is that, depending on the animation event (which each of the directives above trigger depending on what's going on) two
|
3030
|
+
* generated CSS classes will be applied to the element; in the example above we have `.ng-enter` and `.ng-enter-active`. For CSS transitions, the transition
|
3031
|
+
* code **must** be defined within the starting CSS class (in this case `.ng-enter`). The destination class is what the transition will animate towards.
|
3032
|
+
*
|
3033
|
+
* If for example we wanted to create animations for `leave` and `move` (ngRepeat triggers move) then we can do so using the same CSS naming conventions:
|
3034
|
+
*
|
3035
|
+
* ```css
|
3036
|
+
* /* now the element will fade out before it is removed from the DOM */
|
3037
|
+
* .fade.ng-leave {
|
3038
|
+
* transition:0.5s linear all;
|
3039
|
+
* opacity:1;
|
3040
|
+
* }
|
3041
|
+
* .fade.ng-leave.ng-leave-active {
|
3042
|
+
* opacity:0;
|
3043
|
+
* }
|
3044
|
+
* ```
|
3045
|
+
*
|
3046
|
+
* We can also make use of **CSS Keyframes** by referencing the keyframe animation within the starting CSS class:
|
3047
|
+
*
|
3048
|
+
* ```css
|
3049
|
+
* /* there is no need to define anything inside of the destination
|
3050
|
+
* CSS class since the keyframe will take charge of the animation */
|
3051
|
+
* .fade.ng-leave {
|
3052
|
+
* animation: my_fade_animation 0.5s linear;
|
3053
|
+
* -webkit-animation: my_fade_animation 0.5s linear;
|
3054
|
+
* }
|
3055
|
+
*
|
3056
|
+
* @keyframes my_fade_animation {
|
3057
|
+
* from { opacity:1; }
|
3058
|
+
* to { opacity:0; }
|
3059
|
+
* }
|
3060
|
+
*
|
3061
|
+
* @-webkit-keyframes my_fade_animation {
|
3062
|
+
* from { opacity:1; }
|
3063
|
+
* to { opacity:0; }
|
3064
|
+
* }
|
3065
|
+
* ```
|
3066
|
+
*
|
3067
|
+
* Feel free also mix transitions and keyframes together as well as any other CSS classes on the same element.
|
3068
|
+
*
|
3069
|
+
* ### CSS Class-based Animations
|
3070
|
+
*
|
3071
|
+
* Class-based animations (animations that are triggered via `ngClass`, `ngShow`, `ngHide` and some other directives) have a slightly different
|
3072
|
+
* naming convention. Class-based animations are basic enough that a standard transition or keyframe can be referenced on the class being added
|
3073
|
+
* and removed.
|
3074
|
+
*
|
3075
|
+
* For example if we wanted to do a CSS animation for `ngHide` then we place an animation on the `.ng-hide` CSS class:
|
3076
|
+
*
|
3077
|
+
* ```html
|
3078
|
+
* <div ng-show="bool" class="fade">
|
3079
|
+
* Show and hide me
|
3080
|
+
* </div>
|
3081
|
+
* <button ng-click="bool=true">Toggle</button>
|
3082
|
+
*
|
3083
|
+
* <style>
|
3084
|
+
* .fade.ng-hide {
|
3085
|
+
* transition:0.5s linear all;
|
3086
|
+
* opacity:0;
|
3087
|
+
* }
|
3088
|
+
* </style>
|
3089
|
+
* ```
|
3090
|
+
*
|
3091
|
+
* All that is going on here with ngShow/ngHide behind the scenes is the `.ng-hide` class is added/removed (when the hidden state is valid). Since
|
3092
|
+
* ngShow and ngHide are animation aware then we can match up a transition and ngAnimate handles the rest.
|
3093
|
+
*
|
3094
|
+
* In addition the addition and removal of the CSS class, ngAnimate also provides two helper methods that we can use to further decorate the animation
|
3095
|
+
* with CSS styles.
|
3096
|
+
*
|
3097
|
+
* ```html
|
3098
|
+
* <div ng-class="{on:onOff}" class="highlight">
|
3099
|
+
* Highlight this box
|
3100
|
+
* </div>
|
3101
|
+
* <button ng-click="onOff=!onOff">Toggle</button>
|
3102
|
+
*
|
3103
|
+
* <style>
|
3104
|
+
* .highlight {
|
3105
|
+
* transition:0.5s linear all;
|
3106
|
+
* }
|
3107
|
+
* .highlight.on-add {
|
3108
|
+
* background:white;
|
3109
|
+
* }
|
3110
|
+
* .highlight.on {
|
3111
|
+
* background:yellow;
|
3112
|
+
* }
|
3113
|
+
* .highlight.on-remove {
|
3114
|
+
* background:black;
|
3115
|
+
* }
|
3116
|
+
* </style>
|
3117
|
+
* ```
|
3118
|
+
*
|
3119
|
+
* We can also make use of CSS keyframes by placing them within the CSS classes.
|
3120
|
+
*
|
3121
|
+
*
|
3122
|
+
* ### CSS Staggering Animations
|
3123
|
+
* A Staggering animation is a collection of animations that are issued with a slight delay in between each successive operation resulting in a
|
3124
|
+
* curtain-like effect. The ngAnimate module (versions >=1.2) supports staggering animations and the stagger effect can be
|
3125
|
+
* performed by creating a **ng-EVENT-stagger** CSS class and attaching that class to the base CSS class used for
|
3126
|
+
* the animation. The style property expected within the stagger class can either be a **transition-delay** or an
|
3127
|
+
* **animation-delay** property (or both if your animation contains both transitions and keyframe animations).
|
3128
|
+
*
|
3129
|
+
* ```css
|
3130
|
+
* .my-animation.ng-enter {
|
3131
|
+
* /* standard transition code */
|
3132
|
+
* transition: 1s linear all;
|
3133
|
+
* opacity:0;
|
3134
|
+
* }
|
3135
|
+
* .my-animation.ng-enter-stagger {
|
3136
|
+
* /* this will have a 100ms delay between each successive leave animation */
|
3137
|
+
* transition-delay: 0.1s;
|
3138
|
+
*
|
3139
|
+
* /* in case the stagger doesn't work then the duration value
|
3140
|
+
* must be set to 0 to avoid an accidental CSS inheritance */
|
3141
|
+
* transition-duration: 0s;
|
3142
|
+
* }
|
3143
|
+
* .my-animation.ng-enter.ng-enter-active {
|
3144
|
+
* /* standard transition styles */
|
3145
|
+
* opacity:1;
|
3146
|
+
* }
|
3147
|
+
* ```
|
3148
|
+
*
|
3149
|
+
* Staggering animations work by default in ngRepeat (so long as the CSS class is defined). Outside of ngRepeat, to use staggering animations
|
3150
|
+
* on your own, they can be triggered by firing multiple calls to the same event on $animate. However, the restrictions surrounding this
|
3151
|
+
* are that each of the elements must have the same CSS className value as well as the same parent element. A stagger operation
|
3152
|
+
* will also be reset if one or more animation frames have passed since the multiple calls to `$animate` were fired.
|
3153
|
+
*
|
3154
|
+
* The following code will issue the **ng-leave-stagger** event on the element provided:
|
3155
|
+
*
|
3156
|
+
* ```js
|
3157
|
+
* var kids = parent.children();
|
3158
|
+
*
|
3159
|
+
* $animate.leave(kids[0]); //stagger index=0
|
3160
|
+
* $animate.leave(kids[1]); //stagger index=1
|
3161
|
+
* $animate.leave(kids[2]); //stagger index=2
|
3162
|
+
* $animate.leave(kids[3]); //stagger index=3
|
3163
|
+
* $animate.leave(kids[4]); //stagger index=4
|
3164
|
+
*
|
3165
|
+
* window.requestAnimationFrame(function() {
|
3166
|
+
* //stagger has reset itself
|
3167
|
+
* $animate.leave(kids[5]); //stagger index=0
|
3168
|
+
* $animate.leave(kids[6]); //stagger index=1
|
3169
|
+
*
|
3170
|
+
* $scope.$digest();
|
3171
|
+
* });
|
3172
|
+
* ```
|
3173
|
+
*
|
3174
|
+
* Stagger animations are currently only supported within CSS-defined animations.
|
3175
|
+
*
|
3176
|
+
* ### The `ng-animate` CSS class
|
3177
|
+
*
|
3178
|
+
* When ngAnimate is animating an element it will apply the `ng-animate` CSS class to the element for the duration of the animation.
|
3179
|
+
* This is a temporary CSS class and it will be removed once the animation is over (for both JavaScript and CSS-based animations).
|
3180
|
+
*
|
3181
|
+
* Therefore, animations can be applied to an element using this temporary class directly via CSS.
|
3182
|
+
*
|
3183
|
+
* ```css
|
3184
|
+
* .zipper.ng-animate {
|
3185
|
+
* transition:0.5s linear all;
|
3186
|
+
* }
|
3187
|
+
* .zipper.ng-enter {
|
3188
|
+
* opacity:0;
|
3189
|
+
* }
|
3190
|
+
* .zipper.ng-enter.ng-enter-active {
|
3191
|
+
* opacity:1;
|
3192
|
+
* }
|
3193
|
+
* .zipper.ng-leave {
|
3194
|
+
* opacity:1;
|
3195
|
+
* }
|
3196
|
+
* .zipper.ng-leave.ng-leave-active {
|
3197
|
+
* opacity:0;
|
3198
|
+
* }
|
3199
|
+
* ```
|
3200
|
+
*
|
3201
|
+
* (Note that the `ng-animate` CSS class is reserved and it cannot be applied on an element directly since ngAnimate will always remove
|
3202
|
+
* the CSS class once an animation has completed.)
|
3203
|
+
*
|
3204
|
+
*
|
3205
|
+
* ## JavaScript-based Animations
|
3206
|
+
*
|
3207
|
+
* ngAnimate also allows for animations to be consumed by JavaScript code. The approach is similar to CSS-based animations (where there is a shared
|
3208
|
+
* CSS class that is referenced in our HTML code) but in addition we need to register the JavaScript animation on the module. By making use of the
|
3209
|
+
* `module.animation()` module function we can register the ainmation.
|
3210
|
+
*
|
3211
|
+
* Let's see an example of a enter/leave animation using `ngRepeat`:
|
3212
|
+
*
|
3213
|
+
* ```html
|
3214
|
+
* <div ng-repeat="item in items" class="slide">
|
3215
|
+
* {{ item }}
|
3216
|
+
* </div>
|
3217
|
+
* ```
|
3218
|
+
*
|
3219
|
+
* See the **slide** CSS class? Let's use that class to define an animation that we'll structure in our module code by using `module.animation`:
|
3220
|
+
*
|
3221
|
+
* ```js
|
3222
|
+
* myModule.animation('.slide', [function() {
|
3223
|
+
* return {
|
3224
|
+
* // make note that other events (like addClass/removeClass)
|
3225
|
+
* // have different function input parameters
|
3226
|
+
* enter: function(element, doneFn) {
|
3227
|
+
* jQuery(element).fadeIn(1000, doneFn);
|
3228
|
+
*
|
3229
|
+
* // remember to call doneFn so that angular
|
3230
|
+
* // knows that the animation has concluded
|
3231
|
+
* },
|
3232
|
+
*
|
3233
|
+
* move: function(element, doneFn) {
|
3234
|
+
* jQuery(element).fadeIn(1000, doneFn);
|
3235
|
+
* },
|
3236
|
+
*
|
3237
|
+
* leave: function(element, doneFn) {
|
3238
|
+
* jQuery(element).fadeOut(1000, doneFn);
|
3239
|
+
* }
|
3240
|
+
* }
|
3241
|
+
* }]
|
3242
|
+
* ```
|
3243
|
+
*
|
3244
|
+
* The nice thing about JS-based animations is that we can inject other services and make use of advanced animation libraries such as
|
3245
|
+
* greensock.js and velocity.js.
|
3246
|
+
*
|
3247
|
+
* If our animation code class-based (meaning that something like `ngClass`, `ngHide` and `ngShow` triggers it) then we can still define
|
3248
|
+
* our animations inside of the same registered animation, however, the function input arguments are a bit different:
|
3249
|
+
*
|
3250
|
+
* ```html
|
3251
|
+
* <div ng-class="color" class="colorful">
|
3252
|
+
* this box is moody
|
3253
|
+
* </div>
|
3254
|
+
* <button ng-click="color='red'">Change to red</button>
|
3255
|
+
* <button ng-click="color='blue'">Change to blue</button>
|
3256
|
+
* <button ng-click="color='green'">Change to green</button>
|
3257
|
+
* ```
|
3258
|
+
*
|
3259
|
+
* ```js
|
3260
|
+
* myModule.animation('.colorful', [function() {
|
3261
|
+
* return {
|
3262
|
+
* addClass: function(element, className, doneFn) {
|
3263
|
+
* // do some cool animation and call the doneFn
|
3264
|
+
* },
|
3265
|
+
* removeClass: function(element, className, doneFn) {
|
3266
|
+
* // do some cool animation and call the doneFn
|
3267
|
+
* },
|
3268
|
+
* setClass: function(element, addedClass, removedClass, doneFn) {
|
3269
|
+
* // do some cool animation and call the doneFn
|
3270
|
+
* }
|
3271
|
+
* }
|
3272
|
+
* }]
|
3273
|
+
* ```
|
3274
|
+
*
|
3275
|
+
* ## CSS + JS Animations Together
|
3276
|
+
*
|
3277
|
+
* AngularJS 1.4 and higher has taken steps to make the amalgamation of CSS and JS animations more flexible. However, unlike earlier versions of Angular,
|
3278
|
+
* defining CSS and JS animations to work off of the same CSS class will not work anymore. Therefore example below will only result in **JS animations taking
|
3279
|
+
* charge of the animation**:
|
3280
|
+
*
|
3281
|
+
* ```html
|
3282
|
+
* <div ng-if="bool" class="slide">
|
3283
|
+
* Slide in and out
|
3284
|
+
* </div>
|
3285
|
+
* ```
|
3286
|
+
*
|
3287
|
+
* ```js
|
3288
|
+
* myModule.animation('.slide', [function() {
|
3289
|
+
* return {
|
3290
|
+
* enter: function(element, doneFn) {
|
3291
|
+
* jQuery(element).slideIn(1000, doneFn);
|
3292
|
+
* }
|
3293
|
+
* }
|
3294
|
+
* }]
|
3295
|
+
* ```
|
3296
|
+
*
|
3297
|
+
* ```css
|
3298
|
+
* .slide.ng-enter {
|
3299
|
+
* transition:0.5s linear all;
|
3300
|
+
* transform:translateY(-100px);
|
3301
|
+
* }
|
3302
|
+
* .slide.ng-enter.ng-enter-active {
|
3303
|
+
* transform:translateY(0);
|
3304
|
+
* }
|
3305
|
+
* ```
|
3306
|
+
*
|
3307
|
+
* Does this mean that CSS and JS animations cannot be used together? Do JS-based animations always have higher priority? We can suppliment for the
|
3308
|
+
* lack of CSS animations by making use of the `$animateCss` service to trigger our own tweaked-out, CSS-based animations directly from
|
3309
|
+
* our own JS-based animation code:
|
3310
|
+
*
|
3311
|
+
* ```js
|
3312
|
+
* myModule.animation('.slide', ['$animateCss', function($animateCss) {
|
3313
|
+
* return {
|
3314
|
+
* enter: function(element, doneFn) {
|
3315
|
+
* // this will trigger `.slide.ng-enter` and `.slide.ng-enter-active`.
|
3316
|
+
* var runner = $animateCss(element, {
|
3317
|
+
* event: 'enter',
|
3318
|
+
* structural: true
|
3319
|
+
* }).start();
|
3320
|
+
* runner.done(doneFn);
|
3321
|
+
* }
|
3322
|
+
* }
|
3323
|
+
* }]
|
3324
|
+
* ```
|
3325
|
+
*
|
3326
|
+
* The nice thing here is that we can save bandwidth by sticking to our CSS-based animation code and we don't need to rely on a 3rd-party animation framework.
|
3327
|
+
*
|
3328
|
+
* The `$animateCss` service is very powerful since we can feed in all kinds of extra properties that will be evaluated and fed into a CSS transition or
|
3329
|
+
* keyframe animation. For example if we wanted to animate the height of an element while adding and removing classes then we can do so by providing that
|
3330
|
+
* data into `$animateCss` directly:
|
3331
|
+
*
|
3332
|
+
* ```js
|
3333
|
+
* myModule.animation('.slide', ['$animateCss', function($animateCss) {
|
3334
|
+
* return {
|
3335
|
+
* enter: function(element, doneFn) {
|
3336
|
+
* var runner = $animateCss(element, {
|
3337
|
+
* event: 'enter',
|
3338
|
+
* addClass: 'maroon-setting',
|
3339
|
+
* from: { height:0 },
|
3340
|
+
* to: { height: 200 }
|
3341
|
+
* }).start();
|
3342
|
+
*
|
3343
|
+
* runner.done(doneFn);
|
3344
|
+
* }
|
3345
|
+
* }
|
3346
|
+
* }]
|
3347
|
+
* ```
|
3348
|
+
*
|
3349
|
+
* Now we can fill in the rest via our transition CSS code:
|
3350
|
+
*
|
3351
|
+
* ```css
|
3352
|
+
* /* the transition tells ngAnimate to make the animation happen */
|
3353
|
+
* .slide.ng-enter { transition:0.5s linear all; }
|
3354
|
+
*
|
3355
|
+
* /* this extra CSS class will be absorbed into the transition
|
3356
|
+
* since the $animateCss code is adding the class */
|
3357
|
+
* .maroon-setting { background:red; }
|
3358
|
+
* ```
|
3359
|
+
*
|
3360
|
+
* And `$animateCss` will figure out the rest. Just make sure to have the `done()` callback fire the `doneFn` function to signal when the animation is over.
|
3361
|
+
*
|
3362
|
+
* To learn more about what's possible be sure to visit the {@link ngAnimate.$animateCss $animateCss service}.
|
3363
|
+
*
|
3364
|
+
* ## Animation Anchoring (via `ng-animate-ref`)
|
3365
|
+
*
|
3366
|
+
* ngAnimate in AngularJS 1.4 comes packed with the ability to cross-animate elements between
|
3367
|
+
* structural areas of an application (like views) by pairing up elements using an attribute
|
3368
|
+
* called `ng-animate-ref`.
|
3369
|
+
*
|
3370
|
+
* Let's say for example we have two views that are managed by `ng-view` and we want to show
|
3371
|
+
* that there is a relationship between two components situated in within these views. By using the
|
3372
|
+
* `ng-animate-ref` attribute we can identify that the two components are paired together and we
|
3373
|
+
* can then attach an animation, which is triggered when the view changes.
|
3374
|
+
*
|
3375
|
+
* Say for example we have the following template code:
|
3376
|
+
*
|
3377
|
+
* ```html
|
3378
|
+
* <!-- index.html -->
|
3379
|
+
* <div ng-view class="view-animation">
|
3380
|
+
* </div>
|
3381
|
+
*
|
3382
|
+
* <!-- home.html -->
|
3383
|
+
* <a href="#/banner-page">
|
3384
|
+
* <img src="./banner.jpg" class="banner" ng-animate-ref="banner">
|
3385
|
+
* </a>
|
3386
|
+
*
|
3387
|
+
* <!-- banner-page.html -->
|
3388
|
+
* <img src="./banner.jpg" class="banner" ng-animate-ref="banner">
|
3389
|
+
* ```
|
3390
|
+
*
|
3391
|
+
* Now, when the view changes (once the link is clicked), ngAnimate will examine the
|
3392
|
+
* HTML contents to see if there is a match reference between any components in the view
|
3393
|
+
* that is leaving and the view that is entering. It will scan both the view which is being
|
3394
|
+
* removed (leave) and inserted (enter) to see if there are any paired DOM elements that
|
3395
|
+
* contain a matching ref value.
|
3396
|
+
*
|
3397
|
+
* The two images match since they share the same ref value. ngAnimate will now create a
|
3398
|
+
* transport element (which is a clone of the first image element) and it will then attempt
|
3399
|
+
* to animate to the position of the second image element in the next view. For the animation to
|
3400
|
+
* work a special CSS class called `ng-anchor` will be added to the transported element.
|
3401
|
+
*
|
3402
|
+
* We can now attach a transition onto the `.banner.ng-anchor` CSS class and then
|
3403
|
+
* ngAnimate will handle the entire transition for us as well as the addition and removal of
|
3404
|
+
* any changes of CSS classes between the elements:
|
3405
|
+
*
|
3406
|
+
* ```css
|
3407
|
+
* .banner.ng-anchor {
|
3408
|
+
* /* this animation will last for 1 second since there are
|
3409
|
+
* two phases to the animation (an `in` and an `out` phase) */
|
3410
|
+
* transition:0.5s linear all;
|
3411
|
+
* }
|
3412
|
+
* ```
|
3413
|
+
*
|
3414
|
+
* We also **must** include animations for the views that are being entered and removed
|
3415
|
+
* (otherwise anchoring wouldn't be possible since the new view would be inserted right away).
|
3416
|
+
*
|
3417
|
+
* ```css
|
3418
|
+
* .view-animation.ng-enter, .view-animation.ng-leave {
|
3419
|
+
* transition:0.5s linear all;
|
3420
|
+
* position:fixed;
|
3421
|
+
* left:0;
|
3422
|
+
* top:0;
|
3423
|
+
* width:100%;
|
3424
|
+
* }
|
3425
|
+
* .view-animation.ng-enter {
|
3426
|
+
* transform:translateX(100%);
|
3427
|
+
* }
|
3428
|
+
* .view-animation.ng-leave,
|
3429
|
+
* .view-animation.ng-enter.ng-enter-active {
|
3430
|
+
* transform:translateX(0%);
|
3431
|
+
* }
|
3432
|
+
* .view-animation.ng-leave.ng-leave-active {
|
3433
|
+
* transform:translateX(-100%);
|
3434
|
+
* }
|
3435
|
+
* ```
|
3436
|
+
*
|
3437
|
+
* Now we can jump back to the anchor animation. When the animation happens, there are two stages that occur:
|
3438
|
+
* an `out` and an `in` stage. The `out` stage happens first and that is when the element is animated away
|
3439
|
+
* from its origin. Once that animation is over then the `in` stage occurs which animates the
|
3440
|
+
* element to its destination. The reason why there are two animations is to give enough time
|
3441
|
+
* for the enter animation on the new element to be ready.
|
3442
|
+
*
|
3443
|
+
* The example above sets up a transition for both the in and out phases, but we can also target the out or
|
3444
|
+
* in phases directly via `ng-anchor-out` and `ng-anchor-in`.
|
3445
|
+
*
|
3446
|
+
* ```css
|
3447
|
+
* .banner.ng-anchor-out {
|
3448
|
+
* transition: 0.5s linear all;
|
3449
|
+
*
|
3450
|
+
* /* the scale will be applied during the out animation,
|
3451
|
+
* but will be animated away when the in animation runs */
|
3452
|
+
* transform: scale(1.2);
|
3453
|
+
* }
|
3454
|
+
*
|
3455
|
+
* .banner.ng-anchor-in {
|
3456
|
+
* transition: 1s linear all;
|
3457
|
+
* }
|
3458
|
+
* ```
|
3459
|
+
*
|
3460
|
+
*
|
3461
|
+
*
|
3462
|
+
*
|
3463
|
+
* ### Anchoring Demo
|
3464
|
+
*
|
3465
|
+
<example module="anchoringExample"
|
3466
|
+
name="anchoringExample"
|
3467
|
+
id="anchoringExample"
|
3468
|
+
deps="angular-animate.js;angular-route.js"
|
3469
|
+
animations="true">
|
3470
|
+
<file name="index.html">
|
3471
|
+
<a href="#/">Home</a>
|
3472
|
+
<hr />
|
3473
|
+
<div class="view-container">
|
3474
|
+
<div ng-view class="view"></div>
|
3475
|
+
</div>
|
3476
|
+
</file>
|
3477
|
+
<file name="script.js">
|
3478
|
+
angular.module('anchoringExample', ['ngAnimate', 'ngRoute'])
|
3479
|
+
.config(['$routeProvider', function($routeProvider) {
|
3480
|
+
$routeProvider.when('/', {
|
3481
|
+
templateUrl: 'home.html',
|
3482
|
+
controller: 'HomeController as home'
|
3483
|
+
});
|
3484
|
+
$routeProvider.when('/profile/:id', {
|
3485
|
+
templateUrl: 'profile.html',
|
3486
|
+
controller: 'ProfileController as profile'
|
3487
|
+
});
|
3488
|
+
}])
|
3489
|
+
.run(['$rootScope', function($rootScope) {
|
3490
|
+
$rootScope.records = [
|
3491
|
+
{ id:1, title: "Miss Beulah Roob" },
|
3492
|
+
{ id:2, title: "Trent Morissette" },
|
3493
|
+
{ id:3, title: "Miss Ava Pouros" },
|
3494
|
+
{ id:4, title: "Rod Pouros" },
|
3495
|
+
{ id:5, title: "Abdul Rice" },
|
3496
|
+
{ id:6, title: "Laurie Rutherford Sr." },
|
3497
|
+
{ id:7, title: "Nakia McLaughlin" },
|
3498
|
+
{ id:8, title: "Jordon Blanda DVM" },
|
3499
|
+
{ id:9, title: "Rhoda Hand" },
|
3500
|
+
{ id:10, title: "Alexandrea Sauer" }
|
3501
|
+
];
|
3502
|
+
}])
|
3503
|
+
.controller('HomeController', [function() {
|
3504
|
+
//empty
|
3505
|
+
}])
|
3506
|
+
.controller('ProfileController', ['$rootScope', '$routeParams', function($rootScope, $routeParams) {
|
3507
|
+
var index = parseInt($routeParams.id, 10);
|
3508
|
+
var record = $rootScope.records[index - 1];
|
3509
|
+
|
3510
|
+
this.title = record.title;
|
3511
|
+
this.id = record.id;
|
3512
|
+
}]);
|
3513
|
+
</file>
|
3514
|
+
<file name="home.html">
|
3515
|
+
<h2>Welcome to the home page</h1>
|
3516
|
+
<p>Please click on an element</p>
|
3517
|
+
<a class="record"
|
3518
|
+
ng-href="#/profile/{{ record.id }}"
|
3519
|
+
ng-animate-ref="{{ record.id }}"
|
3520
|
+
ng-repeat="record in records">
|
3521
|
+
{{ record.title }}
|
3522
|
+
</a>
|
3523
|
+
</file>
|
3524
|
+
<file name="profile.html">
|
3525
|
+
<div class="profile record" ng-animate-ref="{{ profile.id }}">
|
3526
|
+
{{ profile.title }}
|
3527
|
+
</div>
|
3528
|
+
</file>
|
3529
|
+
<file name="animations.css">
|
3530
|
+
.record {
|
3531
|
+
display:block;
|
3532
|
+
font-size:20px;
|
3533
|
+
}
|
3534
|
+
.profile {
|
3535
|
+
background:black;
|
3536
|
+
color:white;
|
3537
|
+
font-size:100px;
|
3538
|
+
}
|
3539
|
+
.view-container {
|
3540
|
+
position:relative;
|
3541
|
+
}
|
3542
|
+
.view-container > .view.ng-animate {
|
3543
|
+
position:absolute;
|
3544
|
+
top:0;
|
3545
|
+
left:0;
|
3546
|
+
width:100%;
|
3547
|
+
min-height:500px;
|
3548
|
+
}
|
3549
|
+
.view.ng-enter, .view.ng-leave,
|
3550
|
+
.record.ng-anchor {
|
3551
|
+
transition:0.5s linear all;
|
3552
|
+
}
|
3553
|
+
.view.ng-enter {
|
3554
|
+
transform:translateX(100%);
|
3555
|
+
}
|
3556
|
+
.view.ng-enter.ng-enter-active, .view.ng-leave {
|
3557
|
+
transform:translateX(0%);
|
3558
|
+
}
|
3559
|
+
.view.ng-leave.ng-leave-active {
|
3560
|
+
transform:translateX(-100%);
|
3561
|
+
}
|
3562
|
+
.record.ng-anchor-out {
|
3563
|
+
background:red;
|
3564
|
+
}
|
3565
|
+
</file>
|
3566
|
+
</example>
|
3567
|
+
*
|
3568
|
+
* ### How is the element transported?
|
3569
|
+
*
|
3570
|
+
* When an anchor animation occurs, ngAnimate will clone the starting element and position it exactly where the starting
|
3571
|
+
* element is located on screen via absolute positioning. The cloned element will be placed inside of the root element
|
3572
|
+
* of the application (where ng-app was defined) and all of the CSS classes of the starting element will be applied. The
|
3573
|
+
* element will then animate into the `out` and `in` animations and will eventually reach the coordinates and match
|
3574
|
+
* the dimensions of the destination element. During the entire animation a CSS class of `.ng-animate-shim` will be applied
|
3575
|
+
* to both the starting and destination elements in order to hide them from being visible (the CSS styling for the class
|
3576
|
+
* is: `visibility:hidden`). Once the anchor reaches its destination then it will be removed and the destination element
|
3577
|
+
* will become visible since the shim class will be removed.
|
3578
|
+
*
|
3579
|
+
* ### How is the morphing handled?
|
3580
|
+
*
|
3581
|
+
* CSS Anchoring relies on transitions and keyframes and the internal code is intelligent enough to figure out
|
3582
|
+
* what CSS classes differ between the starting element and the destination element. These different CSS classes
|
3583
|
+
* will be added/removed on the anchor element and a transition will be applied (the transition that is provided
|
3584
|
+
* in the anchor class). Long story short, ngAnimate will figure out what classes to add and remove which will
|
3585
|
+
* make the transition of the element as smooth and automatic as possible. Be sure to use simple CSS classes that
|
3586
|
+
* do not rely on DOM nesting structure so that the anchor element appears the same as the starting element (since
|
3587
|
+
* the cloned element is placed inside of root element which is likely close to the body element).
|
3588
|
+
*
|
3589
|
+
* Note that if the root element is on the `<html>` element then the cloned node will be placed inside of body.
|
3590
|
+
*
|
3591
|
+
*
|
3592
|
+
* ## Using $animate in your directive code
|
3593
|
+
*
|
3594
|
+
* So far we've explored how to feed in animations into an Angular application, but how do we trigger animations within our own directives in our application?
|
3595
|
+
* By injecting the `$animate` service into our directive code, we can trigger structural and class-based hooks which can then be consumed by animations. Let's
|
3596
|
+
* imagine we have a greeting box that shows and hides itself when the data changes
|
3597
|
+
*
|
3598
|
+
* ```html
|
3599
|
+
* <greeting-box active="onOrOff">Hi there</greeting-box>
|
3600
|
+
* ```
|
3601
|
+
*
|
3602
|
+
* ```js
|
3603
|
+
* ngModule.directive('greetingBox', ['$animate', function($animate) {
|
3604
|
+
* return function(scope, element, attrs) {
|
3605
|
+
* attrs.$observe('active', function(value) {
|
3606
|
+
* value ? $animate.addClass(element, 'on') ? $animate.removeClass(element, 'on');
|
3607
|
+
* });
|
3608
|
+
* });
|
3609
|
+
* }]);
|
3610
|
+
* ```
|
3611
|
+
*
|
3612
|
+
* Now the `on` CSS class is added and removed on the greeting box component. Now if we add a CSS class on top of the greeting box element
|
3613
|
+
* in our HTML code then we can trigger a CSS or JS animation to happen.
|
3614
|
+
*
|
3615
|
+
* ```css
|
3616
|
+
* /* normally we would create a CSS class to reference on the element */
|
3617
|
+
* [greeting-box].on { transition:0.5s linear all; background:green; color:white; }
|
3618
|
+
* ```
|
3619
|
+
*
|
3620
|
+
* The `$animate` service contains a variety of other methods like `enter`, `leave`, `animate` and `setClass`. To learn more about what's
|
3621
|
+
* possible be sure to visit the {@link ng.$animate $animate service API page}.
|
3622
|
+
*
|
3623
|
+
*
|
3624
|
+
* ### Preventing Collisions With Third Party Libraries
|
3625
|
+
*
|
3626
|
+
* Some third-party frameworks place animation duration defaults across many element or className
|
3627
|
+
* selectors in order to make their code small and reuseable. This can lead to issues with ngAnimate, which
|
3628
|
+
* is expecting actual animations on these elements and has to wait for their completion.
|
3629
|
+
*
|
3630
|
+
* You can prevent this unwanted behavior by using a prefix on all your animation classes:
|
3631
|
+
*
|
3632
|
+
* ```css
|
3633
|
+
* /* prefixed with animate- */
|
3634
|
+
* .animate-fade-add.animate-fade-add-active {
|
3635
|
+
* transition:1s linear all;
|
3636
|
+
* opacity:0;
|
3637
|
+
* }
|
3638
|
+
* ```
|
3639
|
+
*
|
3640
|
+
* You then configure `$animate` to enforce this prefix:
|
3641
|
+
*
|
3642
|
+
* ```js
|
3643
|
+
* $animateProvider.classNameFilter(/animate-/);
|
3644
|
+
* ```
|
3645
|
+
*
|
3646
|
+
* This also may provide your application with a speed boost since only specific elements containing CSS class prefix
|
3647
|
+
* will be evaluated for animation when any DOM changes occur in the application.
|
3648
|
+
*
|
3649
|
+
* ## Callbacks and Promises
|
3650
|
+
*
|
3651
|
+
* When `$animate` is called it returns a promise that can be used to capture when the animation has ended. Therefore if we were to trigger
|
3652
|
+
* an animation (within our directive code) then we can continue performing directive and scope related activities after the animation has
|
3653
|
+
* ended by chaining onto the returned promise that animation method returns.
|
3654
|
+
*
|
3655
|
+
* ```js
|
3656
|
+
* // somewhere within the depths of the directive
|
3657
|
+
* $animate.enter(element, parent).then(function() {
|
3658
|
+
* //the animation has completed
|
3659
|
+
* });
|
3660
|
+
* ```
|
3661
|
+
*
|
3662
|
+
* (Note that earlier versions of Angular prior to v1.4 required the promise code to be wrapped using `$scope.$apply(...)`. This is not the case
|
3663
|
+
* anymore.)
|
3664
|
+
*
|
3665
|
+
* In addition to the animation promise, we can also make use of animation-related callbacks within our directives and controller code by registering
|
3666
|
+
* an event listener using the `$animate` service. Let's say for example that an animation was triggered on our view
|
3667
|
+
* routing controller to hook into that:
|
3668
|
+
*
|
3669
|
+
* ```js
|
3670
|
+
* ngModule.controller('HomePageController', ['$animate', function($animate) {
|
3671
|
+
* $animate.on('enter', ngViewElement, function(element) {
|
3672
|
+
* // the animation for this route has completed
|
3673
|
+
* }]);
|
3674
|
+
* }])
|
3675
|
+
* ```
|
3676
|
+
*
|
3677
|
+
* (Note that you will need to trigger a digest within the callback to get angular to notice any scope-related changes.)
|
3678
|
+
*/
|
3679
|
+
|
3680
|
+
/**
|
3681
|
+
* @ngdoc service
|
3682
|
+
* @name $animate
|
3683
|
+
* @kind object
|
3684
|
+
*
|
3685
|
+
* @description
|
3686
|
+
* The ngAnimate `$animate` service documentation is the same for the core `$animate` service.
|
3687
|
+
*
|
3688
|
+
* Click here {@link ng.$animate $animate to learn more about animations with `$animate`}.
|
3689
|
+
*/
|
3690
|
+
angular.module('ngAnimate', [])
|
3691
|
+
.directive('ngAnimateChildren', $$AnimateChildrenDirective)
|
3692
|
+
|
3693
|
+
.factory('$$rAFMutex', $$rAFMutexFactory)
|
3694
|
+
.factory('$$rAFScheduler', $$rAFSchedulerFactory)
|
3695
|
+
|
3696
|
+
.factory('$$AnimateRunner', $$AnimateRunnerFactory)
|
3697
|
+
|
3698
|
+
.provider('$$animateQueue', $$AnimateQueueProvider)
|
3699
|
+
.provider('$$animation', $$AnimationProvider)
|
3700
|
+
|
3701
|
+
.provider('$animateCss', $AnimateCssProvider)
|
3702
|
+
.provider('$$animateCssDriver', $$AnimateCssDriverProvider)
|
3703
|
+
|
3704
|
+
.provider('$$animateJs', $$AnimateJsProvider)
|
3705
|
+
.provider('$$animateJsDriver', $$AnimateJsDriverProvider);
|
3706
|
+
|
3707
|
+
|
3708
|
+
})(window, window.angular);
|