|
@@ -0,0 +1,4115 @@
|
|
|
+
|
|
|
+ * @license AngularJS v1.5.3
|
|
|
+ * (c) 2010-2016 Google, Inc. http:
|
|
|
+ * License: MIT
|
|
|
+ */
|
|
|
+(function(window, angular, undefined) {'use strict';
|
|
|
+
|
|
|
+
|
|
|
+var noop = angular.noop;
|
|
|
+var copy = angular.copy;
|
|
|
+var extend = angular.extend;
|
|
|
+var jqLite = angular.element;
|
|
|
+var forEach = angular.forEach;
|
|
|
+var isArray = angular.isArray;
|
|
|
+var isString = angular.isString;
|
|
|
+var isObject = angular.isObject;
|
|
|
+var isUndefined = angular.isUndefined;
|
|
|
+var isDefined = angular.isDefined;
|
|
|
+var isFunction = angular.isFunction;
|
|
|
+var isElement = angular.isElement;
|
|
|
+
|
|
|
+var ELEMENT_NODE = 1;
|
|
|
+var COMMENT_NODE = 8;
|
|
|
+
|
|
|
+var ADD_CLASS_SUFFIX = '-add';
|
|
|
+var REMOVE_CLASS_SUFFIX = '-remove';
|
|
|
+var EVENT_CLASS_PREFIX = 'ng-';
|
|
|
+var ACTIVE_CLASS_SUFFIX = '-active';
|
|
|
+var PREPARE_CLASS_SUFFIX = '-prepare';
|
|
|
+
|
|
|
+var NG_ANIMATE_CLASSNAME = 'ng-animate';
|
|
|
+var NG_ANIMATE_CHILDREN_DATA = '$$ngAnimateChildren';
|
|
|
+
|
|
|
+
|
|
|
+var CSS_PREFIX = '', TRANSITION_PROP, TRANSITIONEND_EVENT, ANIMATION_PROP, ANIMATIONEND_EVENT;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+if (isUndefined(window.ontransitionend) && isDefined(window.onwebkittransitionend)) {
|
|
|
+ CSS_PREFIX = '-webkit-';
|
|
|
+ TRANSITION_PROP = 'WebkitTransition';
|
|
|
+ TRANSITIONEND_EVENT = 'webkitTransitionEnd transitionend';
|
|
|
+} else {
|
|
|
+ TRANSITION_PROP = 'transition';
|
|
|
+ TRANSITIONEND_EVENT = 'transitionend';
|
|
|
+}
|
|
|
+
|
|
|
+if (isUndefined(window.onanimationend) && isDefined(window.onwebkitanimationend)) {
|
|
|
+ CSS_PREFIX = '-webkit-';
|
|
|
+ ANIMATION_PROP = 'WebkitAnimation';
|
|
|
+ ANIMATIONEND_EVENT = 'webkitAnimationEnd animationend';
|
|
|
+} else {
|
|
|
+ ANIMATION_PROP = 'animation';
|
|
|
+ ANIMATIONEND_EVENT = 'animationend';
|
|
|
+}
|
|
|
+
|
|
|
+var DURATION_KEY = 'Duration';
|
|
|
+var PROPERTY_KEY = 'Property';
|
|
|
+var DELAY_KEY = 'Delay';
|
|
|
+var TIMING_KEY = 'TimingFunction';
|
|
|
+var ANIMATION_ITERATION_COUNT_KEY = 'IterationCount';
|
|
|
+var ANIMATION_PLAYSTATE_KEY = 'PlayState';
|
|
|
+var SAFE_FAST_FORWARD_DURATION_VALUE = 9999;
|
|
|
+
|
|
|
+var ANIMATION_DELAY_PROP = ANIMATION_PROP + DELAY_KEY;
|
|
|
+var ANIMATION_DURATION_PROP = ANIMATION_PROP + DURATION_KEY;
|
|
|
+var TRANSITION_DELAY_PROP = TRANSITION_PROP + DELAY_KEY;
|
|
|
+var TRANSITION_DURATION_PROP = TRANSITION_PROP + DURATION_KEY;
|
|
|
+
|
|
|
+var isPromiseLike = function(p) {
|
|
|
+ return p && p.then ? true : false;
|
|
|
+};
|
|
|
+
|
|
|
+var ngMinErr = angular.$$minErr('ng');
|
|
|
+function assertArg(arg, name, reason) {
|
|
|
+ if (!arg) {
|
|
|
+ throw ngMinErr('areq', "Argument '{0}' is {1}", (name || '?'), (reason || "required"));
|
|
|
+ }
|
|
|
+ return arg;
|
|
|
+}
|
|
|
+
|
|
|
+function mergeClasses(a,b) {
|
|
|
+ if (!a && !b) return '';
|
|
|
+ if (!a) return b;
|
|
|
+ if (!b) return a;
|
|
|
+ if (isArray(a)) a = a.join(' ');
|
|
|
+ if (isArray(b)) b = b.join(' ');
|
|
|
+ return a + ' ' + b;
|
|
|
+}
|
|
|
+
|
|
|
+function packageStyles(options) {
|
|
|
+ var styles = {};
|
|
|
+ if (options && (options.to || options.from)) {
|
|
|
+ styles.to = options.to;
|
|
|
+ styles.from = options.from;
|
|
|
+ }
|
|
|
+ return styles;
|
|
|
+}
|
|
|
+
|
|
|
+function pendClasses(classes, fix, isPrefix) {
|
|
|
+ var className = '';
|
|
|
+ classes = isArray(classes)
|
|
|
+ ? classes
|
|
|
+ : classes && isString(classes) && classes.length
|
|
|
+ ? classes.split(/\s+/)
|
|
|
+ : [];
|
|
|
+ forEach(classes, function(klass, i) {
|
|
|
+ if (klass && klass.length > 0) {
|
|
|
+ className += (i > 0) ? ' ' : '';
|
|
|
+ className += isPrefix ? fix + klass
|
|
|
+ : klass + fix;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return className;
|
|
|
+}
|
|
|
+
|
|
|
+function removeFromArray(arr, val) {
|
|
|
+ var index = arr.indexOf(val);
|
|
|
+ if (val >= 0) {
|
|
|
+ arr.splice(index, 1);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function stripCommentsFromElement(element) {
|
|
|
+ if (element instanceof jqLite) {
|
|
|
+ switch (element.length) {
|
|
|
+ case 0:
|
|
|
+ return [];
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 1:
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (element[0].nodeType === ELEMENT_NODE) {
|
|
|
+ return element;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ return jqLite(extractElementNode(element));
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (element.nodeType === ELEMENT_NODE) {
|
|
|
+ return jqLite(element);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function extractElementNode(element) {
|
|
|
+ if (!element[0]) return element;
|
|
|
+ for (var i = 0; i < element.length; i++) {
|
|
|
+ var elm = element[i];
|
|
|
+ if (elm.nodeType == ELEMENT_NODE) {
|
|
|
+ return elm;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function $$addClass($$jqLite, element, className) {
|
|
|
+ forEach(element, function(elm) {
|
|
|
+ $$jqLite.addClass(elm, className);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function $$removeClass($$jqLite, element, className) {
|
|
|
+ forEach(element, function(elm) {
|
|
|
+ $$jqLite.removeClass(elm, className);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function applyAnimationClassesFactory($$jqLite) {
|
|
|
+ return function(element, options) {
|
|
|
+ if (options.addClass) {
|
|
|
+ $$addClass($$jqLite, element, options.addClass);
|
|
|
+ options.addClass = null;
|
|
|
+ }
|
|
|
+ if (options.removeClass) {
|
|
|
+ $$removeClass($$jqLite, element, options.removeClass);
|
|
|
+ options.removeClass = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function prepareAnimationOptions(options) {
|
|
|
+ options = options || {};
|
|
|
+ if (!options.$$prepared) {
|
|
|
+ var domOperation = options.domOperation || noop;
|
|
|
+ options.domOperation = function() {
|
|
|
+ options.$$domOperationFired = true;
|
|
|
+ domOperation();
|
|
|
+ domOperation = noop;
|
|
|
+ };
|
|
|
+ options.$$prepared = true;
|
|
|
+ }
|
|
|
+ return options;
|
|
|
+}
|
|
|
+
|
|
|
+function applyAnimationStyles(element, options) {
|
|
|
+ applyAnimationFromStyles(element, options);
|
|
|
+ applyAnimationToStyles(element, options);
|
|
|
+}
|
|
|
+
|
|
|
+function applyAnimationFromStyles(element, options) {
|
|
|
+ if (options.from) {
|
|
|
+ element.css(options.from);
|
|
|
+ options.from = null;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function applyAnimationToStyles(element, options) {
|
|
|
+ if (options.to) {
|
|
|
+ element.css(options.to);
|
|
|
+ options.to = null;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function mergeAnimationDetails(element, oldAnimation, newAnimation) {
|
|
|
+ var target = oldAnimation.options || {};
|
|
|
+ var newOptions = newAnimation.options || {};
|
|
|
+
|
|
|
+ var toAdd = (target.addClass || '') + ' ' + (newOptions.addClass || '');
|
|
|
+ var toRemove = (target.removeClass || '') + ' ' + (newOptions.removeClass || '');
|
|
|
+ var classes = resolveElementClasses(element.attr('class'), toAdd, toRemove);
|
|
|
+
|
|
|
+ if (newOptions.preparationClasses) {
|
|
|
+ target.preparationClasses = concatWithSpace(newOptions.preparationClasses, target.preparationClasses);
|
|
|
+ delete newOptions.preparationClasses;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var realDomOperation = target.domOperation !== noop ? target.domOperation : null;
|
|
|
+
|
|
|
+ extend(target, newOptions);
|
|
|
+
|
|
|
+
|
|
|
+ if (realDomOperation) {
|
|
|
+ target.domOperation = realDomOperation;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (classes.addClass) {
|
|
|
+ target.addClass = classes.addClass;
|
|
|
+ } else {
|
|
|
+ target.addClass = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (classes.removeClass) {
|
|
|
+ target.removeClass = classes.removeClass;
|
|
|
+ } else {
|
|
|
+ target.removeClass = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ oldAnimation.addClass = target.addClass;
|
|
|
+ oldAnimation.removeClass = target.removeClass;
|
|
|
+
|
|
|
+ return target;
|
|
|
+}
|
|
|
+
|
|
|
+function resolveElementClasses(existing, toAdd, toRemove) {
|
|
|
+ var ADD_CLASS = 1;
|
|
|
+ var REMOVE_CLASS = -1;
|
|
|
+
|
|
|
+ var flags = {};
|
|
|
+ existing = splitClassesToLookup(existing);
|
|
|
+
|
|
|
+ toAdd = splitClassesToLookup(toAdd);
|
|
|
+ forEach(toAdd, function(value, key) {
|
|
|
+ flags[key] = ADD_CLASS;
|
|
|
+ });
|
|
|
+
|
|
|
+ toRemove = splitClassesToLookup(toRemove);
|
|
|
+ forEach(toRemove, function(value, key) {
|
|
|
+ flags[key] = flags[key] === ADD_CLASS ? null : REMOVE_CLASS;
|
|
|
+ });
|
|
|
+
|
|
|
+ var classes = {
|
|
|
+ addClass: '',
|
|
|
+ removeClass: ''
|
|
|
+ };
|
|
|
+
|
|
|
+ forEach(flags, function(val, klass) {
|
|
|
+ var prop, allow;
|
|
|
+ if (val === ADD_CLASS) {
|
|
|
+ prop = 'addClass';
|
|
|
+ allow = !existing[klass];
|
|
|
+ } else if (val === REMOVE_CLASS) {
|
|
|
+ prop = 'removeClass';
|
|
|
+ allow = existing[klass];
|
|
|
+ }
|
|
|
+ if (allow) {
|
|
|
+ if (classes[prop].length) {
|
|
|
+ classes[prop] += ' ';
|
|
|
+ }
|
|
|
+ classes[prop] += klass;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ function splitClassesToLookup(classes) {
|
|
|
+ if (isString(classes)) {
|
|
|
+ classes = classes.split(' ');
|
|
|
+ }
|
|
|
+
|
|
|
+ var obj = {};
|
|
|
+ forEach(classes, function(klass) {
|
|
|
+
|
|
|
+
|
|
|
+ if (klass.length) {
|
|
|
+ obj[klass] = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return obj;
|
|
|
+ }
|
|
|
+
|
|
|
+ return classes;
|
|
|
+}
|
|
|
+
|
|
|
+function getDomNode(element) {
|
|
|
+ return (element instanceof angular.element) ? element[0] : element;
|
|
|
+}
|
|
|
+
|
|
|
+function applyGeneratedPreparationClasses(element, event, options) {
|
|
|
+ var classes = '';
|
|
|
+ if (event) {
|
|
|
+ classes = pendClasses(event, EVENT_CLASS_PREFIX, true);
|
|
|
+ }
|
|
|
+ if (options.addClass) {
|
|
|
+ classes = concatWithSpace(classes, pendClasses(options.addClass, ADD_CLASS_SUFFIX));
|
|
|
+ }
|
|
|
+ if (options.removeClass) {
|
|
|
+ classes = concatWithSpace(classes, pendClasses(options.removeClass, REMOVE_CLASS_SUFFIX));
|
|
|
+ }
|
|
|
+ if (classes.length) {
|
|
|
+ options.preparationClasses = classes;
|
|
|
+ element.addClass(classes);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function clearGeneratedClasses(element, options) {
|
|
|
+ if (options.preparationClasses) {
|
|
|
+ element.removeClass(options.preparationClasses);
|
|
|
+ options.preparationClasses = null;
|
|
|
+ }
|
|
|
+ if (options.activeClasses) {
|
|
|
+ element.removeClass(options.activeClasses);
|
|
|
+ options.activeClasses = null;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function blockTransitions(node, duration) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var value = duration ? '-' + duration + 's' : '';
|
|
|
+ applyInlineStyle(node, [TRANSITION_DELAY_PROP, value]);
|
|
|
+ return [TRANSITION_DELAY_PROP, value];
|
|
|
+}
|
|
|
+
|
|
|
+function blockKeyframeAnimations(node, applyBlock) {
|
|
|
+ var value = applyBlock ? 'paused' : '';
|
|
|
+ var key = ANIMATION_PROP + ANIMATION_PLAYSTATE_KEY;
|
|
|
+ applyInlineStyle(node, [key, value]);
|
|
|
+ return [key, value];
|
|
|
+}
|
|
|
+
|
|
|
+function applyInlineStyle(node, styleTuple) {
|
|
|
+ var prop = styleTuple[0];
|
|
|
+ var value = styleTuple[1];
|
|
|
+ node.style[prop] = value;
|
|
|
+}
|
|
|
+
|
|
|
+function concatWithSpace(a,b) {
|
|
|
+ if (!a) return b;
|
|
|
+ if (!b) return a;
|
|
|
+ return a + ' ' + b;
|
|
|
+}
|
|
|
+
|
|
|
+var $$rAFSchedulerFactory = ['$$rAF', function($$rAF) {
|
|
|
+ var queue, cancelFn;
|
|
|
+
|
|
|
+ function scheduler(tasks) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ queue = queue.concat(tasks);
|
|
|
+ nextTick();
|
|
|
+ }
|
|
|
+
|
|
|
+ queue = scheduler.queue = [];
|
|
|
+
|
|
|
+
|
|
|
+ * 1. It will run the FINAL `fn` value only when an uncanceled RAF has passed through
|
|
|
+ * 2. It will delay the next wave of tasks from running until the quiet `fn` has run.
|
|
|
+ *
|
|
|
+ * The motivation here is that animation code can request more time from the scheduler
|
|
|
+ * before the next wave runs. This allows for certain DOM properties such as classes to
|
|
|
+ * be resolved in time for the next animation to run.
|
|
|
+ */
|
|
|
+ scheduler.waitUntilQuiet = function(fn) {
|
|
|
+ if (cancelFn) cancelFn();
|
|
|
+
|
|
|
+ cancelFn = $$rAF(function() {
|
|
|
+ cancelFn = null;
|
|
|
+ fn();
|
|
|
+ nextTick();
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ return scheduler;
|
|
|
+
|
|
|
+ function nextTick() {
|
|
|
+ if (!queue.length) return;
|
|
|
+
|
|
|
+ var items = queue.shift();
|
|
|
+ for (var i = 0; i < items.length; i++) {
|
|
|
+ items[i]();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!cancelFn) {
|
|
|
+ $$rAF(function() {
|
|
|
+ if (!cancelFn) nextTick();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+}];
|
|
|
+
|
|
|
+
|
|
|
+ * @ngdoc directive
|
|
|
+ * @name ngAnimateChildren
|
|
|
+ * @restrict AE
|
|
|
+ * @element ANY
|
|
|
+ *
|
|
|
+ * @description
|
|
|
+ *
|
|
|
+ * ngAnimateChildren allows you to specify that children of this element should animate even if any
|
|
|
+ * of the children's parents are currently animating. By default, when an element has an active `enter`, `leave`, or `move`
|
|
|
+ * (structural) animation, child elements that also have an active structural animation are not animated.
|
|
|
+ *
|
|
|
+ * Note that even if `ngAnimteChildren` is set, no child animations will run when the parent element is removed from the DOM (`leave` animation).
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @param {string} ngAnimateChildren If the value is empty, `true` or `on`,
|
|
|
+ * then child animations are allowed. If the value is `false`, child animations are not allowed.
|
|
|
+ *
|
|
|
+ * @example
|
|
|
+ * <example module="ngAnimateChildren" name="ngAnimateChildren" deps="angular-animate.js" animations="true">
|
|
|
+ <file name="index.html">
|
|
|
+ <div ng-controller="mainController as main">
|
|
|
+ <label>Show container? <input type="checkbox" ng-model="main.enterElement" /></label>
|
|
|
+ <label>Animate children? <input type="checkbox" ng-model="main.animateChildren" /></label>
|
|
|
+ <hr>
|
|
|
+ <div ng-animate-children="{{main.animateChildren}}">
|
|
|
+ <div ng-if="main.enterElement" class="container">
|
|
|
+ List of items:
|
|
|
+ <div ng-repeat="item in [0, 1, 2, 3]" class="item">Item {{item}}</div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </file>
|
|
|
+ <file name="animations.css">
|
|
|
+
|
|
|
+ .container.ng-enter,
|
|
|
+ .container.ng-leave {
|
|
|
+ transition: all ease 1.5s;
|
|
|
+ }
|
|
|
+
|
|
|
+ .container.ng-enter,
|
|
|
+ .container.ng-leave-active {
|
|
|
+ opacity: 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ .container.ng-leave,
|
|
|
+ .container.ng-enter-active {
|
|
|
+ opacity: 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ .item {
|
|
|
+ background: firebrick;
|
|
|
+ color: #FFF;
|
|
|
+ margin-bottom: 10px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .item.ng-enter,
|
|
|
+ .item.ng-leave {
|
|
|
+ transition: transform 1.5s ease;
|
|
|
+ }
|
|
|
+
|
|
|
+ .item.ng-enter {
|
|
|
+ transform: translateX(50px);
|
|
|
+ }
|
|
|
+
|
|
|
+ .item.ng-enter-active {
|
|
|
+ transform: translateX(0);
|
|
|
+ }
|
|
|
+ </file>
|
|
|
+ <file name="script.js">
|
|
|
+ angular.module('ngAnimateChildren', ['ngAnimate'])
|
|
|
+ .controller('mainController', function() {
|
|
|
+ this.animateChildren = false;
|
|
|
+ this.enterElement = false;
|
|
|
+ });
|
|
|
+ </file>
|
|
|
+ </example>
|
|
|
+ */
|
|
|
+var $$AnimateChildrenDirective = ['$interpolate', function($interpolate) {
|
|
|
+ return {
|
|
|
+ link: function(scope, element, attrs) {
|
|
|
+ var val = attrs.ngAnimateChildren;
|
|
|
+ if (angular.isString(val) && val.length === 0) {
|
|
|
+ element.data(NG_ANIMATE_CHILDREN_DATA, true);
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+ setData($interpolate(val)(scope));
|
|
|
+ attrs.$observe('ngAnimateChildren', setData);
|
|
|
+ }
|
|
|
+
|
|
|
+ function setData(value) {
|
|
|
+ value = value === 'on' || value === 'true';
|
|
|
+ element.data(NG_ANIMATE_CHILDREN_DATA, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+}];
|
|
|
+
|
|
|
+var ANIMATE_TIMER_KEY = '$$animateCss';
|
|
|
+
|
|
|
+
|
|
|
+ * @ngdoc service
|
|
|
+ * @name $animateCss
|
|
|
+ * @kind object
|
|
|
+ *
|
|
|
+ * @description
|
|
|
+ * The `$animateCss` service is a useful utility to trigger customized CSS-based transitions/keyframes
|
|
|
+ * from a JavaScript-based animation or directly from a directive. The purpose of `$animateCss` is NOT
|
|
|
+ * to side-step how `$animate` and ngAnimate work, but the goal is to allow pre-existing animations or
|
|
|
+ * directives to create more complex animations that can be purely driven using CSS code.
|
|
|
+ *
|
|
|
+ * Note that only browsers that support CSS transitions and/or keyframe animations are capable of
|
|
|
+ * rendering animations triggered via `$animateCss` (bad news for IE9 and lower).
|
|
|
+ *
|
|
|
+ * ## Usage
|
|
|
+ * Once again, `$animateCss` is designed to be used inside of a registered JavaScript animation that
|
|
|
+ * is powered by ngAnimate. It is possible to use `$animateCss` directly inside of a directive, however,
|
|
|
+ * any automatic control over cancelling animations and/or preventing animations from being run on
|
|
|
+ * child elements will not be handled by Angular. For this to work as expected, please use `$animate` to
|
|
|
+ * trigger the animation and then setup a JavaScript animation that injects `$animateCss` to trigger
|
|
|
+ * the CSS animation.
|
|
|
+ *
|
|
|
+ * The example below shows how we can create a folding animation on an element using `ng-if`:
|
|
|
+ *
|
|
|
+ * ```html
|
|
|
+ * <!-- notice the `fold-animation` CSS class -->
|
|
|
+ * <div ng-if="onOff" class="fold-animation">
|
|
|
+ * This element will go BOOM
|
|
|
+ * </div>
|
|
|
+ * <button ng-click="onOff=true">Fold In</button>
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * Now we create the **JavaScript animation** that will trigger the CSS transition:
|
|
|
+ *
|
|
|
+ * ```js
|
|
|
+ * ngModule.animation('.fold-animation', ['$animateCss', function($animateCss) {
|
|
|
+ * return {
|
|
|
+ * enter: function(element, doneFn) {
|
|
|
+ * var height = element[0].offsetHeight;
|
|
|
+ * return $animateCss(element, {
|
|
|
+ * from: { height:'0px' },
|
|
|
+ * to: { height:height + 'px' },
|
|
|
+ * duration: 1
|
|
|
+ * });
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * }]);
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * ## More Advanced Uses
|
|
|
+ *
|
|
|
+ * `$animateCss` is the underlying code that ngAnimate uses to power **CSS-based animations** behind the scenes. Therefore CSS hooks
|
|
|
+ * like `.ng-EVENT`, `.ng-EVENT-active`, `.ng-EVENT-stagger` are all features that can be triggered using `$animateCss` via JavaScript code.
|
|
|
+ *
|
|
|
+ * This also means that just about any combination of adding classes, removing classes, setting styles, dynamically setting a keyframe animation,
|
|
|
+ * applying a hardcoded duration or delay value, changing the animation easing or applying a stagger animation are all options that work with
|
|
|
+ * `$animateCss`. The service itself is smart enough to figure out the combination of options and examine the element styling properties in order
|
|
|
+ * to provide a working animation that will run in CSS.
|
|
|
+ *
|
|
|
+ * The example below showcases a more advanced version of the `.fold-animation` from the example above:
|
|
|
+ *
|
|
|
+ * ```js
|
|
|
+ * ngModule.animation('.fold-animation', ['$animateCss', function($animateCss) {
|
|
|
+ * return {
|
|
|
+ * enter: function(element, doneFn) {
|
|
|
+ * var height = element[0].offsetHeight;
|
|
|
+ * return $animateCss(element, {
|
|
|
+ * addClass: 'red large-text pulse-twice',
|
|
|
+ * easing: 'ease-out',
|
|
|
+ * from: { height:'0px' },
|
|
|
+ * to: { height:height + 'px' },
|
|
|
+ * duration: 1
|
|
|
+ * });
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * }]);
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * Since we're adding/removing CSS classes then the CSS transition will also pick those up:
|
|
|
+ *
|
|
|
+ * ```css
|
|
|
+ * /* since a hardcoded duration value of 1 was provided in the JavaScript animation code,
|
|
|
+ * the CSS classes below will be transitioned despite them being defined as regular CSS classes */
|
|
|
+ * .red { background:red; }
|
|
|
+ * .large-text { font-size:20px; }
|
|
|
+ *
|
|
|
+ * /* we can also use a keyframe animation and $animateCss will make it work alongside the transition */
|
|
|
+ * .pulse-twice {
|
|
|
+ * animation: 0.5s pulse linear 2;
|
|
|
+ * -webkit-animation: 0.5s pulse linear 2;
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * @keyframes pulse {
|
|
|
+ * from { transform: scale(0.5); }
|
|
|
+ * to { transform: scale(1.5); }
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * @-webkit-keyframes pulse {
|
|
|
+ * from { -webkit-transform: scale(0.5); }
|
|
|
+ * to { -webkit-transform: scale(1.5); }
|
|
|
+ * }
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * Given this complex combination of CSS classes, styles and options, `$animateCss` will figure everything out and make the animation happen.
|
|
|
+ *
|
|
|
+ * ## How the Options are handled
|
|
|
+ *
|
|
|
+ * `$animateCss` is very versatile and intelligent when it comes to figuring out what configurations to apply to the element to ensure the animation
|
|
|
+ * 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
|
|
|
+ * styles using the `from` and `to` properties.
|
|
|
+ *
|
|
|
+ * ```js
|
|
|
+ * var animator = $animateCss(element, {
|
|
|
+ * from: { background:'red' },
|
|
|
+ * to: { background:'blue' }
|
|
|
+ * });
|
|
|
+ * animator.start();
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * ```css
|
|
|
+ * .rotating-animation {
|
|
|
+ * animation:0.5s rotate linear;
|
|
|
+ * -webkit-animation:0.5s rotate linear;
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * @keyframes rotate {
|
|
|
+ * from { transform: rotate(0deg); }
|
|
|
+ * to { transform: rotate(360deg); }
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * @-webkit-keyframes rotate {
|
|
|
+ * from { -webkit-transform: rotate(0deg); }
|
|
|
+ * to { -webkit-transform: rotate(360deg); }
|
|
|
+ * }
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * 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
|
|
|
+ * going to be detected from what the keyframe styles on the CSS class are. In this event, `$animateCss` will automatically create an inline transition
|
|
|
+ * 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
|
|
|
+ * 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
|
|
|
+ * and spread across the transition and keyframe animation.
|
|
|
+ *
|
|
|
+ * ## What is returned
|
|
|
+ *
|
|
|
+ * `$animateCss` works in two stages: a preparation phase and an animation phase. Therefore when `$animateCss` is first called it will NOT actually
|
|
|
+ * 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
|
|
|
+ * added and removed on the element). Once `$animateCss` is called it will return an object with the following properties:
|
|
|
+ *
|
|
|
+ * ```js
|
|
|
+ * var animator = $animateCss(element, { ... });
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * Now what do the contents of our `animator` variable look like:
|
|
|
+ *
|
|
|
+ * ```js
|
|
|
+ * {
|
|
|
+ *
|
|
|
+ * start: Function,
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * end: Function
|
|
|
+ * }
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * 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.
|
|
|
+ * 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 styles may have been
|
|
|
+ * applied to the element during the preparation phase). Note that all other properties such as duration, delay, transitions and keyframes are just properties
|
|
|
+ * and that changing them will not reconfigure the parameters of the animation.
|
|
|
+ *
|
|
|
+ * ### runner.done() vs runner.then()
|
|
|
+ * 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
|
|
|
+ * runner called `.done(callbackFn)`. The done method works the same as `.finally(callbackFn)`, however, it does **not trigger a digest to occur**.
|
|
|
+ * Therefore, for performance reasons, it's always best to use `runner.done(callback)` instead of `runner.then()`, `runner.catch()` or `runner.finally()`
|
|
|
+ * unless you really need a digest to kick off afterwards.
|
|
|
+ *
|
|
|
+ * 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
|
|
|
+ * (so there is no need to call `runner.done(doneFn)` inside of your JavaScript animation code).
|
|
|
+ * Check the {@link ngAnimate.$animateCss#usage animation code above} to see how this works.
|
|
|
+ *
|
|
|
+ * @param {DOMElement} element the element that will be animated
|
|
|
+ * @param {object} options the animation-related options that will be applied during the animation
|
|
|
+ *
|
|
|
+ * * `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
|
|
|
+ * 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.)
|
|
|
+ * * `structural` - Indicates that the `ng-` prefix will be added to the event class. Setting to `false` or omitting will turn `ng-EVENT` and
|
|
|
+ * `ng-EVENT-active` in `EVENT` and `EVENT-active`. Unused if `event` is omitted.
|
|
|
+ * * `easing` - The CSS easing value that will be applied to the transition or keyframe animation (or both).
|
|
|
+ * * `transitionStyle` - The raw CSS transition style that will be used (e.g. `1s linear all`).
|
|
|
+ * * `keyframeStyle` - The raw CSS keyframe animation style that will be used (e.g. `1s my_animation linear`).
|
|
|
+ * * `from` - The starting CSS styles (a key/value object) that will be applied at the start of the animation.
|
|
|
+ * * `to` - The ending CSS styles (a key/value object) that will be applied across the animation via a CSS transition.
|
|
|
+ * * `addClass` - A space separated list of CSS classes that will be added to the element and spread across the animation.
|
|
|
+ * * `removeClass` - A space separated list of CSS classes that will be removed from the element and spread across the animation.
|
|
|
+ * * `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`
|
|
|
+ * is provided then the animation will be skipped entirely.
|
|
|
+ * * `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
|
|
|
+ * 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
|
|
|
+ * 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
|
|
|
+ * CSS delay value.
|
|
|
+ * * `stagger` - A numeric time value representing the delay between successively animated elements
|
|
|
+ * ({@link ngAnimate#css-staggering-animations Click here to learn how CSS-based staggering works in ngAnimate.})
|
|
|
+ * * `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
|
|
|
+ * `stagger` option value of `0.1` is used then there will be a stagger delay of `600ms`)
|
|
|
+ * * `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 occurring on the classes being added and removed.)
|
|
|
+ * * `cleanupStyles` - Whether or not the provided `from` and `to` styles will be removed once
|
|
|
+ * the animation is closed. This is useful for when the styles are used purely for the sake of
|
|
|
+ * the animation and do not have a lasting visual effect on the element (e.g. a collapse and open animation).
|
|
|
+ * By default this value is set to `false`.
|
|
|
+ *
|
|
|
+ * @return {object} an object with start and end methods and details about the animation.
|
|
|
+ *
|
|
|
+ * * `start` - The method to start the animation. This will return a `Promise` when called.
|
|
|
+ * * `end` - This method will cancel the animation and remove all applied CSS classes and styles.
|
|
|
+ */
|
|
|
+var ONE_SECOND = 1000;
|
|
|
+var BASE_TEN = 10;
|
|
|
+
|
|
|
+var ELAPSED_TIME_MAX_DECIMAL_PLACES = 3;
|
|
|
+var CLOSING_TIME_BUFFER = 1.5;
|
|
|
+
|
|
|
+var DETECT_CSS_PROPERTIES = {
|
|
|
+ transitionDuration: TRANSITION_DURATION_PROP,
|
|
|
+ transitionDelay: TRANSITION_DELAY_PROP,
|
|
|
+ transitionProperty: TRANSITION_PROP + PROPERTY_KEY,
|
|
|
+ animationDuration: ANIMATION_DURATION_PROP,
|
|
|
+ animationDelay: ANIMATION_DELAY_PROP,
|
|
|
+ animationIterationCount: ANIMATION_PROP + ANIMATION_ITERATION_COUNT_KEY
|
|
|
+};
|
|
|
+
|
|
|
+var DETECT_STAGGER_CSS_PROPERTIES = {
|
|
|
+ transitionDuration: TRANSITION_DURATION_PROP,
|
|
|
+ transitionDelay: TRANSITION_DELAY_PROP,
|
|
|
+ animationDuration: ANIMATION_DURATION_PROP,
|
|
|
+ animationDelay: ANIMATION_DELAY_PROP
|
|
|
+};
|
|
|
+
|
|
|
+function getCssKeyframeDurationStyle(duration) {
|
|
|
+ return [ANIMATION_DURATION_PROP, duration + 's'];
|
|
|
+}
|
|
|
+
|
|
|
+function getCssDelayStyle(delay, isKeyframeAnimation) {
|
|
|
+ var prop = isKeyframeAnimation ? ANIMATION_DELAY_PROP : TRANSITION_DELAY_PROP;
|
|
|
+ return [prop, delay + 's'];
|
|
|
+}
|
|
|
+
|
|
|
+function computeCssStyles($window, element, properties) {
|
|
|
+ var styles = Object.create(null);
|
|
|
+ var detectedStyles = $window.getComputedStyle(element) || {};
|
|
|
+ forEach(properties, function(formalStyleName, actualStyleName) {
|
|
|
+ var val = detectedStyles[formalStyleName];
|
|
|
+ if (val) {
|
|
|
+ var c = val.charAt(0);
|
|
|
+
|
|
|
+
|
|
|
+ if (c === '-' || c === '+' || c >= 0) {
|
|
|
+ val = parseMaxTime(val);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (val === 0) {
|
|
|
+ val = null;
|
|
|
+ }
|
|
|
+ styles[actualStyleName] = val;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return styles;
|
|
|
+}
|
|
|
+
|
|
|
+function parseMaxTime(str) {
|
|
|
+ var maxValue = 0;
|
|
|
+ var values = str.split(/\s*,\s*/);
|
|
|
+ forEach(values, function(value) {
|
|
|
+
|
|
|
+
|
|
|
+ if (value.charAt(value.length - 1) == 's') {
|
|
|
+ value = value.substring(0, value.length - 1);
|
|
|
+ }
|
|
|
+ value = parseFloat(value) || 0;
|
|
|
+ maxValue = maxValue ? Math.max(value, maxValue) : value;
|
|
|
+ });
|
|
|
+ return maxValue;
|
|
|
+}
|
|
|
+
|
|
|
+function truthyTimingValue(val) {
|
|
|
+ return val === 0 || val != null;
|
|
|
+}
|
|
|
+
|
|
|
+function getCssTransitionDurationStyle(duration, applyOnlyDuration) {
|
|
|
+ var style = TRANSITION_PROP;
|
|
|
+ var value = duration + 's';
|
|
|
+ if (applyOnlyDuration) {
|
|
|
+ style += DURATION_KEY;
|
|
|
+ } else {
|
|
|
+ value += ' linear all';
|
|
|
+ }
|
|
|
+ return [style, value];
|
|
|
+}
|
|
|
+
|
|
|
+function createLocalCacheLookup() {
|
|
|
+ var cache = Object.create(null);
|
|
|
+ return {
|
|
|
+ flush: function() {
|
|
|
+ cache = Object.create(null);
|
|
|
+ },
|
|
|
+
|
|
|
+ count: function(key) {
|
|
|
+ var entry = cache[key];
|
|
|
+ return entry ? entry.total : 0;
|
|
|
+ },
|
|
|
+
|
|
|
+ get: function(key) {
|
|
|
+ var entry = cache[key];
|
|
|
+ return entry && entry.value;
|
|
|
+ },
|
|
|
+
|
|
|
+ put: function(key, value) {
|
|
|
+ if (!cache[key]) {
|
|
|
+ cache[key] = { total: 1, value: value };
|
|
|
+ } else {
|
|
|
+ cache[key].total++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+function registerRestorableStyles(backup, node, properties) {
|
|
|
+ forEach(properties, function(prop) {
|
|
|
+ backup[prop] = isDefined(backup[prop])
|
|
|
+ ? backup[prop]
|
|
|
+ : node.style.getPropertyValue(prop);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
|
|
|
+ var gcsLookup = createLocalCacheLookup();
|
|
|
+ var gcsStaggerLookup = createLocalCacheLookup();
|
|
|
+
|
|
|
+ this.$get = ['$window', '$$jqLite', '$$AnimateRunner', '$timeout',
|
|
|
+ '$$forceReflow', '$sniffer', '$$rAFScheduler', '$$animateQueue',
|
|
|
+ function($window, $$jqLite, $$AnimateRunner, $timeout,
|
|
|
+ $$forceReflow, $sniffer, $$rAFScheduler, $$animateQueue) {
|
|
|
+
|
|
|
+ var applyAnimationClasses = applyAnimationClassesFactory($$jqLite);
|
|
|
+
|
|
|
+ var parentCounter = 0;
|
|
|
+ function gcsHashFn(node, extraClasses) {
|
|
|
+ var KEY = "$$ngAnimateParentKey";
|
|
|
+ var parentNode = node.parentNode;
|
|
|
+ var parentID = parentNode[KEY] || (parentNode[KEY] = ++parentCounter);
|
|
|
+ return parentID + '-' + node.getAttribute('class') + '-' + extraClasses;
|
|
|
+ }
|
|
|
+
|
|
|
+ function computeCachedCssStyles(node, className, cacheKey, properties) {
|
|
|
+ var timings = gcsLookup.get(cacheKey);
|
|
|
+
|
|
|
+ if (!timings) {
|
|
|
+ timings = computeCssStyles($window, node, properties);
|
|
|
+ if (timings.animationIterationCount === 'infinite') {
|
|
|
+ timings.animationIterationCount = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ gcsLookup.put(cacheKey, timings);
|
|
|
+ return timings;
|
|
|
+ }
|
|
|
+
|
|
|
+ function computeCachedCssStaggerStyles(node, className, cacheKey, properties) {
|
|
|
+ var stagger;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (gcsLookup.count(cacheKey) > 0) {
|
|
|
+ stagger = gcsStaggerLookup.get(cacheKey);
|
|
|
+
|
|
|
+ if (!stagger) {
|
|
|
+ var staggerClassName = pendClasses(className, '-stagger');
|
|
|
+
|
|
|
+ $$jqLite.addClass(node, staggerClassName);
|
|
|
+
|
|
|
+ stagger = computeCssStyles($window, node, properties);
|
|
|
+
|
|
|
+
|
|
|
+ stagger.animationDuration = Math.max(stagger.animationDuration, 0);
|
|
|
+ stagger.transitionDuration = Math.max(stagger.transitionDuration, 0);
|
|
|
+
|
|
|
+ $$jqLite.removeClass(node, staggerClassName);
|
|
|
+
|
|
|
+ gcsStaggerLookup.put(cacheKey, stagger);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return stagger || {};
|
|
|
+ }
|
|
|
+
|
|
|
+ var cancelLastRAFRequest;
|
|
|
+ var rafWaitQueue = [];
|
|
|
+ function waitUntilQuiet(callback) {
|
|
|
+ rafWaitQueue.push(callback);
|
|
|
+ $$rAFScheduler.waitUntilQuiet(function() {
|
|
|
+ gcsLookup.flush();
|
|
|
+ gcsStaggerLookup.flush();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var pageWidth = $$forceReflow();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ for (var i = 0; i < rafWaitQueue.length; i++) {
|
|
|
+ rafWaitQueue[i](pageWidth);
|
|
|
+ }
|
|
|
+ rafWaitQueue.length = 0;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function computeTimings(node, className, cacheKey) {
|
|
|
+ var timings = computeCachedCssStyles(node, className, cacheKey, DETECT_CSS_PROPERTIES);
|
|
|
+ var aD = timings.animationDelay;
|
|
|
+ var tD = timings.transitionDelay;
|
|
|
+ timings.maxDelay = aD && tD
|
|
|
+ ? Math.max(aD, tD)
|
|
|
+ : (aD || tD);
|
|
|
+ timings.maxDuration = Math.max(
|
|
|
+ timings.animationDuration * timings.animationIterationCount,
|
|
|
+ timings.transitionDuration);
|
|
|
+
|
|
|
+ return timings;
|
|
|
+ }
|
|
|
+
|
|
|
+ return function init(element, initialOptions) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var options = initialOptions || {};
|
|
|
+ if (!options.$$prepared) {
|
|
|
+ options = prepareAnimationOptions(copy(options));
|
|
|
+ }
|
|
|
+
|
|
|
+ var restoreStyles = {};
|
|
|
+ var node = getDomNode(element);
|
|
|
+ if (!node
|
|
|
+ || !node.parentNode
|
|
|
+ || !$$animateQueue.enabled()) {
|
|
|
+ return closeAndReturnNoopAnimator();
|
|
|
+ }
|
|
|
+
|
|
|
+ var temporaryStyles = [];
|
|
|
+ var classes = element.attr('class');
|
|
|
+ var styles = packageStyles(options);
|
|
|
+ var animationClosed;
|
|
|
+ var animationPaused;
|
|
|
+ var animationCompleted;
|
|
|
+ var runner;
|
|
|
+ var runnerHost;
|
|
|
+ var maxDelay;
|
|
|
+ var maxDelayTime;
|
|
|
+ var maxDuration;
|
|
|
+ var maxDurationTime;
|
|
|
+ var startTime;
|
|
|
+ var events = [];
|
|
|
+
|
|
|
+ if (options.duration === 0 || (!$sniffer.animations && !$sniffer.transitions)) {
|
|
|
+ return closeAndReturnNoopAnimator();
|
|
|
+ }
|
|
|
+
|
|
|
+ var method = options.event && isArray(options.event)
|
|
|
+ ? options.event.join(' ')
|
|
|
+ : options.event;
|
|
|
+
|
|
|
+ var isStructural = method && options.structural;
|
|
|
+ var structuralClassName = '';
|
|
|
+ var addRemoveClassName = '';
|
|
|
+
|
|
|
+ if (isStructural) {
|
|
|
+ structuralClassName = pendClasses(method, EVENT_CLASS_PREFIX, true);
|
|
|
+ } else if (method) {
|
|
|
+ structuralClassName = method;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (options.addClass) {
|
|
|
+ addRemoveClassName += pendClasses(options.addClass, ADD_CLASS_SUFFIX);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (options.removeClass) {
|
|
|
+ if (addRemoveClassName.length) {
|
|
|
+ addRemoveClassName += ' ';
|
|
|
+ }
|
|
|
+ addRemoveClassName += pendClasses(options.removeClass, REMOVE_CLASS_SUFFIX);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (options.applyClassesEarly && addRemoveClassName.length) {
|
|
|
+ applyAnimationClasses(element, options);
|
|
|
+ }
|
|
|
+
|
|
|
+ var preparationClasses = [structuralClassName, addRemoveClassName].join(' ').trim();
|
|
|
+ var fullClassName = classes + ' ' + preparationClasses;
|
|
|
+ var activeClasses = pendClasses(preparationClasses, ACTIVE_CLASS_SUFFIX);
|
|
|
+ var hasToStyles = styles.to && Object.keys(styles.to).length > 0;
|
|
|
+ var containsKeyframeAnimation = (options.keyframeStyle || '').length > 0;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!containsKeyframeAnimation
|
|
|
+ && !hasToStyles
|
|
|
+ && !preparationClasses) {
|
|
|
+ return closeAndReturnNoopAnimator();
|
|
|
+ }
|
|
|
+
|
|
|
+ var cacheKey, stagger;
|
|
|
+ if (options.stagger > 0) {
|
|
|
+ var staggerVal = parseFloat(options.stagger);
|
|
|
+ stagger = {
|
|
|
+ transitionDelay: staggerVal,
|
|
|
+ animationDelay: staggerVal,
|
|
|
+ transitionDuration: 0,
|
|
|
+ animationDuration: 0
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ cacheKey = gcsHashFn(node, fullClassName);
|
|
|
+ stagger = computeCachedCssStaggerStyles(node, preparationClasses, cacheKey, DETECT_STAGGER_CSS_PROPERTIES);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!options.$$skipPreparationClasses) {
|
|
|
+ $$jqLite.addClass(element, preparationClasses);
|
|
|
+ }
|
|
|
+
|
|
|
+ var applyOnlyDuration;
|
|
|
+
|
|
|
+ if (options.transitionStyle) {
|
|
|
+ var transitionStyle = [TRANSITION_PROP, options.transitionStyle];
|
|
|
+ applyInlineStyle(node, transitionStyle);
|
|
|
+ temporaryStyles.push(transitionStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (options.duration >= 0) {
|
|
|
+ applyOnlyDuration = node.style[TRANSITION_PROP].length > 0;
|
|
|
+ var durationStyle = getCssTransitionDurationStyle(options.duration, applyOnlyDuration);
|
|
|
+
|
|
|
+
|
|
|
+ applyInlineStyle(node, durationStyle);
|
|
|
+ temporaryStyles.push(durationStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (options.keyframeStyle) {
|
|
|
+ var keyframeStyle = [ANIMATION_PROP, options.keyframeStyle];
|
|
|
+ applyInlineStyle(node, keyframeStyle);
|
|
|
+ temporaryStyles.push(keyframeStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ var itemIndex = stagger
|
|
|
+ ? options.staggerIndex >= 0
|
|
|
+ ? options.staggerIndex
|
|
|
+ : gcsLookup.count(cacheKey)
|
|
|
+ : 0;
|
|
|
+
|
|
|
+ var isFirst = itemIndex === 0;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (isFirst && !options.skipBlocking) {
|
|
|
+ blockTransitions(node, SAFE_FAST_FORWARD_DURATION_VALUE);
|
|
|
+ }
|
|
|
+
|
|
|
+ var timings = computeTimings(node, fullClassName, cacheKey);
|
|
|
+ var relativeDelay = timings.maxDelay;
|
|
|
+ maxDelay = Math.max(relativeDelay, 0);
|
|
|
+ maxDuration = timings.maxDuration;
|
|
|
+
|
|
|
+ var flags = {};
|
|
|
+ flags.hasTransitions = timings.transitionDuration > 0;
|
|
|
+ flags.hasAnimations = timings.animationDuration > 0;
|
|
|
+ flags.hasTransitionAll = flags.hasTransitions && timings.transitionProperty == 'all';
|
|
|
+ flags.applyTransitionDuration = hasToStyles && (
|
|
|
+ (flags.hasTransitions && !flags.hasTransitionAll)
|
|
|
+ || (flags.hasAnimations && !flags.hasTransitions));
|
|
|
+ flags.applyAnimationDuration = options.duration && flags.hasAnimations;
|
|
|
+ flags.applyTransitionDelay = truthyTimingValue(options.delay) && (flags.applyTransitionDuration || flags.hasTransitions);
|
|
|
+ flags.applyAnimationDelay = truthyTimingValue(options.delay) && flags.hasAnimations;
|
|
|
+ flags.recalculateTimingStyles = addRemoveClassName.length > 0;
|
|
|
+
|
|
|
+ if (flags.applyTransitionDuration || flags.applyAnimationDuration) {
|
|
|
+ maxDuration = options.duration ? parseFloat(options.duration) : maxDuration;
|
|
|
+
|
|
|
+ if (flags.applyTransitionDuration) {
|
|
|
+ flags.hasTransitions = true;
|
|
|
+ timings.transitionDuration = maxDuration;
|
|
|
+ applyOnlyDuration = node.style[TRANSITION_PROP + PROPERTY_KEY].length > 0;
|
|
|
+ temporaryStyles.push(getCssTransitionDurationStyle(maxDuration, applyOnlyDuration));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (flags.applyAnimationDuration) {
|
|
|
+ flags.hasAnimations = true;
|
|
|
+ timings.animationDuration = maxDuration;
|
|
|
+ temporaryStyles.push(getCssKeyframeDurationStyle(maxDuration));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (maxDuration === 0 && !flags.recalculateTimingStyles) {
|
|
|
+ return closeAndReturnNoopAnimator();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (options.delay != null) {
|
|
|
+ var delayStyle;
|
|
|
+ if (typeof options.delay !== "boolean") {
|
|
|
+ delayStyle = parseFloat(options.delay);
|
|
|
+
|
|
|
+ maxDelay = Math.max(delayStyle, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (flags.applyTransitionDelay) {
|
|
|
+ temporaryStyles.push(getCssDelayStyle(delayStyle));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (flags.applyAnimationDelay) {
|
|
|
+ temporaryStyles.push(getCssDelayStyle(delayStyle, true));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (options.duration == null && timings.transitionDuration > 0) {
|
|
|
+ flags.recalculateTimingStyles = flags.recalculateTimingStyles || isFirst;
|
|
|
+ }
|
|
|
+
|
|
|
+ maxDelayTime = maxDelay * ONE_SECOND;
|
|
|
+ maxDurationTime = maxDuration * ONE_SECOND;
|
|
|
+ if (!options.skipBlocking) {
|
|
|
+ flags.blockTransition = timings.transitionDuration > 0;
|
|
|
+ flags.blockKeyframeAnimation = timings.animationDuration > 0 &&
|
|
|
+ stagger.animationDelay > 0 &&
|
|
|
+ stagger.animationDuration === 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (options.from) {
|
|
|
+ if (options.cleanupStyles) {
|
|
|
+ registerRestorableStyles(restoreStyles, node, Object.keys(options.from));
|
|
|
+ }
|
|
|
+ applyAnimationFromStyles(element, options);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (flags.blockTransition || flags.blockKeyframeAnimation) {
|
|
|
+ applyBlocking(maxDuration);
|
|
|
+ } else if (!options.skipBlocking) {
|
|
|
+ blockTransitions(node, false);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return {
|
|
|
+ $$willAnimate: true,
|
|
|
+ end: endFn,
|
|
|
+ start: function() {
|
|
|
+ if (animationClosed) return;
|
|
|
+
|
|
|
+ runnerHost = {
|
|
|
+ end: endFn,
|
|
|
+ cancel: cancelFn,
|
|
|
+ resume: null,
|
|
|
+ pause: null
|
|
|
+ };
|
|
|
+
|
|
|
+ runner = new $$AnimateRunner(runnerHost);
|
|
|
+
|
|
|
+ waitUntilQuiet(start);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return runner;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ function endFn() {
|
|
|
+ close();
|
|
|
+ }
|
|
|
+
|
|
|
+ function cancelFn() {
|
|
|
+ close(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ function close(rejected) {
|
|
|
+
|
|
|
+
|
|
|
+ if (animationClosed || (animationCompleted && animationPaused)) return;
|
|
|
+ animationClosed = true;
|
|
|
+ animationPaused = false;
|
|
|
+
|
|
|
+ if (!options.$$skipPreparationClasses) {
|
|
|
+ $$jqLite.removeClass(element, preparationClasses);
|
|
|
+ }
|
|
|
+ $$jqLite.removeClass(element, activeClasses);
|
|
|
+
|
|
|
+ blockKeyframeAnimations(node, false);
|
|
|
+ blockTransitions(node, false);
|
|
|
+
|
|
|
+ forEach(temporaryStyles, function(entry) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ node.style[entry[0]] = '';
|
|
|
+ });
|
|
|
+
|
|
|
+ applyAnimationClasses(element, options);
|
|
|
+ applyAnimationStyles(element, options);
|
|
|
+
|
|
|
+ if (Object.keys(restoreStyles).length) {
|
|
|
+ forEach(restoreStyles, function(value, prop) {
|
|
|
+ value ? node.style.setProperty(prop, value)
|
|
|
+ : node.style.removeProperty(prop);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (options.onDone) {
|
|
|
+ options.onDone();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (events && events.length) {
|
|
|
+
|
|
|
+ element.off(events.join(' '), onAnimationProgress);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var animationTimerData = element.data(ANIMATE_TIMER_KEY);
|
|
|
+ if (animationTimerData) {
|
|
|
+ $timeout.cancel(animationTimerData[0].timer);
|
|
|
+ element.removeData(ANIMATE_TIMER_KEY);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (runner) {
|
|
|
+ runner.complete(!rejected);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function applyBlocking(duration) {
|
|
|
+ if (flags.blockTransition) {
|
|
|
+ blockTransitions(node, duration);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (flags.blockKeyframeAnimation) {
|
|
|
+ blockKeyframeAnimations(node, !!duration);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function closeAndReturnNoopAnimator() {
|
|
|
+ runner = new $$AnimateRunner({
|
|
|
+ end: endFn,
|
|
|
+ cancel: cancelFn
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ waitUntilQuiet(noop);
|
|
|
+ close();
|
|
|
+
|
|
|
+ return {
|
|
|
+ $$willAnimate: false,
|
|
|
+ start: function() {
|
|
|
+ return runner;
|
|
|
+ },
|
|
|
+ end: endFn
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ function onAnimationProgress(event) {
|
|
|
+ event.stopPropagation();
|
|
|
+ var ev = event.originalEvent || event;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var timeStamp = ev.$manualTimeStamp || Date.now();
|
|
|
+
|
|
|
+
|
|
|
+ * when a ms measurement is used for the animation */
|
|
|
+ var elapsedTime = parseFloat(ev.elapsedTime.toFixed(ELAPSED_TIME_MAX_DECIMAL_PLACES));
|
|
|
+
|
|
|
+
|
|
|
+ * within browserTrigger(). This is only here so that tests can
|
|
|
+ * mock animations properly. Real events fallback to event.timeStamp,
|
|
|
+ * or, if they don't, then a timeStamp is automatically created for them.
|
|
|
+ * We're checking to see if the timeStamp surpasses the expected delay,
|
|
|
+ * but we're using elapsedTime instead of the timeStamp on the 2nd
|
|
|
+ * pre-condition since animationPauseds sometimes close off early */
|
|
|
+ if (Math.max(timeStamp - startTime, 0) >= maxDelayTime && elapsedTime >= maxDuration) {
|
|
|
+
|
|
|
+
|
|
|
+ animationCompleted = true;
|
|
|
+ close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function start() {
|
|
|
+ if (animationClosed) return;
|
|
|
+ if (!node.parentNode) {
|
|
|
+ close();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var playPause = function(playAnimation) {
|
|
|
+ if (!animationCompleted) {
|
|
|
+ animationPaused = !playAnimation;
|
|
|
+ if (timings.animationDuration) {
|
|
|
+ var value = blockKeyframeAnimations(node, animationPaused);
|
|
|
+ animationPaused
|
|
|
+ ? temporaryStyles.push(value)
|
|
|
+ : removeFromArray(temporaryStyles, value);
|
|
|
+ }
|
|
|
+ } else if (animationPaused && playAnimation) {
|
|
|
+ animationPaused = false;
|
|
|
+ close();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var maxStagger = itemIndex > 0
|
|
|
+ && ((timings.transitionDuration && stagger.transitionDuration === 0) ||
|
|
|
+ (timings.animationDuration && stagger.animationDuration === 0))
|
|
|
+ && Math.max(stagger.animationDelay, stagger.transitionDelay);
|
|
|
+ if (maxStagger) {
|
|
|
+ $timeout(triggerAnimationStart,
|
|
|
+ Math.floor(maxStagger * itemIndex * ONE_SECOND),
|
|
|
+ false);
|
|
|
+ } else {
|
|
|
+ triggerAnimationStart();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ runnerHost.resume = function() {
|
|
|
+ playPause(true);
|
|
|
+ };
|
|
|
+
|
|
|
+ runnerHost.pause = function() {
|
|
|
+ playPause(false);
|
|
|
+ };
|
|
|
+
|
|
|
+ function triggerAnimationStart() {
|
|
|
+
|
|
|
+
|
|
|
+ if (animationClosed) return;
|
|
|
+
|
|
|
+ applyBlocking(false);
|
|
|
+
|
|
|
+ forEach(temporaryStyles, function(entry) {
|
|
|
+ var key = entry[0];
|
|
|
+ var value = entry[1];
|
|
|
+ node.style[key] = value;
|
|
|
+ });
|
|
|
+
|
|
|
+ applyAnimationClasses(element, options);
|
|
|
+ $$jqLite.addClass(element, activeClasses);
|
|
|
+
|
|
|
+ if (flags.recalculateTimingStyles) {
|
|
|
+ fullClassName = node.className + ' ' + preparationClasses;
|
|
|
+ cacheKey = gcsHashFn(node, fullClassName);
|
|
|
+
|
|
|
+ timings = computeTimings(node, fullClassName, cacheKey);
|
|
|
+ relativeDelay = timings.maxDelay;
|
|
|
+ maxDelay = Math.max(relativeDelay, 0);
|
|
|
+ maxDuration = timings.maxDuration;
|
|
|
+
|
|
|
+ if (maxDuration === 0) {
|
|
|
+ close();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ flags.hasTransitions = timings.transitionDuration > 0;
|
|
|
+ flags.hasAnimations = timings.animationDuration > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (flags.applyAnimationDelay) {
|
|
|
+ relativeDelay = typeof options.delay !== "boolean" && truthyTimingValue(options.delay)
|
|
|
+ ? parseFloat(options.delay)
|
|
|
+ : relativeDelay;
|
|
|
+
|
|
|
+ maxDelay = Math.max(relativeDelay, 0);
|
|
|
+ timings.animationDelay = relativeDelay;
|
|
|
+ delayStyle = getCssDelayStyle(relativeDelay, true);
|
|
|
+ temporaryStyles.push(delayStyle);
|
|
|
+ node.style[delayStyle[0]] = delayStyle[1];
|
|
|
+ }
|
|
|
+
|
|
|
+ maxDelayTime = maxDelay * ONE_SECOND;
|
|
|
+ maxDurationTime = maxDuration * ONE_SECOND;
|
|
|
+
|
|
|
+ if (options.easing) {
|
|
|
+ var easeProp, easeVal = options.easing;
|
|
|
+ if (flags.hasTransitions) {
|
|
|
+ easeProp = TRANSITION_PROP + TIMING_KEY;
|
|
|
+ temporaryStyles.push([easeProp, easeVal]);
|
|
|
+ node.style[easeProp] = easeVal;
|
|
|
+ }
|
|
|
+ if (flags.hasAnimations) {
|
|
|
+ easeProp = ANIMATION_PROP + TIMING_KEY;
|
|
|
+ temporaryStyles.push([easeProp, easeVal]);
|
|
|
+ node.style[easeProp] = easeVal;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (timings.transitionDuration) {
|
|
|
+ events.push(TRANSITIONEND_EVENT);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (timings.animationDuration) {
|
|
|
+ events.push(ANIMATIONEND_EVENT);
|
|
|
+ }
|
|
|
+
|
|
|
+ startTime = Date.now();
|
|
|
+ var timerTime = maxDelayTime + CLOSING_TIME_BUFFER * maxDurationTime;
|
|
|
+ var endTime = startTime + timerTime;
|
|
|
+
|
|
|
+ var animationsData = element.data(ANIMATE_TIMER_KEY) || [];
|
|
|
+ var setupFallbackTimer = true;
|
|
|
+ if (animationsData.length) {
|
|
|
+ var currentTimerData = animationsData[0];
|
|
|
+ setupFallbackTimer = endTime > currentTimerData.expectedEndTime;
|
|
|
+ if (setupFallbackTimer) {
|
|
|
+ $timeout.cancel(currentTimerData.timer);
|
|
|
+ } else {
|
|
|
+ animationsData.push(close);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (setupFallbackTimer) {
|
|
|
+ var timer = $timeout(onAnimationExpired, timerTime, false);
|
|
|
+ animationsData[0] = {
|
|
|
+ timer: timer,
|
|
|
+ expectedEndTime: endTime
|
|
|
+ };
|
|
|
+ animationsData.push(close);
|
|
|
+ element.data(ANIMATE_TIMER_KEY, animationsData);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (events.length) {
|
|
|
+ element.on(events.join(' '), onAnimationProgress);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (options.to) {
|
|
|
+ if (options.cleanupStyles) {
|
|
|
+ registerRestorableStyles(restoreStyles, node, Object.keys(options.to));
|
|
|
+ }
|
|
|
+ applyAnimationToStyles(element, options);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function onAnimationExpired() {
|
|
|
+ var animationsData = element.data(ANIMATE_TIMER_KEY);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (animationsData) {
|
|
|
+ for (var i = 1; i < animationsData.length; i++) {
|
|
|
+ animationsData[i]();
|
|
|
+ }
|
|
|
+ element.removeData(ANIMATE_TIMER_KEY);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }];
|
|
|
+}];
|
|
|
+
|
|
|
+var $$AnimateCssDriverProvider = ['$$animationProvider', function($$animationProvider) {
|
|
|
+ $$animationProvider.drivers.push('$$animateCssDriver');
|
|
|
+
|
|
|
+ var NG_ANIMATE_SHIM_CLASS_NAME = 'ng-animate-shim';
|
|
|
+ var NG_ANIMATE_ANCHOR_CLASS_NAME = 'ng-anchor';
|
|
|
+
|
|
|
+ var NG_OUT_ANCHOR_CLASS_NAME = 'ng-anchor-out';
|
|
|
+ var NG_IN_ANCHOR_CLASS_NAME = 'ng-anchor-in';
|
|
|
+
|
|
|
+ function isDocumentFragment(node) {
|
|
|
+ return node.parentNode && node.parentNode.nodeType === 11;
|
|
|
+ }
|
|
|
+
|
|
|
+ this.$get = ['$animateCss', '$rootScope', '$$AnimateRunner', '$rootElement', '$sniffer', '$$jqLite', '$document',
|
|
|
+ function($animateCss, $rootScope, $$AnimateRunner, $rootElement, $sniffer, $$jqLite, $document) {
|
|
|
+
|
|
|
+
|
|
|
+ if (!$sniffer.animations && !$sniffer.transitions) return noop;
|
|
|
+
|
|
|
+ var bodyNode = $document[0].body;
|
|
|
+ var rootNode = getDomNode($rootElement);
|
|
|
+
|
|
|
+ var rootBodyElement = jqLite(
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ isDocumentFragment(rootNode) || bodyNode.contains(rootNode) ? rootNode : bodyNode
|
|
|
+ );
|
|
|
+
|
|
|
+ var applyAnimationClasses = applyAnimationClassesFactory($$jqLite);
|
|
|
+
|
|
|
+ return function initDriverFn(animationDetails) {
|
|
|
+ return animationDetails.from && animationDetails.to
|
|
|
+ ? prepareFromToAnchorAnimation(animationDetails.from,
|
|
|
+ animationDetails.to,
|
|
|
+ animationDetails.classes,
|
|
|
+ animationDetails.anchors)
|
|
|
+ : prepareRegularAnimation(animationDetails);
|
|
|
+ };
|
|
|
+
|
|
|
+ function filterCssClasses(classes) {
|
|
|
+
|
|
|
+ return classes.replace(/\bng-\S+\b/g, '');
|
|
|
+ }
|
|
|
+
|
|
|
+ function getUniqueValues(a, b) {
|
|
|
+ if (isString(a)) a = a.split(' ');
|
|
|
+ if (isString(b)) b = b.split(' ');
|
|
|
+ return a.filter(function(val) {
|
|
|
+ return b.indexOf(val) === -1;
|
|
|
+ }).join(' ');
|
|
|
+ }
|
|
|
+
|
|
|
+ function prepareAnchoredAnimation(classes, outAnchor, inAnchor) {
|
|
|
+ var clone = jqLite(getDomNode(outAnchor).cloneNode(true));
|
|
|
+ var startingClasses = filterCssClasses(getClassVal(clone));
|
|
|
+
|
|
|
+ outAnchor.addClass(NG_ANIMATE_SHIM_CLASS_NAME);
|
|
|
+ inAnchor.addClass(NG_ANIMATE_SHIM_CLASS_NAME);
|
|
|
+
|
|
|
+ clone.addClass(NG_ANIMATE_ANCHOR_CLASS_NAME);
|
|
|
+
|
|
|
+ rootBodyElement.append(clone);
|
|
|
+
|
|
|
+ var animatorIn, animatorOut = prepareOutAnimation();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!animatorOut) {
|
|
|
+ animatorIn = prepareInAnimation();
|
|
|
+ if (!animatorIn) {
|
|
|
+ return end();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var startingAnimator = animatorOut || animatorIn;
|
|
|
+
|
|
|
+ return {
|
|
|
+ start: function() {
|
|
|
+ var runner;
|
|
|
+
|
|
|
+ var currentAnimation = startingAnimator.start();
|
|
|
+ currentAnimation.done(function() {
|
|
|
+ currentAnimation = null;
|
|
|
+ if (!animatorIn) {
|
|
|
+ animatorIn = prepareInAnimation();
|
|
|
+ if (animatorIn) {
|
|
|
+ currentAnimation = animatorIn.start();
|
|
|
+ currentAnimation.done(function() {
|
|
|
+ currentAnimation = null;
|
|
|
+ end();
|
|
|
+ runner.complete();
|
|
|
+ });
|
|
|
+ return currentAnimation;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ end();
|
|
|
+ runner.complete();
|
|
|
+ });
|
|
|
+
|
|
|
+ runner = new $$AnimateRunner({
|
|
|
+ end: endFn,
|
|
|
+ cancel: endFn
|
|
|
+ });
|
|
|
+
|
|
|
+ return runner;
|
|
|
+
|
|
|
+ function endFn() {
|
|
|
+ if (currentAnimation) {
|
|
|
+ currentAnimation.end();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ function calculateAnchorStyles(anchor) {
|
|
|
+ var styles = {};
|
|
|
+
|
|
|
+ var coords = getDomNode(anchor).getBoundingClientRect();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ forEach(['width','height','top','left'], function(key) {
|
|
|
+ var value = coords[key];
|
|
|
+ switch (key) {
|
|
|
+ case 'top':
|
|
|
+ value += bodyNode.scrollTop;
|
|
|
+ break;
|
|
|
+ case 'left':
|
|
|
+ value += bodyNode.scrollLeft;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ styles[key] = Math.floor(value) + 'px';
|
|
|
+ });
|
|
|
+ return styles;
|
|
|
+ }
|
|
|
+
|
|
|
+ function prepareOutAnimation() {
|
|
|
+ var animator = $animateCss(clone, {
|
|
|
+ addClass: NG_OUT_ANCHOR_CLASS_NAME,
|
|
|
+ delay: true,
|
|
|
+ from: calculateAnchorStyles(outAnchor)
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return animator.$$willAnimate ? animator : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ function getClassVal(element) {
|
|
|
+ return element.attr('class') || '';
|
|
|
+ }
|
|
|
+
|
|
|
+ function prepareInAnimation() {
|
|
|
+ var endingClasses = filterCssClasses(getClassVal(inAnchor));
|
|
|
+ var toAdd = getUniqueValues(endingClasses, startingClasses);
|
|
|
+ var toRemove = getUniqueValues(startingClasses, endingClasses);
|
|
|
+
|
|
|
+ var animator = $animateCss(clone, {
|
|
|
+ to: calculateAnchorStyles(inAnchor),
|
|
|
+ addClass: NG_IN_ANCHOR_CLASS_NAME + ' ' + toAdd,
|
|
|
+ removeClass: NG_OUT_ANCHOR_CLASS_NAME + ' ' + toRemove,
|
|
|
+ delay: true
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return animator.$$willAnimate ? animator : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ function end() {
|
|
|
+ clone.remove();
|
|
|
+ outAnchor.removeClass(NG_ANIMATE_SHIM_CLASS_NAME);
|
|
|
+ inAnchor.removeClass(NG_ANIMATE_SHIM_CLASS_NAME);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function prepareFromToAnchorAnimation(from, to, classes, anchors) {
|
|
|
+ var fromAnimation = prepareRegularAnimation(from, noop);
|
|
|
+ var toAnimation = prepareRegularAnimation(to, noop);
|
|
|
+
|
|
|
+ var anchorAnimations = [];
|
|
|
+ forEach(anchors, function(anchor) {
|
|
|
+ var outElement = anchor['out'];
|
|
|
+ var inElement = anchor['in'];
|
|
|
+ var animator = prepareAnchoredAnimation(classes, outElement, inElement);
|
|
|
+ if (animator) {
|
|
|
+ anchorAnimations.push(animator);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ if (!fromAnimation && !toAnimation && anchorAnimations.length === 0) return;
|
|
|
+
|
|
|
+ return {
|
|
|
+ start: function() {
|
|
|
+ var animationRunners = [];
|
|
|
+
|
|
|
+ if (fromAnimation) {
|
|
|
+ animationRunners.push(fromAnimation.start());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (toAnimation) {
|
|
|
+ animationRunners.push(toAnimation.start());
|
|
|
+ }
|
|
|
+
|
|
|
+ forEach(anchorAnimations, function(animation) {
|
|
|
+ animationRunners.push(animation.start());
|
|
|
+ });
|
|
|
+
|
|
|
+ var runner = new $$AnimateRunner({
|
|
|
+ end: endFn,
|
|
|
+ cancel: endFn
|
|
|
+ });
|
|
|
+
|
|
|
+ $$AnimateRunner.all(animationRunners, function(status) {
|
|
|
+ runner.complete(status);
|
|
|
+ });
|
|
|
+
|
|
|
+ return runner;
|
|
|
+
|
|
|
+ function endFn() {
|
|
|
+ forEach(animationRunners, function(runner) {
|
|
|
+ runner.end();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ function prepareRegularAnimation(animationDetails) {
|
|
|
+ var element = animationDetails.element;
|
|
|
+ var options = animationDetails.options || {};
|
|
|
+
|
|
|
+ if (animationDetails.structural) {
|
|
|
+ options.event = animationDetails.event;
|
|
|
+ options.structural = true;
|
|
|
+ options.applyClassesEarly = true;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (animationDetails.event === 'leave') {
|
|
|
+ options.onDone = options.domOperation;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (options.preparationClasses) {
|
|
|
+ options.event = concatWithSpace(options.event, options.preparationClasses);
|
|
|
+ }
|
|
|
+
|
|
|
+ var animator = $animateCss(element, options);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return animator.$$willAnimate ? animator : null;
|
|
|
+ }
|
|
|
+ }];
|
|
|
+}];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+var $$AnimateJsProvider = ['$animateProvider', function($animateProvider) {
|
|
|
+ this.$get = ['$injector', '$$AnimateRunner', '$$jqLite',
|
|
|
+ function($injector, $$AnimateRunner, $$jqLite) {
|
|
|
+
|
|
|
+ var applyAnimationClasses = applyAnimationClassesFactory($$jqLite);
|
|
|
+
|
|
|
+ return function(element, event, classes, options) {
|
|
|
+ var animationClosed = false;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (arguments.length === 3 && isObject(classes)) {
|
|
|
+ options = classes;
|
|
|
+ classes = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ options = prepareAnimationOptions(options);
|
|
|
+ if (!classes) {
|
|
|
+ classes = element.attr('class') || '';
|
|
|
+ if (options.addClass) {
|
|
|
+ classes += ' ' + options.addClass;
|
|
|
+ }
|
|
|
+ if (options.removeClass) {
|
|
|
+ classes += ' ' + options.removeClass;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var classesToAdd = options.addClass;
|
|
|
+ var classesToRemove = options.removeClass;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var animations = lookupAnimations(classes);
|
|
|
+ var before, after;
|
|
|
+ if (animations.length) {
|
|
|
+ var afterFn, beforeFn;
|
|
|
+ if (event == 'leave') {
|
|
|
+ beforeFn = 'leave';
|
|
|
+ afterFn = 'afterLeave';
|
|
|
+ } else {
|
|
|
+ beforeFn = 'before' + event.charAt(0).toUpperCase() + event.substr(1);
|
|
|
+ afterFn = event;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (event !== 'enter' && event !== 'move') {
|
|
|
+ before = packageAnimations(element, event, options, animations, beforeFn);
|
|
|
+ }
|
|
|
+ after = packageAnimations(element, event, options, animations, afterFn);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!before && !after) return;
|
|
|
+
|
|
|
+ function applyOptions() {
|
|
|
+ options.domOperation();
|
|
|
+ applyAnimationClasses(element, options);
|
|
|
+ }
|
|
|
+
|
|
|
+ function close() {
|
|
|
+ animationClosed = true;
|
|
|
+ applyOptions();
|
|
|
+ applyAnimationStyles(element, options);
|
|
|
+ }
|
|
|
+
|
|
|
+ var runner;
|
|
|
+
|
|
|
+ return {
|
|
|
+ $$willAnimate: true,
|
|
|
+ end: function() {
|
|
|
+ if (runner) {
|
|
|
+ runner.end();
|
|
|
+ } else {
|
|
|
+ close();
|
|
|
+ runner = new $$AnimateRunner();
|
|
|
+ runner.complete(true);
|
|
|
+ }
|
|
|
+ return runner;
|
|
|
+ },
|
|
|
+ start: function() {
|
|
|
+ if (runner) {
|
|
|
+ return runner;
|
|
|
+ }
|
|
|
+
|
|
|
+ runner = new $$AnimateRunner();
|
|
|
+ var closeActiveAnimations;
|
|
|
+ var chain = [];
|
|
|
+
|
|
|
+ if (before) {
|
|
|
+ chain.push(function(fn) {
|
|
|
+ closeActiveAnimations = before(fn);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (chain.length) {
|
|
|
+ chain.push(function(fn) {
|
|
|
+ applyOptions();
|
|
|
+ fn(true);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ applyOptions();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (after) {
|
|
|
+ chain.push(function(fn) {
|
|
|
+ closeActiveAnimations = after(fn);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ runner.setHost({
|
|
|
+ end: function() {
|
|
|
+ endAnimations();
|
|
|
+ },
|
|
|
+ cancel: function() {
|
|
|
+ endAnimations(true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ $$AnimateRunner.chain(chain, onComplete);
|
|
|
+ return runner;
|
|
|
+
|
|
|
+ function onComplete(success) {
|
|
|
+ close(success);
|
|
|
+ runner.complete(success);
|
|
|
+ }
|
|
|
+
|
|
|
+ function endAnimations(cancelled) {
|
|
|
+ if (!animationClosed) {
|
|
|
+ (closeActiveAnimations || noop)(cancelled);
|
|
|
+ onComplete(cancelled);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ function executeAnimationFn(fn, element, event, options, onDone) {
|
|
|
+ var args;
|
|
|
+ switch (event) {
|
|
|
+ case 'animate':
|
|
|
+ args = [element, options.from, options.to, onDone];
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'setClass':
|
|
|
+ args = [element, classesToAdd, classesToRemove, onDone];
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'addClass':
|
|
|
+ args = [element, classesToAdd, onDone];
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'removeClass':
|
|
|
+ args = [element, classesToRemove, onDone];
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ args = [element, onDone];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ args.push(options);
|
|
|
+
|
|
|
+ var value = fn.apply(fn, args);
|
|
|
+ if (value) {
|
|
|
+ if (isFunction(value.start)) {
|
|
|
+ value = value.start();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (value instanceof $$AnimateRunner) {
|
|
|
+ value.done(onDone);
|
|
|
+ } else if (isFunction(value)) {
|
|
|
+
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return noop;
|
|
|
+ }
|
|
|
+
|
|
|
+ function groupEventedAnimations(element, event, options, animations, fnName) {
|
|
|
+ var operations = [];
|
|
|
+ forEach(animations, function(ani) {
|
|
|
+ var animation = ani[fnName];
|
|
|
+ if (!animation) return;
|
|
|
+
|
|
|
+
|
|
|
+ operations.push(function() {
|
|
|
+ var runner;
|
|
|
+ var endProgressCb;
|
|
|
+
|
|
|
+ var resolved = false;
|
|
|
+ var onAnimationComplete = function(rejected) {
|
|
|
+ if (!resolved) {
|
|
|
+ resolved = true;
|
|
|
+ (endProgressCb || noop)(rejected);
|
|
|
+ runner.complete(!rejected);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ runner = new $$AnimateRunner({
|
|
|
+ end: function() {
|
|
|
+ onAnimationComplete();
|
|
|
+ },
|
|
|
+ cancel: function() {
|
|
|
+ onAnimationComplete(true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ endProgressCb = executeAnimationFn(animation, element, event, options, function(result) {
|
|
|
+ var cancelled = result === false;
|
|
|
+ onAnimationComplete(cancelled);
|
|
|
+ });
|
|
|
+
|
|
|
+ return runner;
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ return operations;
|
|
|
+ }
|
|
|
+
|
|
|
+ function packageAnimations(element, event, options, animations, fnName) {
|
|
|
+ var operations = groupEventedAnimations(element, event, options, animations, fnName);
|
|
|
+ if (operations.length === 0) {
|
|
|
+ var a,b;
|
|
|
+ if (fnName === 'beforeSetClass') {
|
|
|
+ a = groupEventedAnimations(element, 'removeClass', options, animations, 'beforeRemoveClass');
|
|
|
+ b = groupEventedAnimations(element, 'addClass', options, animations, 'beforeAddClass');
|
|
|
+ } else if (fnName === 'setClass') {
|
|
|
+ a = groupEventedAnimations(element, 'removeClass', options, animations, 'removeClass');
|
|
|
+ b = groupEventedAnimations(element, 'addClass', options, animations, 'addClass');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (a) {
|
|
|
+ operations = operations.concat(a);
|
|
|
+ }
|
|
|
+ if (b) {
|
|
|
+ operations = operations.concat(b);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (operations.length === 0) return;
|
|
|
+
|
|
|
+
|
|
|
+ return function startAnimation(callback) {
|
|
|
+ var runners = [];
|
|
|
+ if (operations.length) {
|
|
|
+ forEach(operations, function(animateFn) {
|
|
|
+ runners.push(animateFn());
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ runners.length ? $$AnimateRunner.all(runners, callback) : callback();
|
|
|
+
|
|
|
+ return function endFn(reject) {
|
|
|
+ forEach(runners, function(runner) {
|
|
|
+ reject ? runner.cancel() : runner.end();
|
|
|
+ });
|
|
|
+ };
|
|
|
+ };
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ function lookupAnimations(classes) {
|
|
|
+ classes = isArray(classes) ? classes : classes.split(' ');
|
|
|
+ var matches = [], flagMap = {};
|
|
|
+ for (var i=0; i < classes.length; i++) {
|
|
|
+ var klass = classes[i],
|
|
|
+ animationFactory = $animateProvider.$$registeredAnimations[klass];
|
|
|
+ if (animationFactory && !flagMap[klass]) {
|
|
|
+ matches.push($injector.get(animationFactory));
|
|
|
+ flagMap[klass] = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return matches;
|
|
|
+ }
|
|
|
+ }];
|
|
|
+}];
|
|
|
+
|
|
|
+var $$AnimateJsDriverProvider = ['$$animationProvider', function($$animationProvider) {
|
|
|
+ $$animationProvider.drivers.push('$$animateJsDriver');
|
|
|
+ this.$get = ['$$animateJs', '$$AnimateRunner', function($$animateJs, $$AnimateRunner) {
|
|
|
+ return function initDriverFn(animationDetails) {
|
|
|
+ if (animationDetails.from && animationDetails.to) {
|
|
|
+ var fromAnimation = prepareAnimation(animationDetails.from);
|
|
|
+ var toAnimation = prepareAnimation(animationDetails.to);
|
|
|
+ if (!fromAnimation && !toAnimation) return;
|
|
|
+
|
|
|
+ return {
|
|
|
+ start: function() {
|
|
|
+ var animationRunners = [];
|
|
|
+
|
|
|
+ if (fromAnimation) {
|
|
|
+ animationRunners.push(fromAnimation.start());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (toAnimation) {
|
|
|
+ animationRunners.push(toAnimation.start());
|
|
|
+ }
|
|
|
+
|
|
|
+ $$AnimateRunner.all(animationRunners, done);
|
|
|
+
|
|
|
+ var runner = new $$AnimateRunner({
|
|
|
+ end: endFnFactory(),
|
|
|
+ cancel: endFnFactory()
|
|
|
+ });
|
|
|
+
|
|
|
+ return runner;
|
|
|
+
|
|
|
+ function endFnFactory() {
|
|
|
+ return function() {
|
|
|
+ forEach(animationRunners, function(runner) {
|
|
|
+
|
|
|
+ runner.end();
|
|
|
+ });
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ function done(status) {
|
|
|
+ runner.complete(status);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ return prepareAnimation(animationDetails);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ function prepareAnimation(animationDetails) {
|
|
|
+
|
|
|
+ var element = animationDetails.element;
|
|
|
+ var event = animationDetails.event;
|
|
|
+ var options = animationDetails.options;
|
|
|
+ var classes = animationDetails.classes;
|
|
|
+ return $$animateJs(element, event, classes, options);
|
|
|
+ }
|
|
|
+ }];
|
|
|
+}];
|
|
|
+
|
|
|
+var NG_ANIMATE_ATTR_NAME = 'data-ng-animate';
|
|
|
+var NG_ANIMATE_PIN_DATA = '$ngAnimatePin';
|
|
|
+var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
|
|
|
+ var PRE_DIGEST_STATE = 1;
|
|
|
+ var RUNNING_STATE = 2;
|
|
|
+ var ONE_SPACE = ' ';
|
|
|
+
|
|
|
+ var rules = this.rules = {
|
|
|
+ skip: [],
|
|
|
+ cancel: [],
|
|
|
+ join: []
|
|
|
+ };
|
|
|
+
|
|
|
+ function makeTruthyCssClassMap(classString) {
|
|
|
+ if (!classString) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ var keys = classString.split(ONE_SPACE);
|
|
|
+ var map = Object.create(null);
|
|
|
+
|
|
|
+ forEach(keys, function(key) {
|
|
|
+ map[key] = true;
|
|
|
+ });
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ function hasMatchingClasses(newClassString, currentClassString) {
|
|
|
+ if (newClassString && currentClassString) {
|
|
|
+ var currentClassMap = makeTruthyCssClassMap(currentClassString);
|
|
|
+ return newClassString.split(ONE_SPACE).some(function(className) {
|
|
|
+ return currentClassMap[className];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function isAllowed(ruleType, element, currentAnimation, previousAnimation) {
|
|
|
+ return rules[ruleType].some(function(fn) {
|
|
|
+ return fn(element, currentAnimation, previousAnimation);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function hasAnimationClasses(animation, and) {
|
|
|
+ var a = (animation.addClass || '').length > 0;
|
|
|
+ var b = (animation.removeClass || '').length > 0;
|
|
|
+ return and ? a && b : a || b;
|
|
|
+ }
|
|
|
+
|
|
|
+ rules.join.push(function(element, newAnimation, currentAnimation) {
|
|
|
+
|
|
|
+ return !newAnimation.structural && hasAnimationClasses(newAnimation);
|
|
|
+ });
|
|
|
+
|
|
|
+ rules.skip.push(function(element, newAnimation, currentAnimation) {
|
|
|
+
|
|
|
+
|
|
|
+ return !newAnimation.structural && !hasAnimationClasses(newAnimation);
|
|
|
+ });
|
|
|
+
|
|
|
+ rules.skip.push(function(element, newAnimation, currentAnimation) {
|
|
|
+
|
|
|
+
|
|
|
+ return currentAnimation.event == 'leave' && newAnimation.structural;
|
|
|
+ });
|
|
|
+
|
|
|
+ rules.skip.push(function(element, newAnimation, currentAnimation) {
|
|
|
+
|
|
|
+ return currentAnimation.structural && currentAnimation.state === RUNNING_STATE && !newAnimation.structural;
|
|
|
+ });
|
|
|
+
|
|
|
+ rules.cancel.push(function(element, newAnimation, currentAnimation) {
|
|
|
+
|
|
|
+ return currentAnimation.structural && newAnimation.structural;
|
|
|
+ });
|
|
|
+
|
|
|
+ rules.cancel.push(function(element, newAnimation, currentAnimation) {
|
|
|
+
|
|
|
+
|
|
|
+ return currentAnimation.state === RUNNING_STATE && newAnimation.structural;
|
|
|
+ });
|
|
|
+
|
|
|
+ rules.cancel.push(function(element, newAnimation, currentAnimation) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (currentAnimation.structural) return false;
|
|
|
+
|
|
|
+ var nA = newAnimation.addClass;
|
|
|
+ var nR = newAnimation.removeClass;
|
|
|
+ var cA = currentAnimation.addClass;
|
|
|
+ var cR = currentAnimation.removeClass;
|
|
|
+
|
|
|
+
|
|
|
+ if ((isUndefined(nA) && isUndefined(nR)) || (isUndefined(cA) && isUndefined(cR))) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return hasMatchingClasses(nA, cR) || hasMatchingClasses(nR, cA);
|
|
|
+ });
|
|
|
+
|
|
|
+ this.$get = ['$$rAF', '$rootScope', '$rootElement', '$document', '$$HashMap',
|
|
|
+ '$$animation', '$$AnimateRunner', '$templateRequest', '$$jqLite', '$$forceReflow',
|
|
|
+ function($$rAF, $rootScope, $rootElement, $document, $$HashMap,
|
|
|
+ $$animation, $$AnimateRunner, $templateRequest, $$jqLite, $$forceReflow) {
|
|
|
+
|
|
|
+ var activeAnimationsLookup = new $$HashMap();
|
|
|
+ var disabledElementsLookup = new $$HashMap();
|
|
|
+ var animationsEnabled = null;
|
|
|
+
|
|
|
+ function postDigestTaskFactory() {
|
|
|
+ var postDigestCalled = false;
|
|
|
+ return function(fn) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (postDigestCalled) {
|
|
|
+ fn();
|
|
|
+ } else {
|
|
|
+ $rootScope.$$postDigest(function() {
|
|
|
+ postDigestCalled = true;
|
|
|
+ fn();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var deregisterWatch = $rootScope.$watch(
|
|
|
+ function() { return $templateRequest.totalPendingRequests === 0; },
|
|
|
+ function(isEmpty) {
|
|
|
+ if (!isEmpty) return;
|
|
|
+ deregisterWatch();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $rootScope.$$postDigest(function() {
|
|
|
+ $rootScope.$$postDigest(function() {
|
|
|
+
|
|
|
+
|
|
|
+ if (animationsEnabled === null) {
|
|
|
+ animationsEnabled = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+ var callbackRegistry = {};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var classNameFilter = $animateProvider.classNameFilter();
|
|
|
+ var isAnimatableClassName = !classNameFilter
|
|
|
+ ? function() { return true; }
|
|
|
+ : function(className) {
|
|
|
+ return classNameFilter.test(className);
|
|
|
+ };
|
|
|
+
|
|
|
+ var applyAnimationClasses = applyAnimationClassesFactory($$jqLite);
|
|
|
+
|
|
|
+ function normalizeAnimationDetails(element, animation) {
|
|
|
+ return mergeAnimationDetails(element, animation, {});
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var contains = Node.prototype.contains || function(arg) {
|
|
|
+
|
|
|
+ return this === arg || !!(this.compareDocumentPosition(arg) & 16);
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ function findCallbacks(parent, element, event) {
|
|
|
+ var targetNode = getDomNode(element);
|
|
|
+ var targetParentNode = getDomNode(parent);
|
|
|
+
|
|
|
+ var matches = [];
|
|
|
+ var entries = callbackRegistry[event];
|
|
|
+ if (entries) {
|
|
|
+ forEach(entries, function(entry) {
|
|
|
+ if (contains.call(entry.node, targetNode)) {
|
|
|
+ matches.push(entry.callback);
|
|
|
+ } else if (event === 'leave' && contains.call(entry.node, targetParentNode)) {
|
|
|
+ matches.push(entry.callback);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return matches;
|
|
|
+ }
|
|
|
+
|
|
|
+ var $animate = {
|
|
|
+ on: function(event, container, callback) {
|
|
|
+ var node = extractElementNode(container);
|
|
|
+ callbackRegistry[event] = callbackRegistry[event] || [];
|
|
|
+ callbackRegistry[event].push({
|
|
|
+ node: node,
|
|
|
+ callback: callback
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ jqLite(container).on('$destroy', function() {
|
|
|
+ $animate.off(event, container, callback);
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ off: function(event, container, callback) {
|
|
|
+ var entries = callbackRegistry[event];
|
|
|
+ if (!entries) return;
|
|
|
+
|
|
|
+ callbackRegistry[event] = arguments.length === 1
|
|
|
+ ? null
|
|
|
+ : filterFromRegistry(entries, container, callback);
|
|
|
+
|
|
|
+ function filterFromRegistry(list, matchContainer, matchCallback) {
|
|
|
+ var containerNode = extractElementNode(matchContainer);
|
|
|
+ return list.filter(function(entry) {
|
|
|
+ var isMatch = entry.node === containerNode &&
|
|
|
+ (!matchCallback || entry.callback === matchCallback);
|
|
|
+ return !isMatch;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ pin: function(element, parentElement) {
|
|
|
+ assertArg(isElement(element), 'element', 'not an element');
|
|
|
+ assertArg(isElement(parentElement), 'parentElement', 'not an element');
|
|
|
+ element.data(NG_ANIMATE_PIN_DATA, parentElement);
|
|
|
+ },
|
|
|
+
|
|
|
+ push: function(element, event, options, domOperation) {
|
|
|
+ options = options || {};
|
|
|
+ options.domOperation = domOperation;
|
|
|
+ return queueAnimation(element, event, options);
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ enabled: function(element, bool) {
|
|
|
+ var argCount = arguments.length;
|
|
|
+
|
|
|
+ if (argCount === 0) {
|
|
|
+
|
|
|
+ bool = !!animationsEnabled;
|
|
|
+ } else {
|
|
|
+ var hasElement = isElement(element);
|
|
|
+
|
|
|
+ if (!hasElement) {
|
|
|
+
|
|
|
+ bool = animationsEnabled = !!element;
|
|
|
+ } else {
|
|
|
+ var node = getDomNode(element);
|
|
|
+ var recordExists = disabledElementsLookup.get(node);
|
|
|
+
|
|
|
+ if (argCount === 1) {
|
|
|
+
|
|
|
+ bool = !recordExists;
|
|
|
+ } else {
|
|
|
+
|
|
|
+ disabledElementsLookup.put(node, !bool);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return bool;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ return $animate;
|
|
|
+
|
|
|
+ function queueAnimation(element, event, initialOptions) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var options = copy(initialOptions);
|
|
|
+
|
|
|
+ var node, parent;
|
|
|
+ element = stripCommentsFromElement(element);
|
|
|
+ if (element) {
|
|
|
+ node = getDomNode(element);
|
|
|
+ parent = element.parent();
|
|
|
+ }
|
|
|
+
|
|
|
+ options = prepareAnimationOptions(options);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var runner = new $$AnimateRunner();
|
|
|
+
|
|
|
+
|
|
|
+ var runInNextPostDigestOrNow = postDigestTaskFactory();
|
|
|
+
|
|
|
+ if (isArray(options.addClass)) {
|
|
|
+ options.addClass = options.addClass.join(' ');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (options.addClass && !isString(options.addClass)) {
|
|
|
+ options.addClass = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isArray(options.removeClass)) {
|
|
|
+ options.removeClass = options.removeClass.join(' ');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (options.removeClass && !isString(options.removeClass)) {
|
|
|
+ options.removeClass = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (options.from && !isObject(options.from)) {
|
|
|
+ options.from = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (options.to && !isObject(options.to)) {
|
|
|
+ options.to = null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!node) {
|
|
|
+ close();
|
|
|
+ return runner;
|
|
|
+ }
|
|
|
+
|
|
|
+ var className = [node.className, options.addClass, options.removeClass].join(' ');
|
|
|
+ if (!isAnimatableClassName(className)) {
|
|
|
+ close();
|
|
|
+ return runner;
|
|
|
+ }
|
|
|
+
|
|
|
+ var isStructural = ['enter', 'move', 'leave'].indexOf(event) >= 0;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var skipAnimations = !animationsEnabled || $document[0].hidden || disabledElementsLookup.get(node);
|
|
|
+ var existingAnimation = (!skipAnimations && activeAnimationsLookup.get(node)) || {};
|
|
|
+ var hasExistingAnimation = !!existingAnimation.state;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!skipAnimations && (!hasExistingAnimation || existingAnimation.state != PRE_DIGEST_STATE)) {
|
|
|
+ skipAnimations = !areAnimationsAllowed(element, parent, event);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (skipAnimations) {
|
|
|
+ close();
|
|
|
+ return runner;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isStructural) {
|
|
|
+ closeChildAnimations(element);
|
|
|
+ }
|
|
|
+
|
|
|
+ var newAnimation = {
|
|
|
+ structural: isStructural,
|
|
|
+ element: element,
|
|
|
+ event: event,
|
|
|
+ addClass: options.addClass,
|
|
|
+ removeClass: options.removeClass,
|
|
|
+ close: close,
|
|
|
+ options: options,
|
|
|
+ runner: runner
|
|
|
+ };
|
|
|
+
|
|
|
+ if (hasExistingAnimation) {
|
|
|
+ var skipAnimationFlag = isAllowed('skip', element, newAnimation, existingAnimation);
|
|
|
+ if (skipAnimationFlag) {
|
|
|
+ if (existingAnimation.state === RUNNING_STATE) {
|
|
|
+ close();
|
|
|
+ return runner;
|
|
|
+ } else {
|
|
|
+ mergeAnimationDetails(element, existingAnimation, newAnimation);
|
|
|
+ return existingAnimation.runner;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var cancelAnimationFlag = isAllowed('cancel', element, newAnimation, existingAnimation);
|
|
|
+ if (cancelAnimationFlag) {
|
|
|
+ if (existingAnimation.state === RUNNING_STATE) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ existingAnimation.runner.end();
|
|
|
+ } else if (existingAnimation.structural) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ existingAnimation.close();
|
|
|
+ } else {
|
|
|
+
|
|
|
+ mergeAnimationDetails(element, existingAnimation, newAnimation);
|
|
|
+
|
|
|
+ return existingAnimation.runner;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var joinAnimationFlag = isAllowed('join', element, newAnimation, existingAnimation);
|
|
|
+ if (joinAnimationFlag) {
|
|
|
+ if (existingAnimation.state === RUNNING_STATE) {
|
|
|
+ normalizeAnimationDetails(element, newAnimation);
|
|
|
+ } else {
|
|
|
+ applyGeneratedPreparationClasses(element, isStructural ? event : null, options);
|
|
|
+
|
|
|
+ event = newAnimation.event = existingAnimation.event;
|
|
|
+ options = mergeAnimationDetails(element, existingAnimation, newAnimation);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return existingAnimation.runner;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+ normalizeAnimationDetails(element, newAnimation);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var isValidAnimation = newAnimation.structural;
|
|
|
+ if (!isValidAnimation) {
|
|
|
+
|
|
|
+ isValidAnimation = (newAnimation.event === 'animate' && Object.keys(newAnimation.options.to || {}).length > 0)
|
|
|
+ || hasAnimationClasses(newAnimation);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!isValidAnimation) {
|
|
|
+ close();
|
|
|
+ clearElementAnimationState(element);
|
|
|
+ return runner;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var counter = (existingAnimation.counter || 0) + 1;
|
|
|
+ newAnimation.counter = counter;
|
|
|
+
|
|
|
+ markElementAnimationState(element, PRE_DIGEST_STATE, newAnimation);
|
|
|
+
|
|
|
+ $rootScope.$$postDigest(function() {
|
|
|
+ var animationDetails = activeAnimationsLookup.get(node);
|
|
|
+ var animationCancelled = !animationDetails;
|
|
|
+ animationDetails = animationDetails || {};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var parentElement = element.parent() || [];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var isValidAnimation = parentElement.length > 0
|
|
|
+ && (animationDetails.event === 'animate'
|
|
|
+ || animationDetails.structural
|
|
|
+ || hasAnimationClasses(animationDetails));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (animationCancelled || animationDetails.counter !== counter || !isValidAnimation) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (animationCancelled) {
|
|
|
+ applyAnimationClasses(element, options);
|
|
|
+ applyAnimationStyles(element, options);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (animationCancelled || (isStructural && animationDetails.event !== event)) {
|
|
|
+ options.domOperation();
|
|
|
+ runner.end();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!isValidAnimation) {
|
|
|
+ clearElementAnimationState(element);
|
|
|
+ }
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ event = !animationDetails.structural && hasAnimationClasses(animationDetails, true)
|
|
|
+ ? 'setClass'
|
|
|
+ : animationDetails.event;
|
|
|
+
|
|
|
+ markElementAnimationState(element, RUNNING_STATE);
|
|
|
+ var realRunner = $$animation(element, event, animationDetails.options);
|
|
|
+
|
|
|
+ realRunner.done(function(status) {
|
|
|
+ close(!status);
|
|
|
+ var animationDetails = activeAnimationsLookup.get(node);
|
|
|
+ if (animationDetails && animationDetails.counter === counter) {
|
|
|
+ clearElementAnimationState(getDomNode(element));
|
|
|
+ }
|
|
|
+ notifyProgress(runner, event, 'close', {});
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ runner.setHost(realRunner);
|
|
|
+ notifyProgress(runner, event, 'start', {});
|
|
|
+ });
|
|
|
+
|
|
|
+ return runner;
|
|
|
+
|
|
|
+ function notifyProgress(runner, event, phase, data) {
|
|
|
+ runInNextPostDigestOrNow(function() {
|
|
|
+ var callbacks = findCallbacks(parent, element, event);
|
|
|
+ if (callbacks.length) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $$rAF(function() {
|
|
|
+ forEach(callbacks, function(callback) {
|
|
|
+ callback(element, phase, data);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ runner.progress(event, phase, data);
|
|
|
+ }
|
|
|
+
|
|
|
+ function close(reject) {
|
|
|
+ clearGeneratedClasses(element, options);
|
|
|
+ applyAnimationClasses(element, options);
|
|
|
+ applyAnimationStyles(element, options);
|
|
|
+ options.domOperation();
|
|
|
+ runner.complete(!reject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function closeChildAnimations(element) {
|
|
|
+ var node = getDomNode(element);
|
|
|
+ var children = node.querySelectorAll('[' + NG_ANIMATE_ATTR_NAME + ']');
|
|
|
+ forEach(children, function(child) {
|
|
|
+ var state = parseInt(child.getAttribute(NG_ANIMATE_ATTR_NAME));
|
|
|
+ var animationDetails = activeAnimationsLookup.get(child);
|
|
|
+ if (animationDetails) {
|
|
|
+ switch (state) {
|
|
|
+ case RUNNING_STATE:
|
|
|
+ animationDetails.runner.end();
|
|
|
+
|
|
|
+ case PRE_DIGEST_STATE:
|
|
|
+ activeAnimationsLookup.remove(child);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function clearElementAnimationState(element) {
|
|
|
+ var node = getDomNode(element);
|
|
|
+ node.removeAttribute(NG_ANIMATE_ATTR_NAME);
|
|
|
+ activeAnimationsLookup.remove(node);
|
|
|
+ }
|
|
|
+
|
|
|
+ function isMatchingElement(nodeOrElmA, nodeOrElmB) {
|
|
|
+ return getDomNode(nodeOrElmA) === getDomNode(nodeOrElmB);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * This fn returns false if any of the following is true:
|
|
|
+ * a) animations on any parent element are disabled, and animations on the element aren't explicitly allowed
|
|
|
+ * b) a parent element has an ongoing structural animation, and animateChildren is false
|
|
|
+ * c) the element is not a child of the body
|
|
|
+ * d) the element is not a child of the $rootElement
|
|
|
+ */
|
|
|
+ function areAnimationsAllowed(element, parentElement, event) {
|
|
|
+ var bodyElement = jqLite($document[0].body);
|
|
|
+ var bodyElementDetected = isMatchingElement(element, bodyElement) || element[0].nodeName === 'HTML';
|
|
|
+ var rootElementDetected = isMatchingElement(element, $rootElement);
|
|
|
+ var parentAnimationDetected = false;
|
|
|
+ var animateChildren;
|
|
|
+ var elementDisabled = disabledElementsLookup.get(getDomNode(element));
|
|
|
+
|
|
|
+ var parentHost = jqLite.data(element[0], NG_ANIMATE_PIN_DATA);
|
|
|
+ if (parentHost) {
|
|
|
+ parentElement = parentHost;
|
|
|
+ }
|
|
|
+
|
|
|
+ parentElement = getDomNode(parentElement);
|
|
|
+
|
|
|
+ while (parentElement) {
|
|
|
+ if (!rootElementDetected) {
|
|
|
+
|
|
|
+
|
|
|
+ rootElementDetected = isMatchingElement(parentElement, $rootElement);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (parentElement.nodeType !== ELEMENT_NODE) {
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ var details = activeAnimationsLookup.get(parentElement) || {};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (!parentAnimationDetected) {
|
|
|
+ var parentElementDisabled = disabledElementsLookup.get(parentElement);
|
|
|
+
|
|
|
+ if (parentElementDisabled === true && elementDisabled !== false) {
|
|
|
+
|
|
|
+
|
|
|
+ elementDisabled = true;
|
|
|
+
|
|
|
+ break;
|
|
|
+ } else if (parentElementDisabled === false) {
|
|
|
+ elementDisabled = false;
|
|
|
+ }
|
|
|
+ parentAnimationDetected = details.structural;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isUndefined(animateChildren) || animateChildren === true) {
|
|
|
+ var value = jqLite.data(parentElement, NG_ANIMATE_CHILDREN_DATA);
|
|
|
+ if (isDefined(value)) {
|
|
|
+ animateChildren = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (parentAnimationDetected && animateChildren === false) break;
|
|
|
+
|
|
|
+ if (!bodyElementDetected) {
|
|
|
+
|
|
|
+
|
|
|
+ bodyElementDetected = isMatchingElement(parentElement, bodyElement);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (bodyElementDetected && rootElementDetected) {
|
|
|
+
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!rootElementDetected) {
|
|
|
+
|
|
|
+ parentHost = jqLite.data(parentElement, NG_ANIMATE_PIN_DATA);
|
|
|
+ if (parentHost) {
|
|
|
+
|
|
|
+ parentElement = getDomNode(parentHost);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ parentElement = parentElement.parentNode;
|
|
|
+ }
|
|
|
+
|
|
|
+ var allowAnimation = (!parentAnimationDetected || animateChildren) && elementDisabled !== true;
|
|
|
+ return allowAnimation && rootElementDetected && bodyElementDetected;
|
|
|
+ }
|
|
|
+
|
|
|
+ function markElementAnimationState(element, state, details) {
|
|
|
+ details = details || {};
|
|
|
+ details.state = state;
|
|
|
+
|
|
|
+ var node = getDomNode(element);
|
|
|
+ node.setAttribute(NG_ANIMATE_ATTR_NAME, state);
|
|
|
+
|
|
|
+ var oldValue = activeAnimationsLookup.get(node);
|
|
|
+ var newValue = oldValue
|
|
|
+ ? extend(oldValue, details)
|
|
|
+ : details;
|
|
|
+ activeAnimationsLookup.put(node, newValue);
|
|
|
+ }
|
|
|
+ }];
|
|
|
+}];
|
|
|
+
|
|
|
+var $$AnimationProvider = ['$animateProvider', function($animateProvider) {
|
|
|
+ var NG_ANIMATE_REF_ATTR = 'ng-animate-ref';
|
|
|
+
|
|
|
+ var drivers = this.drivers = [];
|
|
|
+
|
|
|
+ var RUNNER_STORAGE_KEY = '$$animationRunner';
|
|
|
+
|
|
|
+ function setRunner(element, runner) {
|
|
|
+ element.data(RUNNER_STORAGE_KEY, runner);
|
|
|
+ }
|
|
|
+
|
|
|
+ function removeRunner(element) {
|
|
|
+ element.removeData(RUNNER_STORAGE_KEY);
|
|
|
+ }
|
|
|
+
|
|
|
+ function getRunner(element) {
|
|
|
+ return element.data(RUNNER_STORAGE_KEY);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.$get = ['$$jqLite', '$rootScope', '$injector', '$$AnimateRunner', '$$HashMap', '$$rAFScheduler',
|
|
|
+ function($$jqLite, $rootScope, $injector, $$AnimateRunner, $$HashMap, $$rAFScheduler) {
|
|
|
+
|
|
|
+ var animationQueue = [];
|
|
|
+ var applyAnimationClasses = applyAnimationClassesFactory($$jqLite);
|
|
|
+
|
|
|
+ function sortAnimations(animations) {
|
|
|
+ var tree = { children: [] };
|
|
|
+ var i, lookup = new $$HashMap();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ for (i = 0; i < animations.length; i++) {
|
|
|
+ var animation = animations[i];
|
|
|
+ lookup.put(animation.domNode, animations[i] = {
|
|
|
+ domNode: animation.domNode,
|
|
|
+ fn: animation.fn,
|
|
|
+ children: []
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ for (i = 0; i < animations.length; i++) {
|
|
|
+ processNode(animations[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ return flatten(tree);
|
|
|
+
|
|
|
+ function processNode(entry) {
|
|
|
+ if (entry.processed) return entry;
|
|
|
+ entry.processed = true;
|
|
|
+
|
|
|
+ var elementNode = entry.domNode;
|
|
|
+ var parentNode = elementNode.parentNode;
|
|
|
+ lookup.put(elementNode, entry);
|
|
|
+
|
|
|
+ var parentEntry;
|
|
|
+ while (parentNode) {
|
|
|
+ parentEntry = lookup.get(parentNode);
|
|
|
+ if (parentEntry) {
|
|
|
+ if (!parentEntry.processed) {
|
|
|
+ parentEntry = processNode(parentEntry);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ parentNode = parentNode.parentNode;
|
|
|
+ }
|
|
|
+
|
|
|
+ (parentEntry || tree).children.push(entry);
|
|
|
+ return entry;
|
|
|
+ }
|
|
|
+
|
|
|
+ function flatten(tree) {
|
|
|
+ var result = [];
|
|
|
+ var queue = [];
|
|
|
+ var i;
|
|
|
+
|
|
|
+ for (i = 0; i < tree.children.length; i++) {
|
|
|
+ queue.push(tree.children[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ var remainingLevelEntries = queue.length;
|
|
|
+ var nextLevelEntries = 0;
|
|
|
+ var row = [];
|
|
|
+
|
|
|
+ for (i = 0; i < queue.length; i++) {
|
|
|
+ var entry = queue[i];
|
|
|
+ if (remainingLevelEntries <= 0) {
|
|
|
+ remainingLevelEntries = nextLevelEntries;
|
|
|
+ nextLevelEntries = 0;
|
|
|
+ result.push(row);
|
|
|
+ row = [];
|
|
|
+ }
|
|
|
+ row.push(entry.fn);
|
|
|
+ entry.children.forEach(function(childEntry) {
|
|
|
+ nextLevelEntries++;
|
|
|
+ queue.push(childEntry);
|
|
|
+ });
|
|
|
+ remainingLevelEntries--;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (row.length) {
|
|
|
+ result.push(row);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return function(element, event, options) {
|
|
|
+ options = prepareAnimationOptions(options);
|
|
|
+ var isStructural = ['enter', 'move', 'leave'].indexOf(event) >= 0;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var runner = new $$AnimateRunner({
|
|
|
+ end: function() { close(); },
|
|
|
+ cancel: function() { close(true); }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (!drivers.length) {
|
|
|
+ close();
|
|
|
+ return runner;
|
|
|
+ }
|
|
|
+
|
|
|
+ setRunner(element, runner);
|
|
|
+
|
|
|
+ var classes = mergeClasses(element.attr('class'), mergeClasses(options.addClass, options.removeClass));
|
|
|
+ var tempClasses = options.tempClasses;
|
|
|
+ if (tempClasses) {
|
|
|
+ classes += ' ' + tempClasses;
|
|
|
+ options.tempClasses = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ var prepareClassName;
|
|
|
+ if (isStructural) {
|
|
|
+ prepareClassName = 'ng-' + event + PREPARE_CLASS_SUFFIX;
|
|
|
+ $$jqLite.addClass(element, prepareClassName);
|
|
|
+ }
|
|
|
+
|
|
|
+ animationQueue.push({
|
|
|
+
|
|
|
+
|
|
|
+ element: element,
|
|
|
+ classes: classes,
|
|
|
+ event: event,
|
|
|
+ structural: isStructural,
|
|
|
+ options: options,
|
|
|
+ beforeStart: beforeStart,
|
|
|
+ close: close
|
|
|
+ });
|
|
|
+
|
|
|
+ element.on('$destroy', handleDestroyedElement);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (animationQueue.length > 1) return runner;
|
|
|
+
|
|
|
+ $rootScope.$$postDigest(function() {
|
|
|
+ var animations = [];
|
|
|
+ forEach(animationQueue, function(entry) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (getRunner(entry.element)) {
|
|
|
+ animations.push(entry);
|
|
|
+ } else {
|
|
|
+ entry.close();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ animationQueue.length = 0;
|
|
|
+
|
|
|
+ var groupedAnimations = groupAnimations(animations);
|
|
|
+ var toBeSortedAnimations = [];
|
|
|
+
|
|
|
+ forEach(groupedAnimations, function(animationEntry) {
|
|
|
+ toBeSortedAnimations.push({
|
|
|
+ domNode: getDomNode(animationEntry.from ? animationEntry.from.element : animationEntry.element),
|
|
|
+ fn: function triggerAnimationStart() {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ animationEntry.beforeStart();
|
|
|
+
|
|
|
+ var startAnimationFn, closeFn = animationEntry.close;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ var targetElement = animationEntry.anchors
|
|
|
+ ? (animationEntry.from.element || animationEntry.to.element)
|
|
|
+ : animationEntry.element;
|
|
|
+
|
|
|
+ if (getRunner(targetElement)) {
|
|
|
+ var operation = invokeFirstDriver(animationEntry);
|
|
|
+ if (operation) {
|
|
|
+ startAnimationFn = operation.start;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!startAnimationFn) {
|
|
|
+ closeFn();
|
|
|
+ } else {
|
|
|
+ var animationRunner = startAnimationFn();
|
|
|
+ animationRunner.done(function(status) {
|
|
|
+ closeFn(!status);
|
|
|
+ });
|
|
|
+ updateAnimationRunners(animationEntry, animationRunner);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $$rAFScheduler(sortAnimations(toBeSortedAnimations));
|
|
|
+ });
|
|
|
+
|
|
|
+ return runner;
|
|
|
+
|
|
|
+
|
|
|
+ function getAnchorNodes(node) {
|
|
|
+ var SELECTOR = '[' + NG_ANIMATE_REF_ATTR + ']';
|
|
|
+ var items = node.hasAttribute(NG_ANIMATE_REF_ATTR)
|
|
|
+ ? [node]
|
|
|
+ : node.querySelectorAll(SELECTOR);
|
|
|
+ var anchors = [];
|
|
|
+ forEach(items, function(node) {
|
|
|
+ var attr = node.getAttribute(NG_ANIMATE_REF_ATTR);
|
|
|
+ if (attr && attr.length) {
|
|
|
+ anchors.push(node);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return anchors;
|
|
|
+ }
|
|
|
+
|
|
|
+ function groupAnimations(animations) {
|
|
|
+ var preparedAnimations = [];
|
|
|
+ var refLookup = {};
|
|
|
+ forEach(animations, function(animation, index) {
|
|
|
+ var element = animation.element;
|
|
|
+ var node = getDomNode(element);
|
|
|
+ var event = animation.event;
|
|
|
+ var enterOrMove = ['enter', 'move'].indexOf(event) >= 0;
|
|
|
+ var anchorNodes = animation.structural ? getAnchorNodes(node) : [];
|
|
|
+
|
|
|
+ if (anchorNodes.length) {
|
|
|
+ var direction = enterOrMove ? 'to' : 'from';
|
|
|
+
|
|
|
+ forEach(anchorNodes, function(anchor) {
|
|
|
+ var key = anchor.getAttribute(NG_ANIMATE_REF_ATTR);
|
|
|
+ refLookup[key] = refLookup[key] || {};
|
|
|
+ refLookup[key][direction] = {
|
|
|
+ animationID: index,
|
|
|
+ element: jqLite(anchor)
|
|
|
+ };
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ preparedAnimations.push(animation);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ var usedIndicesLookup = {};
|
|
|
+ var anchorGroups = {};
|
|
|
+ forEach(refLookup, function(operations, key) {
|
|
|
+ var from = operations.from;
|
|
|
+ var to = operations.to;
|
|
|
+
|
|
|
+ if (!from || !to) {
|
|
|
+
|
|
|
+
|
|
|
+ var index = from ? from.animationID : to.animationID;
|
|
|
+ var indexKey = index.toString();
|
|
|
+ if (!usedIndicesLookup[indexKey]) {
|
|
|
+ usedIndicesLookup[indexKey] = true;
|
|
|
+ preparedAnimations.push(animations[index]);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var fromAnimation = animations[from.animationID];
|
|
|
+ var toAnimation = animations[to.animationID];
|
|
|
+ var lookupKey = from.animationID.toString();
|
|
|
+ if (!anchorGroups[lookupKey]) {
|
|
|
+ var group = anchorGroups[lookupKey] = {
|
|
|
+ structural: true,
|
|
|
+ beforeStart: function() {
|
|
|
+ fromAnimation.beforeStart();
|
|
|
+ toAnimation.beforeStart();
|
|
|
+ },
|
|
|
+ close: function() {
|
|
|
+ fromAnimation.close();
|
|
|
+ toAnimation.close();
|
|
|
+ },
|
|
|
+ classes: cssClassesIntersection(fromAnimation.classes, toAnimation.classes),
|
|
|
+ from: fromAnimation,
|
|
|
+ to: toAnimation,
|
|
|
+ anchors: []
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (group.classes.length) {
|
|
|
+ preparedAnimations.push(group);
|
|
|
+ } else {
|
|
|
+ preparedAnimations.push(fromAnimation);
|
|
|
+ preparedAnimations.push(toAnimation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ anchorGroups[lookupKey].anchors.push({
|
|
|
+ 'out': from.element, 'in': to.element
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ return preparedAnimations;
|
|
|
+ }
|
|
|
+
|
|
|
+ function cssClassesIntersection(a,b) {
|
|
|
+ a = a.split(' ');
|
|
|
+ b = b.split(' ');
|
|
|
+ var matches = [];
|
|
|
+
|
|
|
+ for (var i = 0; i < a.length; i++) {
|
|
|
+ var aa = a[i];
|
|
|
+ if (aa.substring(0,3) === 'ng-') continue;
|
|
|
+
|
|
|
+ for (var j = 0; j < b.length; j++) {
|
|
|
+ if (aa === b[j]) {
|
|
|
+ matches.push(aa);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return matches.join(' ');
|
|
|
+ }
|
|
|
+
|
|
|
+ function invokeFirstDriver(animationDetails) {
|
|
|
+
|
|
|
+
|
|
|
+ for (var i = drivers.length - 1; i >= 0; i--) {
|
|
|
+ var driverName = drivers[i];
|
|
|
+ if (!$injector.has(driverName)) continue;
|
|
|
+
|
|
|
+ var factory = $injector.get(driverName);
|
|
|
+ var driver = factory(animationDetails);
|
|
|
+ if (driver) {
|
|
|
+ return driver;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function beforeStart() {
|
|
|
+ element.addClass(NG_ANIMATE_CLASSNAME);
|
|
|
+ if (tempClasses) {
|
|
|
+ $$jqLite.addClass(element, tempClasses);
|
|
|
+ }
|
|
|
+ if (prepareClassName) {
|
|
|
+ $$jqLite.removeClass(element, prepareClassName);
|
|
|
+ prepareClassName = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function updateAnimationRunners(animation, newRunner) {
|
|
|
+ if (animation.from && animation.to) {
|
|
|
+ update(animation.from.element);
|
|
|
+ update(animation.to.element);
|
|
|
+ } else {
|
|
|
+ update(animation.element);
|
|
|
+ }
|
|
|
+
|
|
|
+ function update(element) {
|
|
|
+ getRunner(element).setHost(newRunner);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function handleDestroyedElement() {
|
|
|
+ var runner = getRunner(element);
|
|
|
+ if (runner && (event !== 'leave' || !options.$$domOperationFired)) {
|
|
|
+ runner.end();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function close(rejected) {
|
|
|
+ element.off('$destroy', handleDestroyedElement);
|
|
|
+ removeRunner(element);
|
|
|
+
|
|
|
+ applyAnimationClasses(element, options);
|
|
|
+ applyAnimationStyles(element, options);
|
|
|
+ options.domOperation();
|
|
|
+
|
|
|
+ if (tempClasses) {
|
|
|
+ $$jqLite.removeClass(element, tempClasses);
|
|
|
+ }
|
|
|
+
|
|
|
+ element.removeClass(NG_ANIMATE_CLASSNAME);
|
|
|
+ runner.complete(!rejected);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }];
|
|
|
+}];
|
|
|
+
|
|
|
+
|
|
|
+ * @ngdoc directive
|
|
|
+ * @name ngAnimateSwap
|
|
|
+ * @restrict A
|
|
|
+ * @scope
|
|
|
+ *
|
|
|
+ * @description
|
|
|
+ *
|
|
|
+ * ngAnimateSwap is a animation-oriented directive that allows for the container to
|
|
|
+ * be removed and entered in whenever the associated expression changes. A
|
|
|
+ * common usecase for this directive is a rotating banner or slider component which
|
|
|
+ * contains one image being present at a time. When the active image changes
|
|
|
+ * then the old image will perform a `leave` animation and the new element
|
|
|
+ * will be inserted via an `enter` animation.
|
|
|
+ *
|
|
|
+ * @animations
|
|
|
+ * | Animation | Occurs |
|
|
|
+ * |----------------------------------|--------------------------------------|
|
|
|
+ * | {@link ng.$animate#enter enter} | when the new element is inserted to the DOM |
|
|
|
+ * | {@link ng.$animate#leave leave} | when the old element is removed from the DOM |
|
|
|
+ *
|
|
|
+ * @example
|
|
|
+ * <example name="ngAnimateSwap-directive" module="ngAnimateSwapExample"
|
|
|
+ * deps="angular-animate.js"
|
|
|
+ * animations="true" fixBase="true">
|
|
|
+ * <file name="index.html">
|
|
|
+ * <div class="container" ng-controller="AppCtrl">
|
|
|
+ * <div ng-animate-swap="number" class="cell swap-animation" ng-class="colorClass(number)">
|
|
|
+ * {{ number }}
|
|
|
+ * </div>
|
|
|
+ * </div>
|
|
|
+ * </file>
|
|
|
+ * <file name="script.js">
|
|
|
+ * angular.module('ngAnimateSwapExample', ['ngAnimate'])
|
|
|
+ * .controller('AppCtrl', ['$scope', '$interval', function($scope, $interval) {
|
|
|
+ * $scope.number = 0;
|
|
|
+ * $interval(function() {
|
|
|
+ * $scope.number++;
|
|
|
+ * }, 1000);
|
|
|
+ *
|
|
|
+ * var colors = ['red','blue','green','yellow','orange'];
|
|
|
+ * $scope.colorClass = function(number) {
|
|
|
+ * return colors[number % colors.length];
|
|
|
+ * };
|
|
|
+ * }]);
|
|
|
+ * </file>
|
|
|
+ * <file name="animations.css">
|
|
|
+ * .container {
|
|
|
+ * height:250px;
|
|
|
+ * width:250px;
|
|
|
+ * position:relative;
|
|
|
+ * overflow:hidden;
|
|
|
+ * border:2px solid black;
|
|
|
+ * }
|
|
|
+ * .container .cell {
|
|
|
+ * font-size:150px;
|
|
|
+ * text-align:center;
|
|
|
+ * line-height:250px;
|
|
|
+ * position:absolute;
|
|
|
+ * top:0;
|
|
|
+ * left:0;
|
|
|
+ * right:0;
|
|
|
+ * border-bottom:2px solid black;
|
|
|
+ * }
|
|
|
+ * .swap-animation.ng-enter, .swap-animation.ng-leave {
|
|
|
+ * transition:0.5s linear all;
|
|
|
+ * }
|
|
|
+ * .swap-animation.ng-enter {
|
|
|
+ * top:-250px;
|
|
|
+ * }
|
|
|
+ * .swap-animation.ng-enter-active {
|
|
|
+ * top:0px;
|
|
|
+ * }
|
|
|
+ * .swap-animation.ng-leave {
|
|
|
+ * top:0px;
|
|
|
+ * }
|
|
|
+ * .swap-animation.ng-leave-active {
|
|
|
+ * top:250px;
|
|
|
+ * }
|
|
|
+ * .red { background:red; }
|
|
|
+ * .green { background:green; }
|
|
|
+ * .blue { background:blue; }
|
|
|
+ * .yellow { background:yellow; }
|
|
|
+ * .orange { background:orange; }
|
|
|
+ * </file>
|
|
|
+ * </example>
|
|
|
+ */
|
|
|
+var ngAnimateSwapDirective = ['$animate', '$rootScope', function($animate, $rootScope) {
|
|
|
+ return {
|
|
|
+ restrict: 'A',
|
|
|
+ transclude: 'element',
|
|
|
+ terminal: true,
|
|
|
+ priority: 600,
|
|
|
+ link: function(scope, $element, attrs, ctrl, $transclude) {
|
|
|
+ var previousElement, previousScope;
|
|
|
+ scope.$watchCollection(attrs.ngAnimateSwap || attrs['for'], function(value) {
|
|
|
+ if (previousElement) {
|
|
|
+ $animate.leave(previousElement);
|
|
|
+ }
|
|
|
+ if (previousScope) {
|
|
|
+ previousScope.$destroy();
|
|
|
+ previousScope = null;
|
|
|
+ }
|
|
|
+ if (value || value === 0) {
|
|
|
+ previousScope = scope.$new();
|
|
|
+ $transclude(previousScope, function(element) {
|
|
|
+ previousElement = element;
|
|
|
+ $animate.enter(element, null, $element);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+}];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ ngAnimateSwapDirective,
|
|
|
+ $$AnimateAsyncRunFactory,
|
|
|
+ $$rAFSchedulerFactory,
|
|
|
+ $$AnimateChildrenDirective,
|
|
|
+ $$AnimateQueueProvider,
|
|
|
+ $$AnimationProvider,
|
|
|
+ $AnimateCssProvider,
|
|
|
+ $$AnimateCssDriverProvider,
|
|
|
+ $$AnimateJsProvider,
|
|
|
+ $$AnimateJsDriverProvider,
|
|
|
+*/
|
|
|
+
|
|
|
+
|
|
|
+ * @ngdoc module
|
|
|
+ * @name ngAnimate
|
|
|
+ * @description
|
|
|
+ *
|
|
|
+ * The `ngAnimate` module provides support for CSS-based animations (keyframes and transitions) as well as JavaScript-based animations via
|
|
|
+ * callback hooks. Animations are not enabled by default, however, by including `ngAnimate` the animation hooks are enabled for an Angular app.
|
|
|
+ *
|
|
|
+ * <div doc-module-components="ngAnimate"></div>
|
|
|
+ *
|
|
|
+ * # Usage
|
|
|
+ * 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
|
|
|
+ * using CSS (by using matching CSS selectors/styles) and the latter triggers animations that are registered via `module.animation()`. For
|
|
|
+ * both CSS and JS animations the sole requirement is to have a matching `CSS class` that exists both in the registered animation and within
|
|
|
+ * the HTML element that the animation will be triggered on.
|
|
|
+ *
|
|
|
+ * ## Directive Support
|
|
|
+ * The following directives are "animation aware":
|
|
|
+ *
|
|
|
+ * | Directive | Supported Animations |
|
|
|
+ * |----------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------|
|
|
|
+ * | {@link ng.directive:ngRepeat#animations ngRepeat} | enter, leave and move |
|
|
|
+ * | {@link ngRoute.directive:ngView#animations ngView} | enter and leave |
|
|
|
+ * | {@link ng.directive:ngInclude#animations ngInclude} | enter and leave |
|
|
|
+ * | {@link ng.directive:ngSwitch#animations ngSwitch} | enter and leave |
|
|
|
+ * | {@link ng.directive:ngIf#animations ngIf} | enter and leave |
|
|
|
+ * | {@link ng.directive:ngClass#animations ngClass} | add and remove (the CSS class(es) present) |
|
|
|
+ * | {@link ng.directive:ngShow#animations ngShow} & {@link ng.directive:ngHide#animations ngHide} | add and remove (the ng-hide class value) |
|
|
|
+ * | {@link ng.directive:form#animation-hooks form} & {@link ng.directive:ngModel#animation-hooks ngModel} | add and remove (dirty, pristine, valid, invalid & all other validations) |
|
|
|
+ * | {@link module:ngMessages#animations ngMessages} | add and remove (ng-active & ng-inactive) |
|
|
|
+ * | {@link module:ngMessages#animations ngMessage} | enter and leave |
|
|
|
+ *
|
|
|
+ * (More information can be found by visiting each the documentation associated with each directive.)
|
|
|
+ *
|
|
|
+ * ## CSS-based Animations
|
|
|
+ *
|
|
|
+ * 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
|
|
|
+ * and CSS code we can create an animation that will be picked up by Angular when an the underlying directive performs an operation.
|
|
|
+ *
|
|
|
+ * The example below shows how an `enter` animation can be made possible on an element using `ng-if`:
|
|
|
+ *
|
|
|
+ * ```html
|
|
|
+ * <div ng-if="bool" class="fade">
|
|
|
+ * Fade me in out
|
|
|
+ * </div>
|
|
|
+ * <button ng-click="bool=true">Fade In!</button>
|
|
|
+ * <button ng-click="bool=false">Fade Out!</button>
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * Notice the CSS class **fade**? We can now create the CSS transition code that references this class:
|
|
|
+ *
|
|
|
+ * ```css
|
|
|
+ * /* The starting CSS styles for the enter animation */
|
|
|
+ * .fade.ng-enter {
|
|
|
+ * transition:0.5s linear all;
|
|
|
+ * opacity:0;
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * /* The finishing CSS styles for the enter animation */
|
|
|
+ * .fade.ng-enter.ng-enter-active {
|
|
|
+ * opacity:1;
|
|
|
+ * }
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * 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
|
|
|
+ * 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
|
|
|
+ * code **must** be defined within the starting CSS class (in this case `.ng-enter`). The destination class is what the transition will animate towards.
|
|
|
+ *
|
|
|
+ * 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:
|
|
|
+ *
|
|
|
+ * ```css
|
|
|
+ * /* now the element will fade out before it is removed from the DOM */
|
|
|
+ * .fade.ng-leave {
|
|
|
+ * transition:0.5s linear all;
|
|
|
+ * opacity:1;
|
|
|
+ * }
|
|
|
+ * .fade.ng-leave.ng-leave-active {
|
|
|
+ * opacity:0;
|
|
|
+ * }
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * We can also make use of **CSS Keyframes** by referencing the keyframe animation within the starting CSS class:
|
|
|
+ *
|
|
|
+ * ```css
|
|
|
+ * /* there is no need to define anything inside of the destination
|
|
|
+ * CSS class since the keyframe will take charge of the animation */
|
|
|
+ * .fade.ng-leave {
|
|
|
+ * animation: my_fade_animation 0.5s linear;
|
|
|
+ * -webkit-animation: my_fade_animation 0.5s linear;
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * @keyframes my_fade_animation {
|
|
|
+ * from { opacity:1; }
|
|
|
+ * to { opacity:0; }
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * @-webkit-keyframes my_fade_animation {
|
|
|
+ * from { opacity:1; }
|
|
|
+ * to { opacity:0; }
|
|
|
+ * }
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * Feel free also mix transitions and keyframes together as well as any other CSS classes on the same element.
|
|
|
+ *
|
|
|
+ * ### CSS Class-based Animations
|
|
|
+ *
|
|
|
+ * Class-based animations (animations that are triggered via `ngClass`, `ngShow`, `ngHide` and some other directives) have a slightly different
|
|
|
+ * naming convention. Class-based animations are basic enough that a standard transition or keyframe can be referenced on the class being added
|
|
|
+ * and removed.
|
|
|
+ *
|
|
|
+ * For example if we wanted to do a CSS animation for `ngHide` then we place an animation on the `.ng-hide` CSS class:
|
|
|
+ *
|
|
|
+ * ```html
|
|
|
+ * <div ng-show="bool" class="fade">
|
|
|
+ * Show and hide me
|
|
|
+ * </div>
|
|
|
+ * <button ng-click="bool=true">Toggle</button>
|
|
|
+ *
|
|
|
+ * <style>
|
|
|
+ * .fade.ng-hide {
|
|
|
+ * transition:0.5s linear all;
|
|
|
+ * opacity:0;
|
|
|
+ * }
|
|
|
+ * </style>
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * 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
|
|
|
+ * ngShow and ngHide are animation aware then we can match up a transition and ngAnimate handles the rest.
|
|
|
+ *
|
|
|
+ * 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
|
|
|
+ * with CSS styles.
|
|
|
+ *
|
|
|
+ * ```html
|
|
|
+ * <div ng-class="{on:onOff}" class="highlight">
|
|
|
+ * Highlight this box
|
|
|
+ * </div>
|
|
|
+ * <button ng-click="onOff=!onOff">Toggle</button>
|
|
|
+ *
|
|
|
+ * <style>
|
|
|
+ * .highlight {
|
|
|
+ * transition:0.5s linear all;
|
|
|
+ * }
|
|
|
+ * .highlight.on-add {
|
|
|
+ * background:white;
|
|
|
+ * }
|
|
|
+ * .highlight.on {
|
|
|
+ * background:yellow;
|
|
|
+ * }
|
|
|
+ * .highlight.on-remove {
|
|
|
+ * background:black;
|
|
|
+ * }
|
|
|
+ * </style>
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * We can also make use of CSS keyframes by placing them within the CSS classes.
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * ### CSS Staggering Animations
|
|
|
+ * A Staggering animation is a collection of animations that are issued with a slight delay in between each successive operation resulting in a
|
|
|
+ * curtain-like effect. The ngAnimate module (versions >=1.2) supports staggering animations and the stagger effect can be
|
|
|
+ * performed by creating a **ng-EVENT-stagger** CSS class and attaching that class to the base CSS class used for
|
|
|
+ * the animation. The style property expected within the stagger class can either be a **transition-delay** or an
|
|
|
+ * **animation-delay** property (or both if your animation contains both transitions and keyframe animations).
|
|
|
+ *
|
|
|
+ * ```css
|
|
|
+ * .my-animation.ng-enter {
|
|
|
+ * /* standard transition code */
|
|
|
+ * transition: 1s linear all;
|
|
|
+ * opacity:0;
|
|
|
+ * }
|
|
|
+ * .my-animation.ng-enter-stagger {
|
|
|
+ * /* this will have a 100ms delay between each successive leave animation */
|
|
|
+ * transition-delay: 0.1s;
|
|
|
+ *
|
|
|
+ * /* As of 1.4.4, this must always be set: it signals ngAnimate
|
|
|
+ * to not accidentally inherit a delay property from another CSS class */
|
|
|
+ * transition-duration: 0s;
|
|
|
+ * }
|
|
|
+ * .my-animation.ng-enter.ng-enter-active {
|
|
|
+ * /* standard transition styles */
|
|
|
+ * opacity:1;
|
|
|
+ * }
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * Staggering animations work by default in ngRepeat (so long as the CSS class is defined). Outside of ngRepeat, to use staggering animations
|
|
|
+ * on your own, they can be triggered by firing multiple calls to the same event on $animate. However, the restrictions surrounding this
|
|
|
+ * are that each of the elements must have the same CSS className value as well as the same parent element. A stagger operation
|
|
|
+ * will also be reset if one or more animation frames have passed since the multiple calls to `$animate` were fired.
|
|
|
+ *
|
|
|
+ * The following code will issue the **ng-leave-stagger** event on the element provided:
|
|
|
+ *
|
|
|
+ * ```js
|
|
|
+ * var kids = parent.children();
|
|
|
+ *
|
|
|
+ * $animate.leave(kids[0]);
|
|
|
+ * $animate.leave(kids[1]);
|
|
|
+ * $animate.leave(kids[2]);
|
|
|
+ * $animate.leave(kids[3]);
|
|
|
+ * $animate.leave(kids[4]);
|
|
|
+ *
|
|
|
+ * window.requestAnimationFrame(function() {
|
|
|
+ *
|
|
|
+ * $animate.leave(kids[5]);
|
|
|
+ * $animate.leave(kids[6]);
|
|
|
+ *
|
|
|
+ * $scope.$digest();
|
|
|
+ * });
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * Stagger animations are currently only supported within CSS-defined animations.
|
|
|
+ *
|
|
|
+ * ### The `ng-animate` CSS class
|
|
|
+ *
|
|
|
+ * When ngAnimate is animating an element it will apply the `ng-animate` CSS class to the element for the duration of the animation.
|
|
|
+ * This is a temporary CSS class and it will be removed once the animation is over (for both JavaScript and CSS-based animations).
|
|
|
+ *
|
|
|
+ * Therefore, animations can be applied to an element using this temporary class directly via CSS.
|
|
|
+ *
|
|
|
+ * ```css
|
|
|
+ * .zipper.ng-animate {
|
|
|
+ * transition:0.5s linear all;
|
|
|
+ * }
|
|
|
+ * .zipper.ng-enter {
|
|
|
+ * opacity:0;
|
|
|
+ * }
|
|
|
+ * .zipper.ng-enter.ng-enter-active {
|
|
|
+ * opacity:1;
|
|
|
+ * }
|
|
|
+ * .zipper.ng-leave {
|
|
|
+ * opacity:1;
|
|
|
+ * }
|
|
|
+ * .zipper.ng-leave.ng-leave-active {
|
|
|
+ * opacity:0;
|
|
|
+ * }
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * (Note that the `ng-animate` CSS class is reserved and it cannot be applied on an element directly since ngAnimate will always remove
|
|
|
+ * the CSS class once an animation has completed.)
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * ### The `ng-[event]-prepare` class
|
|
|
+ *
|
|
|
+ * This is a special class that can be used to prevent unwanted flickering / flash of content before
|
|
|
+ * the actual animation starts. The class is added as soon as an animation is initialized, but removed
|
|
|
+ * before the actual animation starts (after waiting for a $digest).
|
|
|
+ * It is also only added for *structural* animations (`enter`, `move`, and `leave`).
|
|
|
+ *
|
|
|
+ * In practice, flickering can appear when nesting elements with structural animations such as `ngIf`
|
|
|
+ * into elements that have class-based animations such as `ngClass`.
|
|
|
+ *
|
|
|
+ * ```html
|
|
|
+ * <div ng-class="{red: myProp}">
|
|
|
+ * <div ng-class="{blue: myProp}">
|
|
|
+ * <div class="message" ng-if="myProp"></div>
|
|
|
+ * </div>
|
|
|
+ * </div>
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * It is possible that during the `enter` animation, the `.message` div will be briefly visible before it starts animating.
|
|
|
+ * In that case, you can add styles to the CSS that make sure the element stays hidden before the animation starts:
|
|
|
+ *
|
|
|
+ * ```css
|
|
|
+ * .message.ng-enter-prepare {
|
|
|
+ * opacity: 0;
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * ## JavaScript-based Animations
|
|
|
+ *
|
|
|
+ * ngAnimate also allows for animations to be consumed by JavaScript code. The approach is similar to CSS-based animations (where there is a shared
|
|
|
+ * 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
|
|
|
+ * `module.animation()` module function we can register the animation.
|
|
|
+ *
|
|
|
+ * Let's see an example of a enter/leave animation using `ngRepeat`:
|
|
|
+ *
|
|
|
+ * ```html
|
|
|
+ * <div ng-repeat="item in items" class="slide">
|
|
|
+ * {{ item }}
|
|
|
+ * </div>
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * 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`:
|
|
|
+ *
|
|
|
+ * ```js
|
|
|
+ * myModule.animation('.slide', [function() {
|
|
|
+ * return {
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * enter: function(element, doneFn) {
|
|
|
+ * jQuery(element).fadeIn(1000, doneFn);
|
|
|
+ *
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * },
|
|
|
+ *
|
|
|
+ * move: function(element, doneFn) {
|
|
|
+ * jQuery(element).fadeIn(1000, doneFn);
|
|
|
+ * },
|
|
|
+ *
|
|
|
+ * leave: function(element, doneFn) {
|
|
|
+ * jQuery(element).fadeOut(1000, doneFn);
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * }]);
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * The nice thing about JS-based animations is that we can inject other services and make use of advanced animation libraries such as
|
|
|
+ * greensock.js and velocity.js.
|
|
|
+ *
|
|
|
+ * If our animation code class-based (meaning that something like `ngClass`, `ngHide` and `ngShow` triggers it) then we can still define
|
|
|
+ * our animations inside of the same registered animation, however, the function input arguments are a bit different:
|
|
|
+ *
|
|
|
+ * ```html
|
|
|
+ * <div ng-class="color" class="colorful">
|
|
|
+ * this box is moody
|
|
|
+ * </div>
|
|
|
+ * <button ng-click="color='red'">Change to red</button>
|
|
|
+ * <button ng-click="color='blue'">Change to blue</button>
|
|
|
+ * <button ng-click="color='green'">Change to green</button>
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * ```js
|
|
|
+ * myModule.animation('.colorful', [function() {
|
|
|
+ * return {
|
|
|
+ * addClass: function(element, className, doneFn) {
|
|
|
+ *
|
|
|
+ * },
|
|
|
+ * removeClass: function(element, className, doneFn) {
|
|
|
+ *
|
|
|
+ * },
|
|
|
+ * setClass: function(element, addedClass, removedClass, doneFn) {
|
|
|
+ *
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * }]);
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * ## CSS + JS Animations Together
|
|
|
+ *
|
|
|
+ * 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,
|
|
|
+ * defining CSS and JS animations to work off of the same CSS class will not work anymore. Therefore the example below will only result in **JS animations taking
|
|
|
+ * charge of the animation**:
|
|
|
+ *
|
|
|
+ * ```html
|
|
|
+ * <div ng-if="bool" class="slide">
|
|
|
+ * Slide in and out
|
|
|
+ * </div>
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * ```js
|
|
|
+ * myModule.animation('.slide', [function() {
|
|
|
+ * return {
|
|
|
+ * enter: function(element, doneFn) {
|
|
|
+ * jQuery(element).slideIn(1000, doneFn);
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * }]);
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * ```css
|
|
|
+ * .slide.ng-enter {
|
|
|
+ * transition:0.5s linear all;
|
|
|
+ * transform:translateY(-100px);
|
|
|
+ * }
|
|
|
+ * .slide.ng-enter.ng-enter-active {
|
|
|
+ * transform:translateY(0);
|
|
|
+ * }
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * Does this mean that CSS and JS animations cannot be used together? Do JS-based animations always have higher priority? We can make up for the
|
|
|
+ * lack of CSS animations by using the `$animateCss` service to trigger our own tweaked-out, CSS-based animations directly from
|
|
|
+ * our own JS-based animation code:
|
|
|
+ *
|
|
|
+ * ```js
|
|
|
+ * myModule.animation('.slide', ['$animateCss', function($animateCss) {
|
|
|
+ * return {
|
|
|
+ * enter: function(element) {
|
|
|
+*
|
|
|
+ * return $animateCss(element, {
|
|
|
+ * event: 'enter',
|
|
|
+ * structural: true
|
|
|
+ * });
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * }]);
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * 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.
|
|
|
+ *
|
|
|
+ * 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
|
|
|
+ * 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
|
|
|
+ * data into `$animateCss` directly:
|
|
|
+ *
|
|
|
+ * ```js
|
|
|
+ * myModule.animation('.slide', ['$animateCss', function($animateCss) {
|
|
|
+ * return {
|
|
|
+ * enter: function(element) {
|
|
|
+ * return $animateCss(element, {
|
|
|
+ * event: 'enter',
|
|
|
+ * structural: true,
|
|
|
+ * addClass: 'maroon-setting',
|
|
|
+ * from: { height:0 },
|
|
|
+ * to: { height: 200 }
|
|
|
+ * });
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * }]);
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * Now we can fill in the rest via our transition CSS code:
|
|
|
+ *
|
|
|
+ * ```css
|
|
|
+ * /* the transition tells ngAnimate to make the animation happen */
|
|
|
+ * .slide.ng-enter { transition:0.5s linear all; }
|
|
|
+ *
|
|
|
+ * /* this extra CSS class will be absorbed into the transition
|
|
|
+ * since the $animateCss code is adding the class */
|
|
|
+ * .maroon-setting { background:red; }
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * 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.
|
|
|
+ *
|
|
|
+ * To learn more about what's possible be sure to visit the {@link ngAnimate.$animateCss $animateCss service}.
|
|
|
+ *
|
|
|
+ * ## Animation Anchoring (via `ng-animate-ref`)
|
|
|
+ *
|
|
|
+ * ngAnimate in AngularJS 1.4 comes packed with the ability to cross-animate elements between
|
|
|
+ * structural areas of an application (like views) by pairing up elements using an attribute
|
|
|
+ * called `ng-animate-ref`.
|
|
|
+ *
|
|
|
+ * Let's say for example we have two views that are managed by `ng-view` and we want to show
|
|
|
+ * that there is a relationship between two components situated in within these views. By using the
|
|
|
+ * `ng-animate-ref` attribute we can identify that the two components are paired together and we
|
|
|
+ * can then attach an animation, which is triggered when the view changes.
|
|
|
+ *
|
|
|
+ * Say for example we have the following template code:
|
|
|
+ *
|
|
|
+ * ```html
|
|
|
+ * <!-- index.html -->
|
|
|
+ * <div ng-view class="view-animation">
|
|
|
+ * </div>
|
|
|
+ *
|
|
|
+ * <!-- home.html -->
|
|
|
+ * <a href="#/banner-page">
|
|
|
+ * <img src="./banner.jpg" class="banner" ng-animate-ref="banner">
|
|
|
+ * </a>
|
|
|
+ *
|
|
|
+ * <!-- banner-page.html -->
|
|
|
+ * <img src="./banner.jpg" class="banner" ng-animate-ref="banner">
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * Now, when the view changes (once the link is clicked), ngAnimate will examine the
|
|
|
+ * HTML contents to see if there is a match reference between any components in the view
|
|
|
+ * that is leaving and the view that is entering. It will scan both the view which is being
|
|
|
+ * removed (leave) and inserted (enter) to see if there are any paired DOM elements that
|
|
|
+ * contain a matching ref value.
|
|
|
+ *
|
|
|
+ * The two images match since they share the same ref value. ngAnimate will now create a
|
|
|
+ * transport element (which is a clone of the first image element) and it will then attempt
|
|
|
+ * to animate to the position of the second image element in the next view. For the animation to
|
|
|
+ * work a special CSS class called `ng-anchor` will be added to the transported element.
|
|
|
+ *
|
|
|
+ * We can now attach a transition onto the `.banner.ng-anchor` CSS class and then
|
|
|
+ * ngAnimate will handle the entire transition for us as well as the addition and removal of
|
|
|
+ * any changes of CSS classes between the elements:
|
|
|
+ *
|
|
|
+ * ```css
|
|
|
+ * .banner.ng-anchor {
|
|
|
+ * /* this animation will last for 1 second since there are
|
|
|
+ * two phases to the animation (an `in` and an `out` phase) */
|
|
|
+ * transition:0.5s linear all;
|
|
|
+ * }
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * We also **must** include animations for the views that are being entered and removed
|
|
|
+ * (otherwise anchoring wouldn't be possible since the new view would be inserted right away).
|
|
|
+ *
|
|
|
+ * ```css
|
|
|
+ * .view-animation.ng-enter, .view-animation.ng-leave {
|
|
|
+ * transition:0.5s linear all;
|
|
|
+ * position:fixed;
|
|
|
+ * left:0;
|
|
|
+ * top:0;
|
|
|
+ * width:100%;
|
|
|
+ * }
|
|
|
+ * .view-animation.ng-enter {
|
|
|
+ * transform:translateX(100%);
|
|
|
+ * }
|
|
|
+ * .view-animation.ng-leave,
|
|
|
+ * .view-animation.ng-enter.ng-enter-active {
|
|
|
+ * transform:translateX(0%);
|
|
|
+ * }
|
|
|
+ * .view-animation.ng-leave.ng-leave-active {
|
|
|
+ * transform:translateX(-100%);
|
|
|
+ * }
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * Now we can jump back to the anchor animation. When the animation happens, there are two stages that occur:
|
|
|
+ * an `out` and an `in` stage. The `out` stage happens first and that is when the element is animated away
|
|
|
+ * from its origin. Once that animation is over then the `in` stage occurs which animates the
|
|
|
+ * element to its destination. The reason why there are two animations is to give enough time
|
|
|
+ * for the enter animation on the new element to be ready.
|
|
|
+ *
|
|
|
+ * The example above sets up a transition for both the in and out phases, but we can also target the out or
|
|
|
+ * in phases directly via `ng-anchor-out` and `ng-anchor-in`.
|
|
|
+ *
|
|
|
+ * ```css
|
|
|
+ * .banner.ng-anchor-out {
|
|
|
+ * transition: 0.5s linear all;
|
|
|
+ *
|
|
|
+ * /* the scale will be applied during the out animation,
|
|
|
+ * but will be animated away when the in animation runs */
|
|
|
+ * transform: scale(1.2);
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * .banner.ng-anchor-in {
|
|
|
+ * transition: 1s linear all;
|
|
|
+ * }
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ *
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * ### Anchoring Demo
|
|
|
+ *
|
|
|
+ <example module="anchoringExample"
|
|
|
+ name="anchoringExample"
|
|
|
+ id="anchoringExample"
|
|
|
+ deps="angular-animate.js;angular-route.js"
|
|
|
+ animations="true">
|
|
|
+ <file name="index.html">
|
|
|
+ <a href="#/">Home</a>
|
|
|
+ <hr />
|
|
|
+ <div class="view-container">
|
|
|
+ <div ng-view class="view"></div>
|
|
|
+ </div>
|
|
|
+ </file>
|
|
|
+ <file name="script.js">
|
|
|
+ angular.module('anchoringExample', ['ngAnimate', 'ngRoute'])
|
|
|
+ .config(['$routeProvider', function($routeProvider) {
|
|
|
+ $routeProvider.when('/', {
|
|
|
+ templateUrl: 'home.html',
|
|
|
+ controller: 'HomeController as home'
|
|
|
+ });
|
|
|
+ $routeProvider.when('/profile/:id', {
|
|
|
+ templateUrl: 'profile.html',
|
|
|
+ controller: 'ProfileController as profile'
|
|
|
+ });
|
|
|
+ }])
|
|
|
+ .run(['$rootScope', function($rootScope) {
|
|
|
+ $rootScope.records = [
|
|
|
+ { id:1, title: "Miss Beulah Roob" },
|
|
|
+ { id:2, title: "Trent Morissette" },
|
|
|
+ { id:3, title: "Miss Ava Pouros" },
|
|
|
+ { id:4, title: "Rod Pouros" },
|
|
|
+ { id:5, title: "Abdul Rice" },
|
|
|
+ { id:6, title: "Laurie Rutherford Sr." },
|
|
|
+ { id:7, title: "Nakia McLaughlin" },
|
|
|
+ { id:8, title: "Jordon Blanda DVM" },
|
|
|
+ { id:9, title: "Rhoda Hand" },
|
|
|
+ { id:10, title: "Alexandrea Sauer" }
|
|
|
+ ];
|
|
|
+ }])
|
|
|
+ .controller('HomeController', [function() {
|
|
|
+
|
|
|
+ }])
|
|
|
+ .controller('ProfileController', ['$rootScope', '$routeParams', function($rootScope, $routeParams) {
|
|
|
+ var index = parseInt($routeParams.id, 10);
|
|
|
+ var record = $rootScope.records[index - 1];
|
|
|
+
|
|
|
+ this.title = record.title;
|
|
|
+ this.id = record.id;
|
|
|
+ }]);
|
|
|
+ </file>
|
|
|
+ <file name="home.html">
|
|
|
+ <h2>Welcome to the home page</h1>
|
|
|
+ <p>Please click on an element</p>
|
|
|
+ <a class="record"
|
|
|
+ ng-href="#/profile/{{ record.id }}"
|
|
|
+ ng-animate-ref="{{ record.id }}"
|
|
|
+ ng-repeat="record in records">
|
|
|
+ {{ record.title }}
|
|
|
+ </a>
|
|
|
+ </file>
|
|
|
+ <file name="profile.html">
|
|
|
+ <div class="profile record" ng-animate-ref="{{ profile.id }}">
|
|
|
+ {{ profile.title }}
|
|
|
+ </div>
|
|
|
+ </file>
|
|
|
+ <file name="animations.css">
|
|
|
+ .record {
|
|
|
+ display:block;
|
|
|
+ font-size:20px;
|
|
|
+ }
|
|
|
+ .profile {
|
|
|
+ background:black;
|
|
|
+ color:white;
|
|
|
+ font-size:100px;
|
|
|
+ }
|
|
|
+ .view-container {
|
|
|
+ position:relative;
|
|
|
+ }
|
|
|
+ .view-container > .view.ng-animate {
|
|
|
+ position:absolute;
|
|
|
+ top:0;
|
|
|
+ left:0;
|
|
|
+ width:100%;
|
|
|
+ min-height:500px;
|
|
|
+ }
|
|
|
+ .view.ng-enter, .view.ng-leave,
|
|
|
+ .record.ng-anchor {
|
|
|
+ transition:0.5s linear all;
|
|
|
+ }
|
|
|
+ .view.ng-enter {
|
|
|
+ transform:translateX(100%);
|
|
|
+ }
|
|
|
+ .view.ng-enter.ng-enter-active, .view.ng-leave {
|
|
|
+ transform:translateX(0%);
|
|
|
+ }
|
|
|
+ .view.ng-leave.ng-leave-active {
|
|
|
+ transform:translateX(-100%);
|
|
|
+ }
|
|
|
+ .record.ng-anchor-out {
|
|
|
+ background:red;
|
|
|
+ }
|
|
|
+ </file>
|
|
|
+ </example>
|
|
|
+ *
|
|
|
+ * ### How is the element transported?
|
|
|
+ *
|
|
|
+ * When an anchor animation occurs, ngAnimate will clone the starting element and position it exactly where the starting
|
|
|
+ * element is located on screen via absolute positioning. The cloned element will be placed inside of the root element
|
|
|
+ * of the application (where ng-app was defined) and all of the CSS classes of the starting element will be applied. The
|
|
|
+ * element will then animate into the `out` and `in` animations and will eventually reach the coordinates and match
|
|
|
+ * the dimensions of the destination element. During the entire animation a CSS class of `.ng-animate-shim` will be applied
|
|
|
+ * to both the starting and destination elements in order to hide them from being visible (the CSS styling for the class
|
|
|
+ * is: `visibility:hidden`). Once the anchor reaches its destination then it will be removed and the destination element
|
|
|
+ * will become visible since the shim class will be removed.
|
|
|
+ *
|
|
|
+ * ### How is the morphing handled?
|
|
|
+ *
|
|
|
+ * CSS Anchoring relies on transitions and keyframes and the internal code is intelligent enough to figure out
|
|
|
+ * what CSS classes differ between the starting element and the destination element. These different CSS classes
|
|
|
+ * will be added/removed on the anchor element and a transition will be applied (the transition that is provided
|
|
|
+ * in the anchor class). Long story short, ngAnimate will figure out what classes to add and remove which will
|
|
|
+ * make the transition of the element as smooth and automatic as possible. Be sure to use simple CSS classes that
|
|
|
+ * do not rely on DOM nesting structure so that the anchor element appears the same as the starting element (since
|
|
|
+ * the cloned element is placed inside of root element which is likely close to the body element).
|
|
|
+ *
|
|
|
+ * Note that if the root element is on the `<html>` element then the cloned node will be placed inside of body.
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * ## Using $animate in your directive code
|
|
|
+ *
|
|
|
+ * 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?
|
|
|
+ * 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
|
|
|
+ * imagine we have a greeting box that shows and hides itself when the data changes
|
|
|
+ *
|
|
|
+ * ```html
|
|
|
+ * <greeting-box active="onOrOff">Hi there</greeting-box>
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * ```js
|
|
|
+ * ngModule.directive('greetingBox', ['$animate', function($animate) {
|
|
|
+ * return function(scope, element, attrs) {
|
|
|
+ * attrs.$observe('active', function(value) {
|
|
|
+ * value ? $animate.addClass(element, 'on') : $animate.removeClass(element, 'on');
|
|
|
+ * });
|
|
|
+ * });
|
|
|
+ * }]);
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * 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
|
|
|
+ * in our HTML code then we can trigger a CSS or JS animation to happen.
|
|
|
+ *
|
|
|
+ * ```css
|
|
|
+ * /* normally we would create a CSS class to reference on the element */
|
|
|
+ * greeting-box.on { transition:0.5s linear all; background:green; color:white; }
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * The `$animate` service contains a variety of other methods like `enter`, `leave`, `animate` and `setClass`. To learn more about what's
|
|
|
+ * possible be sure to visit the {@link ng.$animate $animate service API page}.
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * ## Callbacks and Promises
|
|
|
+ *
|
|
|
+ * 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
|
|
|
+ * an animation (within our directive code) then we can continue performing directive and scope related activities after the animation has
|
|
|
+ * ended by chaining onto the returned promise that animation method returns.
|
|
|
+ *
|
|
|
+ * ```js
|
|
|
+ *
|
|
|
+ * $animate.enter(element, parent).then(function() {
|
|
|
+ *
|
|
|
+ * });
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * (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
|
|
|
+ * anymore.)
|
|
|
+ *
|
|
|
+ * In addition to the animation promise, we can also make use of animation-related callbacks within our directives and controller code by registering
|
|
|
+ * an event listener using the `$animate` service. Let's say for example that an animation was triggered on our view
|
|
|
+ * routing controller to hook into that:
|
|
|
+ *
|
|
|
+ * ```js
|
|
|
+ * ngModule.controller('HomePageController', ['$animate', function($animate) {
|
|
|
+ * $animate.on('enter', ngViewElement, function(element) {
|
|
|
+ *
|
|
|
+ * }]);
|
|
|
+ * }])
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * (Note that you will need to trigger a digest within the callback to get angular to notice any scope-related changes.)
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+ * @ngdoc service
|
|
|
+ * @name $animate
|
|
|
+ * @kind object
|
|
|
+ *
|
|
|
+ * @description
|
|
|
+ * The ngAnimate `$animate` service documentation is the same for the core `$animate` service.
|
|
|
+ *
|
|
|
+ * Click here {@link ng.$animate to learn more about animations with `$animate`}.
|
|
|
+ */
|
|
|
+angular.module('ngAnimate', [])
|
|
|
+ .directive('ngAnimateSwap', ngAnimateSwapDirective)
|
|
|
+
|
|
|
+ .directive('ngAnimateChildren', $$AnimateChildrenDirective)
|
|
|
+ .factory('$$rAFScheduler', $$rAFSchedulerFactory)
|
|
|
+
|
|
|
+ .provider('$$animateQueue', $$AnimateQueueProvider)
|
|
|
+ .provider('$$animation', $$AnimationProvider)
|
|
|
+
|
|
|
+ .provider('$animateCss', $AnimateCssProvider)
|
|
|
+ .provider('$$animateCssDriver', $$AnimateCssDriverProvider)
|
|
|
+
|
|
|
+ .provider('$$animateJs', $$AnimateJsProvider)
|
|
|
+ .provider('$$animateJsDriver', $$AnimateJsDriverProvider);
|
|
|
+
|
|
|
+
|
|
|
+})(window, window.angular);
|