angular-animate.js 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704
  1. /**
  2. * @license AngularJS v1.2.30
  3. * (c) 2010-2014 Google, Inc. http://angularjs.org
  4. * License: MIT
  5. */
  6. (function(window, angular, undefined) {'use strict';
  7. /* jshint maxlen: false */
  8. /**
  9. * @ngdoc module
  10. * @name ngAnimate
  11. * @description
  12. *
  13. * # ngAnimate
  14. *
  15. * The `ngAnimate` module provides support for JavaScript, CSS3 transition and CSS3 keyframe animation hooks within existing core and custom directives.
  16. *
  17. *
  18. * <div doc-module-components="ngAnimate"></div>
  19. *
  20. * # Usage
  21. *
  22. * To see animations in action, all that is required is to define the appropriate CSS classes
  23. * or to register a JavaScript animation via the myModule.animation() function. The directives that support animation automatically are:
  24. * `ngRepeat`, `ngInclude`, `ngIf`, `ngSwitch`, `ngShow`, `ngHide`, `ngView` and `ngClass`. Custom directives can take advantage of animation
  25. * by using the `$animate` service.
  26. *
  27. * Below is a more detailed breakdown of the supported animation events provided by pre-existing ng directives:
  28. *
  29. * | Directive | Supported Animations |
  30. * |---------------------------------------------------------- |----------------------------------------------------|
  31. * | {@link ng.directive:ngRepeat#usage_animations ngRepeat} | enter, leave and move |
  32. * | {@link ngRoute.directive:ngView#usage_animations ngView} | enter and leave |
  33. * | {@link ng.directive:ngInclude#usage_animations ngInclude} | enter and leave |
  34. * | {@link ng.directive:ngSwitch#usage_animations ngSwitch} | enter and leave |
  35. * | {@link ng.directive:ngIf#usage_animations ngIf} | enter and leave |
  36. * | {@link ng.directive:ngClass#usage_animations ngClass} | add and remove |
  37. * | {@link ng.directive:ngShow#usage_animations ngShow & ngHide} | add and remove (the ng-hide class value) |
  38. * | {@link ng.directive:form#usage_animations form} | add and remove (dirty, pristine, valid, invalid & all other validations) |
  39. * | {@link ng.directive:ngModel#usage_animations ngModel} | add and remove (dirty, pristine, valid, invalid & all other validations) |
  40. *
  41. * You can find out more information about animations upon visiting each directive page.
  42. *
  43. * Below is an example of how to apply animations to a directive that supports animation hooks:
  44. *
  45. * ```html
  46. * <style type="text/css">
  47. * .slide.ng-enter, .slide.ng-leave {
  48. * -webkit-transition:0.5s linear all;
  49. * transition:0.5s linear all;
  50. * }
  51. *
  52. * .slide.ng-enter { } /&#42; starting animations for enter &#42;/
  53. * .slide.ng-enter.ng-enter-active { } /&#42; terminal animations for enter &#42;/
  54. * .slide.ng-leave { } /&#42; starting animations for leave &#42;/
  55. * .slide.ng-leave.ng-leave-active { } /&#42; terminal animations for leave &#42;/
  56. * </style>
  57. *
  58. * <!--
  59. * the animate service will automatically add .ng-enter and .ng-leave to the element
  60. * to trigger the CSS transition/animations
  61. * -->
  62. * <ANY class="slide" ng-include="..."></ANY>
  63. * ```
  64. *
  65. * Keep in mind that, by default, if an animation is running, any child elements cannot be animated
  66. * until the parent element's animation has completed. This blocking feature can be overridden by
  67. * placing the `ng-animate-children` attribute on a parent container tag.
  68. *
  69. * ```html
  70. * <div class="slide-animation" ng-if="on" ng-animate-children>
  71. * <div class="fade-animation" ng-if="on">
  72. * <div class="explode-animation" ng-if="on">
  73. * ...
  74. * </div>
  75. * </div>
  76. * </div>
  77. * ```
  78. *
  79. * When the `on` expression value changes and an animation is triggered then each of the elements within
  80. * will all animate without the block being applied to child elements.
  81. *
  82. * <h2>CSS-defined Animations</h2>
  83. * The animate service will automatically apply two CSS classes to the animated element and these two CSS classes
  84. * are designed to contain the start and end CSS styling. Both CSS transitions and keyframe animations are supported
  85. * and can be used to play along with this naming structure.
  86. *
  87. * The following code below demonstrates how to perform animations using **CSS transitions** with Angular:
  88. *
  89. * ```html
  90. * <style type="text/css">
  91. * /&#42;
  92. * The animate class is apart of the element and the ng-enter class
  93. * is attached to the element once the enter animation event is triggered
  94. * &#42;/
  95. * .reveal-animation.ng-enter {
  96. * -webkit-transition: 1s linear all; /&#42; Safari/Chrome &#42;/
  97. * transition: 1s linear all; /&#42; All other modern browsers and IE10+ &#42;/
  98. *
  99. * /&#42; The animation preparation code &#42;/
  100. * opacity: 0;
  101. * }
  102. *
  103. * /&#42;
  104. * Keep in mind that you want to combine both CSS
  105. * classes together to avoid any CSS-specificity
  106. * conflicts
  107. * &#42;/
  108. * .reveal-animation.ng-enter.ng-enter-active {
  109. * /&#42; The animation code itself &#42;/
  110. * opacity: 1;
  111. * }
  112. * </style>
  113. *
  114. * <div class="view-container">
  115. * <div ng-view class="reveal-animation"></div>
  116. * </div>
  117. * ```
  118. *
  119. * The following code below demonstrates how to perform animations using **CSS animations** with Angular:
  120. *
  121. * ```html
  122. * <style type="text/css">
  123. * .reveal-animation.ng-enter {
  124. * -webkit-animation: enter_sequence 1s linear; /&#42; Safari/Chrome &#42;/
  125. * animation: enter_sequence 1s linear; /&#42; IE10+ and Future Browsers &#42;/
  126. * }
  127. * @-webkit-keyframes enter_sequence {
  128. * from { opacity:0; }
  129. * to { opacity:1; }
  130. * }
  131. * @keyframes enter_sequence {
  132. * from { opacity:0; }
  133. * to { opacity:1; }
  134. * }
  135. * </style>
  136. *
  137. * <div class="view-container">
  138. * <div ng-view class="reveal-animation"></div>
  139. * </div>
  140. * ```
  141. *
  142. * Both CSS3 animations and transitions can be used together and the animate service will figure out the correct duration and delay timing.
  143. *
  144. * Upon DOM mutation, the event class is added first (something like `ng-enter`), then the browser prepares itself to add
  145. * the active class (in this case `ng-enter-active`) which then triggers the animation. The animation module will automatically
  146. * detect the CSS code to determine when the animation ends. Once the animation is over then both CSS classes will be
  147. * removed from the DOM. If a browser does not support CSS transitions or CSS animations then the animation will start and end
  148. * immediately resulting in a DOM element that is at its final state. This final state is when the DOM element
  149. * has no CSS transition/animation classes applied to it.
  150. *
  151. * <h3>CSS Staggering Animations</h3>
  152. * A Staggering animation is a collection of animations that are issued with a slight delay in between each successive operation resulting in a
  153. * curtain-like effect. The ngAnimate module, as of 1.2.0, supports staggering animations and the stagger effect can be
  154. * performed by creating a **ng-EVENT-stagger** CSS class and attaching that class to the base CSS class used for
  155. * the animation. The style property expected within the stagger class can either be a **transition-delay** or an
  156. * **animation-delay** property (or both if your animation contains both transitions and keyframe animations).
  157. *
  158. * ```css
  159. * .my-animation.ng-enter {
  160. * /&#42; standard transition code &#42;/
  161. * -webkit-transition: 1s linear all;
  162. * transition: 1s linear all;
  163. * opacity:0;
  164. * }
  165. * .my-animation.ng-enter-stagger {
  166. * /&#42; this will have a 100ms delay between each successive leave animation &#42;/
  167. * -webkit-transition-delay: 0.1s;
  168. * transition-delay: 0.1s;
  169. *
  170. * /&#42; in case the stagger doesn't work then these two values
  171. * must be set to 0 to avoid an accidental CSS inheritance &#42;/
  172. * -webkit-transition-duration: 0s;
  173. * transition-duration: 0s;
  174. * }
  175. * .my-animation.ng-enter.ng-enter-active {
  176. * /&#42; standard transition styles &#42;/
  177. * opacity:1;
  178. * }
  179. * ```
  180. *
  181. * Staggering animations work by default in ngRepeat (so long as the CSS class is defined). Outside of ngRepeat, to use staggering animations
  182. * on your own, they can be triggered by firing multiple calls to the same event on $animate. However, the restrictions surrounding this
  183. * are that each of the elements must have the same CSS className value as well as the same parent element. A stagger operation
  184. * will also be reset if more than 10ms has passed after the last animation has been fired.
  185. *
  186. * The following code will issue the **ng-leave-stagger** event on the element provided:
  187. *
  188. * ```js
  189. * var kids = parent.children();
  190. *
  191. * $animate.leave(kids[0]); //stagger index=0
  192. * $animate.leave(kids[1]); //stagger index=1
  193. * $animate.leave(kids[2]); //stagger index=2
  194. * $animate.leave(kids[3]); //stagger index=3
  195. * $animate.leave(kids[4]); //stagger index=4
  196. *
  197. * $timeout(function() {
  198. * //stagger has reset itself
  199. * $animate.leave(kids[5]); //stagger index=0
  200. * $animate.leave(kids[6]); //stagger index=1
  201. * }, 100, false);
  202. * ```
  203. *
  204. * Stagger animations are currently only supported within CSS-defined animations.
  205. *
  206. * <h2>JavaScript-defined Animations</h2>
  207. * In the event that you do not want to use CSS3 transitions or CSS3 animations or if you wish to offer animations on browsers that do not
  208. * yet support CSS transitions/animations, then you can make use of JavaScript animations defined inside of your AngularJS module.
  209. *
  210. * ```js
  211. * //!annotate="YourApp" Your AngularJS Module|Replace this or ngModule with the module that you used to define your application.
  212. * var ngModule = angular.module('YourApp', ['ngAnimate']);
  213. * ngModule.animation('.my-crazy-animation', function() {
  214. * return {
  215. * enter: function(element, done) {
  216. * //run the animation here and call done when the animation is complete
  217. * return function(cancelled) {
  218. * //this (optional) function will be called when the animation
  219. * //completes or when the animation is cancelled (the cancelled
  220. * //flag will be set to true if cancelled).
  221. * };
  222. * },
  223. * leave: function(element, done) { },
  224. * move: function(element, done) { },
  225. *
  226. * //animation that can be triggered before the class is added
  227. * beforeAddClass: function(element, className, done) { },
  228. *
  229. * //animation that can be triggered after the class is added
  230. * addClass: function(element, className, done) { },
  231. *
  232. * //animation that can be triggered before the class is removed
  233. * beforeRemoveClass: function(element, className, done) { },
  234. *
  235. * //animation that can be triggered after the class is removed
  236. * removeClass: function(element, className, done) { }
  237. * };
  238. * });
  239. * ```
  240. *
  241. * JavaScript-defined animations are created with a CSS-like class selector and a collection of events which are set to run
  242. * a javascript callback function. When an animation is triggered, $animate will look for a matching animation which fits
  243. * the element's CSS class attribute value and then run the matching animation event function (if found).
  244. * In other words, if the CSS classes present on the animated element match any of the JavaScript animations then the callback function will
  245. * be executed. It should be also noted that only simple, single class selectors are allowed (compound class selectors are not supported).
  246. *
  247. * Within a JavaScript animation, an object containing various event callback animation functions is expected to be returned.
  248. * As explained above, these callbacks are triggered based on the animation event. Therefore if an enter animation is run,
  249. * and the JavaScript animation is found, then the enter callback will handle that animation (in addition to the CSS keyframe animation
  250. * or transition code that is defined via a stylesheet).
  251. *
  252. */
  253. angular.module('ngAnimate', ['ng'])
  254. /**
  255. * @ngdoc provider
  256. * @name $animateProvider
  257. * @description
  258. *
  259. * The `$animateProvider` allows developers to register JavaScript animation event handlers directly inside of a module.
  260. * When an animation is triggered, the $animate service will query the $animate service to find any animations that match
  261. * the provided name value.
  262. *
  263. * Requires the {@link ngAnimate `ngAnimate`} module to be installed.
  264. *
  265. * Please visit the {@link ngAnimate `ngAnimate`} module overview page learn more about how to use animations in your application.
  266. *
  267. */
  268. .directive('ngAnimateChildren', function() {
  269. var NG_ANIMATE_CHILDREN = '$$ngAnimateChildren';
  270. return function(scope, element, attrs) {
  271. var val = attrs.ngAnimateChildren;
  272. if(angular.isString(val) && val.length === 0) { //empty attribute
  273. element.data(NG_ANIMATE_CHILDREN, true);
  274. } else {
  275. scope.$watch(val, function(value) {
  276. element.data(NG_ANIMATE_CHILDREN, !!value);
  277. });
  278. }
  279. };
  280. })
  281. //this private service is only used within CSS-enabled animations
  282. //IE8 + IE9 do not support rAF natively, but that is fine since they
  283. //also don't support transitions and keyframes which means that the code
  284. //below will never be used by the two browsers.
  285. .factory('$$animateReflow', ['$$rAF', '$document', function($$rAF, $document) {
  286. var bod = $document[0].body;
  287. return function(fn) {
  288. //the returned function acts as the cancellation function
  289. return $$rAF(function() {
  290. //the line below will force the browser to perform a repaint
  291. //so that all the animated elements within the animation frame
  292. //will be properly updated and drawn on screen. This is
  293. //required to perform multi-class CSS based animations with
  294. //Firefox. DO NOT REMOVE THIS LINE. DO NOT OPTIMIZE THIS LINE.
  295. //THE MINIFIER WILL REMOVE IT OTHERWISE WHICH WILL RESULT IN AN
  296. //UNPREDICTABLE BUG THAT IS VERY HARD TO TRACK DOWN AND WILL
  297. //TAKE YEARS AWAY FROM YOUR LIFE!
  298. fn(bod.offsetWidth);
  299. });
  300. };
  301. }])
  302. .config(['$provide', '$animateProvider', function($provide, $animateProvider) {
  303. var noop = angular.noop;
  304. var forEach = angular.forEach;
  305. var selectors = $animateProvider.$$selectors;
  306. var ELEMENT_NODE = 1;
  307. var NG_ANIMATE_STATE = '$$ngAnimateState';
  308. var NG_ANIMATE_CHILDREN = '$$ngAnimateChildren';
  309. var NG_ANIMATE_CLASS_NAME = 'ng-animate';
  310. var rootAnimateState = {running: true};
  311. function extractElementNode(element) {
  312. for(var i = 0; i < element.length; i++) {
  313. var elm = element[i];
  314. if(elm.nodeType == ELEMENT_NODE) {
  315. return elm;
  316. }
  317. }
  318. }
  319. function prepareElement(element) {
  320. return element && angular.element(element);
  321. }
  322. function stripCommentsFromElement(element) {
  323. return angular.element(extractElementNode(element));
  324. }
  325. function isMatchingElement(elm1, elm2) {
  326. return extractElementNode(elm1) == extractElementNode(elm2);
  327. }
  328. $provide.decorator('$animate', ['$delegate', '$injector', '$sniffer', '$rootElement', '$$asyncCallback', '$rootScope', '$document',
  329. function($delegate, $injector, $sniffer, $rootElement, $$asyncCallback, $rootScope, $document) {
  330. var globalAnimationCounter = 0;
  331. $rootElement.data(NG_ANIMATE_STATE, rootAnimateState);
  332. // disable animations during bootstrap, but once we bootstrapped, wait again
  333. // for another digest until enabling animations. The reason why we digest twice
  334. // is because all structural animations (enter, leave and move) all perform a
  335. // post digest operation before animating. If we only wait for a single digest
  336. // to pass then the structural animation would render its animation on page load.
  337. // (which is what we're trying to avoid when the application first boots up.)
  338. $rootScope.$$postDigest(function() {
  339. $rootScope.$$postDigest(function() {
  340. rootAnimateState.running = false;
  341. });
  342. });
  343. var classNameFilter = $animateProvider.classNameFilter();
  344. var isAnimatableClassName = !classNameFilter
  345. ? function() { return true; }
  346. : function(className) {
  347. return classNameFilter.test(className);
  348. };
  349. function blockElementAnimations(element) {
  350. var data = element.data(NG_ANIMATE_STATE) || {};
  351. data.running = true;
  352. element.data(NG_ANIMATE_STATE, data);
  353. }
  354. function lookup(name) {
  355. if (name) {
  356. var matches = [],
  357. flagMap = {},
  358. classes = name.substr(1).split('.');
  359. //the empty string value is the default animation
  360. //operation which performs CSS transition and keyframe
  361. //animations sniffing. This is always included for each
  362. //element animation procedure if the browser supports
  363. //transitions and/or keyframe animations. The default
  364. //animation is added to the top of the list to prevent
  365. //any previous animations from affecting the element styling
  366. //prior to the element being animated.
  367. if ($sniffer.transitions || $sniffer.animations) {
  368. matches.push($injector.get(selectors['']));
  369. }
  370. for(var i=0; i < classes.length; i++) {
  371. var klass = classes[i],
  372. selectorFactoryName = selectors[klass];
  373. if(selectorFactoryName && !flagMap[klass]) {
  374. matches.push($injector.get(selectorFactoryName));
  375. flagMap[klass] = true;
  376. }
  377. }
  378. return matches;
  379. }
  380. }
  381. function animationRunner(element, animationEvent, className) {
  382. //transcluded directives may sometimes fire an animation using only comment nodes
  383. //best to catch this early on to prevent any animation operations from occurring
  384. var node = element[0];
  385. if(!node) {
  386. return;
  387. }
  388. var isSetClassOperation = animationEvent == 'setClass';
  389. var isClassBased = isSetClassOperation ||
  390. animationEvent == 'addClass' ||
  391. animationEvent == 'removeClass';
  392. var classNameAdd, classNameRemove;
  393. if(angular.isArray(className)) {
  394. classNameAdd = className[0];
  395. classNameRemove = className[1];
  396. className = classNameAdd + ' ' + classNameRemove;
  397. }
  398. var currentClassName = element.attr('class');
  399. var classes = currentClassName + ' ' + className;
  400. if(!isAnimatableClassName(classes)) {
  401. return;
  402. }
  403. var beforeComplete = noop,
  404. beforeCancel = [],
  405. before = [],
  406. afterComplete = noop,
  407. afterCancel = [],
  408. after = [];
  409. var animationLookup = (' ' + classes).replace(/\s+/g,'.');
  410. forEach(lookup(animationLookup), function(animationFactory) {
  411. var created = registerAnimation(animationFactory, animationEvent);
  412. if(!created && isSetClassOperation) {
  413. registerAnimation(animationFactory, 'addClass');
  414. registerAnimation(animationFactory, 'removeClass');
  415. }
  416. });
  417. function registerAnimation(animationFactory, event) {
  418. var afterFn = animationFactory[event];
  419. var beforeFn = animationFactory['before' + event.charAt(0).toUpperCase() + event.substr(1)];
  420. if(afterFn || beforeFn) {
  421. if(event == 'leave') {
  422. beforeFn = afterFn;
  423. //when set as null then animation knows to skip this phase
  424. afterFn = null;
  425. }
  426. after.push({
  427. event : event, fn : afterFn
  428. });
  429. before.push({
  430. event : event, fn : beforeFn
  431. });
  432. return true;
  433. }
  434. }
  435. function run(fns, cancellations, allCompleteFn) {
  436. var animations = [];
  437. forEach(fns, function(animation) {
  438. animation.fn && animations.push(animation);
  439. });
  440. var count = 0;
  441. function afterAnimationComplete(index) {
  442. if(cancellations) {
  443. (cancellations[index] || noop)();
  444. if(++count < animations.length) return;
  445. cancellations = null;
  446. }
  447. allCompleteFn();
  448. }
  449. //The code below adds directly to the array in order to work with
  450. //both sync and async animations. Sync animations are when the done()
  451. //operation is called right away. DO NOT REFACTOR!
  452. forEach(animations, function(animation, index) {
  453. var progress = function() {
  454. afterAnimationComplete(index);
  455. };
  456. switch(animation.event) {
  457. case 'setClass':
  458. cancellations.push(animation.fn(element, classNameAdd, classNameRemove, progress));
  459. break;
  460. case 'addClass':
  461. cancellations.push(animation.fn(element, classNameAdd || className, progress));
  462. break;
  463. case 'removeClass':
  464. cancellations.push(animation.fn(element, classNameRemove || className, progress));
  465. break;
  466. default:
  467. cancellations.push(animation.fn(element, progress));
  468. break;
  469. }
  470. });
  471. if(cancellations && cancellations.length === 0) {
  472. allCompleteFn();
  473. }
  474. }
  475. return {
  476. node : node,
  477. event : animationEvent,
  478. className : className,
  479. isClassBased : isClassBased,
  480. isSetClassOperation : isSetClassOperation,
  481. before : function(allCompleteFn) {
  482. beforeComplete = allCompleteFn;
  483. run(before, beforeCancel, function() {
  484. beforeComplete = noop;
  485. allCompleteFn();
  486. });
  487. },
  488. after : function(allCompleteFn) {
  489. afterComplete = allCompleteFn;
  490. run(after, afterCancel, function() {
  491. afterComplete = noop;
  492. allCompleteFn();
  493. });
  494. },
  495. cancel : function() {
  496. if(beforeCancel) {
  497. forEach(beforeCancel, function(cancelFn) {
  498. (cancelFn || noop)(true);
  499. });
  500. beforeComplete(true);
  501. }
  502. if(afterCancel) {
  503. forEach(afterCancel, function(cancelFn) {
  504. (cancelFn || noop)(true);
  505. });
  506. afterComplete(true);
  507. }
  508. }
  509. };
  510. }
  511. /**
  512. * @ngdoc service
  513. * @name $animate
  514. * @kind function
  515. *
  516. * @description
  517. * The `$animate` service provides animation detection support while performing DOM operations (enter, leave and move) as well as during addClass and removeClass operations.
  518. * When any of these operations are run, the $animate service
  519. * will examine any JavaScript-defined animations (which are defined by using the $animateProvider provider object)
  520. * as well as any CSS-defined animations against the CSS classes present on the element once the DOM operation is run.
  521. *
  522. * The `$animate` service is used behind the scenes with pre-existing directives and animation with these directives
  523. * will work out of the box without any extra configuration.
  524. *
  525. * Requires the {@link ngAnimate `ngAnimate`} module to be installed.
  526. *
  527. * Please visit the {@link ngAnimate `ngAnimate`} module overview page learn more about how to use animations in your application.
  528. *
  529. */
  530. return {
  531. /**
  532. * @ngdoc method
  533. * @name $animate#enter
  534. * @kind function
  535. *
  536. * @description
  537. * Appends the element to the parentElement element that resides in the document and then runs the enter animation. Once
  538. * the animation is started, the following CSS classes will be present on the element for the duration of the animation:
  539. *
  540. * Below is a breakdown of each step that occurs during enter animation:
  541. *
  542. * | Animation Step | What the element class attribute looks like |
  543. * |----------------------------------------------------------------------------------------------|---------------------------------------------|
  544. * | 1. $animate.enter(...) is called | class="my-animation" |
  545. * | 2. element is inserted into the parentElement element or beside the afterElement element | class="my-animation" |
  546. * | 3. $animate runs any JavaScript-defined animations on the element | class="my-animation ng-animate" |
  547. * | 4. the .ng-enter class is added to the element | class="my-animation ng-animate ng-enter" |
  548. * | 5. $animate scans the element styles to get the CSS transition/animation duration and delay | class="my-animation ng-animate ng-enter" |
  549. * | 6. $animate waits for 10ms (this performs a reflow) | class="my-animation ng-animate ng-enter" |
  550. * | 7. the .ng-enter-active and .ng-animate-active classes are added (this triggers the CSS transition/animation) | class="my-animation ng-animate ng-animate-active ng-enter ng-enter-active" |
  551. * | 8. $animate waits for X milliseconds for the animation to complete | class="my-animation ng-animate ng-animate-active ng-enter ng-enter-active" |
  552. * | 9. The animation ends and all generated CSS classes are removed from the element | class="my-animation" |
  553. * | 10. The doneCallback() callback is fired (if provided) | class="my-animation" |
  554. *
  555. * @param {DOMElement} element the element that will be the focus of the enter animation
  556. * @param {DOMElement} parentElement the parent element of the element that will be the focus of the enter animation
  557. * @param {DOMElement} afterElement the sibling element (which is the previous element) of the element that will be the focus of the enter animation
  558. * @param {function()=} doneCallback the callback function that will be called once the animation is complete
  559. */
  560. enter : function(element, parentElement, afterElement, doneCallback) {
  561. element = angular.element(element);
  562. parentElement = prepareElement(parentElement);
  563. afterElement = prepareElement(afterElement);
  564. blockElementAnimations(element);
  565. $delegate.enter(element, parentElement, afterElement);
  566. $rootScope.$$postDigest(function() {
  567. element = stripCommentsFromElement(element);
  568. performAnimation('enter', 'ng-enter', element, parentElement, afterElement, noop, doneCallback);
  569. });
  570. },
  571. /**
  572. * @ngdoc method
  573. * @name $animate#leave
  574. * @kind function
  575. *
  576. * @description
  577. * Runs the leave animation operation and, upon completion, removes the element from the DOM. Once
  578. * the animation is started, the following CSS classes will be added for the duration of the animation:
  579. *
  580. * Below is a breakdown of each step that occurs during leave animation:
  581. *
  582. * | Animation Step | What the element class attribute looks like |
  583. * |----------------------------------------------------------------------------------------------|---------------------------------------------|
  584. * | 1. $animate.leave(...) is called | class="my-animation" |
  585. * | 2. $animate runs any JavaScript-defined animations on the element | class="my-animation ng-animate" |
  586. * | 3. the .ng-leave class is added to the element | class="my-animation ng-animate ng-leave" |
  587. * | 4. $animate scans the element styles to get the CSS transition/animation duration and delay | class="my-animation ng-animate ng-leave" |
  588. * | 5. $animate waits for 10ms (this performs a reflow) | class="my-animation ng-animate ng-leave" |
  589. * | 6. the .ng-leave-active and .ng-animate-active classes is added (this triggers the CSS transition/animation) | class="my-animation ng-animate ng-animate-active ng-leave ng-leave-active" |
  590. * | 7. $animate waits for X milliseconds for the animation to complete | class="my-animation ng-animate ng-animate-active ng-leave ng-leave-active" |
  591. * | 8. The animation ends and all generated CSS classes are removed from the element | class="my-animation" |
  592. * | 9. The element is removed from the DOM | ... |
  593. * | 10. The doneCallback() callback is fired (if provided) | ... |
  594. *
  595. * @param {DOMElement} element the element that will be the focus of the leave animation
  596. * @param {function()=} doneCallback the callback function that will be called once the animation is complete
  597. */
  598. leave : function(element, doneCallback) {
  599. element = angular.element(element);
  600. cancelChildAnimations(element);
  601. blockElementAnimations(element);
  602. $rootScope.$$postDigest(function() {
  603. performAnimation('leave', 'ng-leave', stripCommentsFromElement(element), null, null, function() {
  604. $delegate.leave(element);
  605. }, doneCallback);
  606. });
  607. },
  608. /**
  609. * @ngdoc method
  610. * @name $animate#move
  611. * @kind function
  612. *
  613. * @description
  614. * Fires the move DOM operation. Just before the animation starts, the animate service will either append it into the parentElement container or
  615. * add the element directly after the afterElement element if present. Then the move animation will be run. Once
  616. * the animation is started, the following CSS classes will be added for the duration of the animation:
  617. *
  618. * Below is a breakdown of each step that occurs during move animation:
  619. *
  620. * | Animation Step | What the element class attribute looks like |
  621. * |----------------------------------------------------------------------------------------------|---------------------------------------------|
  622. * | 1. $animate.move(...) is called | class="my-animation" |
  623. * | 2. element is moved into the parentElement element or beside the afterElement element | class="my-animation" |
  624. * | 3. $animate runs any JavaScript-defined animations on the element | class="my-animation ng-animate" |
  625. * | 4. the .ng-move class is added to the element | class="my-animation ng-animate ng-move" |
  626. * | 5. $animate scans the element styles to get the CSS transition/animation duration and delay | class="my-animation ng-animate ng-move" |
  627. * | 6. $animate waits for 10ms (this performs a reflow) | class="my-animation ng-animate ng-move" |
  628. * | 7. the .ng-move-active and .ng-animate-active classes is added (this triggers the CSS transition/animation) | class="my-animation ng-animate ng-animate-active ng-move ng-move-active" |
  629. * | 8. $animate waits for X milliseconds for the animation to complete | class="my-animation ng-animate ng-animate-active ng-move ng-move-active" |
  630. * | 9. The animation ends and all generated CSS classes are removed from the element | class="my-animation" |
  631. * | 10. The doneCallback() callback is fired (if provided) | class="my-animation" |
  632. *
  633. * @param {DOMElement} element the element that will be the focus of the move animation
  634. * @param {DOMElement} parentElement the parentElement element of the element that will be the focus of the move animation
  635. * @param {DOMElement} afterElement the sibling element (which is the previous element) of the element that will be the focus of the move animation
  636. * @param {function()=} doneCallback the callback function that will be called once the animation is complete
  637. */
  638. move : function(element, parentElement, afterElement, doneCallback) {
  639. element = angular.element(element);
  640. parentElement = prepareElement(parentElement);
  641. afterElement = prepareElement(afterElement);
  642. cancelChildAnimations(element);
  643. blockElementAnimations(element);
  644. $delegate.move(element, parentElement, afterElement);
  645. $rootScope.$$postDigest(function() {
  646. element = stripCommentsFromElement(element);
  647. performAnimation('move', 'ng-move', element, parentElement, afterElement, noop, doneCallback);
  648. });
  649. },
  650. /**
  651. * @ngdoc method
  652. * @name $animate#addClass
  653. *
  654. * @description
  655. * Triggers a custom animation event based off the className variable and then attaches the className value to the element as a CSS class.
  656. * Unlike the other animation methods, the animate service will suffix the className value with {@type -add} in order to provide
  657. * the animate service the setup and active CSS classes in order to trigger the animation (this will be skipped if no CSS transitions
  658. * or keyframes are defined on the -add or base CSS class).
  659. *
  660. * Below is a breakdown of each step that occurs during addClass animation:
  661. *
  662. * | Animation Step | What the element class attribute looks like |
  663. * |------------------------------------------------------------------------------------------------|---------------------------------------------|
  664. * | 1. $animate.addClass(element, 'super') is called | class="my-animation" |
  665. * | 2. $animate runs any JavaScript-defined animations on the element | class="my-animation ng-animate" |
  666. * | 3. the .super-add class are added to the element | class="my-animation ng-animate super-add" |
  667. * | 4. $animate scans the element styles to get the CSS transition/animation duration and delay | class="my-animation ng-animate super-add" |
  668. * | 5. $animate waits for 10ms (this performs a reflow) | class="my-animation ng-animate super-add" |
  669. * | 6. the .super, .super-add-active and .ng-animate-active classes are added (this triggers the CSS transition/animation) | class="my-animation ng-animate ng-animate-active super super-add super-add-active" |
  670. * | 7. $animate waits for X milliseconds for the animation to complete | class="my-animation super super-add super-add-active" |
  671. * | 8. The animation ends and all generated CSS classes are removed from the element | class="my-animation super" |
  672. * | 9. The super class is kept on the element | class="my-animation super" |
  673. * | 10. The doneCallback() callback is fired (if provided) | class="my-animation super" |
  674. *
  675. * @param {DOMElement} element the element that will be animated
  676. * @param {string} className the CSS class that will be added to the element and then animated
  677. * @param {function()=} doneCallback the callback function that will be called once the animation is complete
  678. */
  679. addClass : function(element, className, doneCallback) {
  680. element = angular.element(element);
  681. element = stripCommentsFromElement(element);
  682. performAnimation('addClass', className, element, null, null, function() {
  683. $delegate.addClass(element, className);
  684. }, doneCallback);
  685. },
  686. /**
  687. * @ngdoc method
  688. * @name $animate#removeClass
  689. *
  690. * @description
  691. * Triggers a custom animation event based off the className variable and then removes the CSS class provided by the className value
  692. * from the element. Unlike the other animation methods, the animate service will suffix the className value with {@type -remove} in
  693. * order to provide the animate service the setup and active CSS classes in order to trigger the animation (this will be skipped if
  694. * no CSS transitions or keyframes are defined on the -remove or base CSS classes).
  695. *
  696. * Below is a breakdown of each step that occurs during removeClass animation:
  697. *
  698. * | Animation Step | What the element class attribute looks like |
  699. * |-----------------------------------------------------------------------------------------------|---------------------------------------------|
  700. * | 1. $animate.removeClass(element, 'super') is called | class="my-animation super" |
  701. * | 2. $animate runs any JavaScript-defined animations on the element | class="my-animation super ng-animate" |
  702. * | 3. the .super-remove class are added to the element | class="my-animation super ng-animate super-remove"|
  703. * | 4. $animate scans the element styles to get the CSS transition/animation duration and delay | class="my-animation super ng-animate super-remove" |
  704. * | 5. $animate waits for 10ms (this performs a reflow) | class="my-animation super ng-animate super-remove" |
  705. * | 6. the .super-remove-active and .ng-animate-active classes are added and .super is removed (this triggers the CSS transition/animation) | class="my-animation ng-animate ng-animate-active super-remove super-remove-active" |
  706. * | 7. $animate waits for X milliseconds for the animation to complete | class="my-animation ng-animate ng-animate-active super-remove super-remove-active" |
  707. * | 8. The animation ends and all generated CSS classes are removed from the element | class="my-animation" |
  708. * | 9. The doneCallback() callback is fired (if provided) | class="my-animation" |
  709. *
  710. *
  711. * @param {DOMElement} element the element that will be animated
  712. * @param {string} className the CSS class that will be animated and then removed from the element
  713. * @param {function()=} doneCallback the callback function that will be called once the animation is complete
  714. */
  715. removeClass : function(element, className, doneCallback) {
  716. element = angular.element(element);
  717. element = stripCommentsFromElement(element);
  718. performAnimation('removeClass', className, element, null, null, function() {
  719. $delegate.removeClass(element, className);
  720. }, doneCallback);
  721. },
  722. /**
  723. *
  724. * @ngdoc function
  725. * @name $animate#setClass
  726. * @function
  727. * @description Adds and/or removes the given CSS classes to and from the element.
  728. * Once complete, the done() callback will be fired (if provided).
  729. * @param {DOMElement} element the element which will its CSS classes changed
  730. * removed from it
  731. * @param {string} add the CSS classes which will be added to the element
  732. * @param {string} remove the CSS class which will be removed from the element
  733. * @param {Function=} done the callback function (if provided) that will be fired after the
  734. * CSS classes have been set on the element
  735. */
  736. setClass : function(element, add, remove, doneCallback) {
  737. element = angular.element(element);
  738. element = stripCommentsFromElement(element);
  739. performAnimation('setClass', [add, remove], element, null, null, function() {
  740. $delegate.setClass(element, add, remove);
  741. }, doneCallback);
  742. },
  743. /**
  744. * @ngdoc method
  745. * @name $animate#enabled
  746. * @kind function
  747. *
  748. * @param {boolean=} value If provided then set the animation on or off.
  749. * @param {DOMElement=} element If provided then the element will be used to represent the enable/disable operation
  750. * @return {boolean} Current animation state.
  751. *
  752. * @description
  753. * Globally enables/disables animations.
  754. *
  755. */
  756. enabled : function(value, element) {
  757. switch(arguments.length) {
  758. case 2:
  759. if(value) {
  760. cleanup(element);
  761. } else {
  762. var data = element.data(NG_ANIMATE_STATE) || {};
  763. data.disabled = true;
  764. element.data(NG_ANIMATE_STATE, data);
  765. }
  766. break;
  767. case 1:
  768. rootAnimateState.disabled = !value;
  769. break;
  770. default:
  771. value = !rootAnimateState.disabled;
  772. break;
  773. }
  774. return !!value;
  775. }
  776. };
  777. /*
  778. all animations call this shared animation triggering function internally.
  779. The animationEvent variable refers to the JavaScript animation event that will be triggered
  780. and the className value is the name of the animation that will be applied within the
  781. CSS code. Element, parentElement and afterElement are provided DOM elements for the animation
  782. and the onComplete callback will be fired once the animation is fully complete.
  783. */
  784. function performAnimation(animationEvent, className, element, parentElement, afterElement, domOperation, doneCallback) {
  785. var runner = animationRunner(element, animationEvent, className);
  786. if(!runner) {
  787. fireDOMOperation();
  788. fireBeforeCallbackAsync();
  789. fireAfterCallbackAsync();
  790. closeAnimation();
  791. return;
  792. }
  793. className = runner.className;
  794. var elementEvents = angular.element._data(runner.node);
  795. elementEvents = elementEvents && elementEvents.events;
  796. if (!parentElement) {
  797. parentElement = afterElement ? afterElement.parent() : element.parent();
  798. }
  799. var ngAnimateState = element.data(NG_ANIMATE_STATE) || {};
  800. var runningAnimations = ngAnimateState.active || {};
  801. var totalActiveAnimations = ngAnimateState.totalActive || 0;
  802. var lastAnimation = ngAnimateState.last;
  803. //only allow animations if the currently running animation is not structural
  804. //or if there is no animation running at all
  805. var skipAnimations;
  806. if (runner.isClassBased) {
  807. skipAnimations = ngAnimateState.running ||
  808. ngAnimateState.disabled ||
  809. (lastAnimation && !lastAnimation.isClassBased);
  810. }
  811. //skip the animation if animations are disabled, a parent is already being animated,
  812. //the element is not currently attached to the document body or then completely close
  813. //the animation if any matching animations are not found at all.
  814. //NOTE: IE8 + IE9 should close properly (run closeAnimation()) in case an animation was found.
  815. if (skipAnimations || animationsDisabled(element, parentElement)) {
  816. fireDOMOperation();
  817. fireBeforeCallbackAsync();
  818. fireAfterCallbackAsync();
  819. closeAnimation();
  820. return;
  821. }
  822. var skipAnimation = false;
  823. if(totalActiveAnimations > 0) {
  824. var animationsToCancel = [];
  825. if(!runner.isClassBased) {
  826. if(animationEvent == 'leave' && runningAnimations['ng-leave']) {
  827. skipAnimation = true;
  828. } else {
  829. //cancel all animations when a structural animation takes place
  830. for(var klass in runningAnimations) {
  831. animationsToCancel.push(runningAnimations[klass]);
  832. cleanup(element, klass);
  833. }
  834. runningAnimations = {};
  835. totalActiveAnimations = 0;
  836. }
  837. } else if(lastAnimation.event == 'setClass') {
  838. animationsToCancel.push(lastAnimation);
  839. cleanup(element, className);
  840. }
  841. else if(runningAnimations[className]) {
  842. var current = runningAnimations[className];
  843. if(current.event == animationEvent) {
  844. skipAnimation = true;
  845. } else {
  846. animationsToCancel.push(current);
  847. cleanup(element, className);
  848. }
  849. }
  850. if(animationsToCancel.length > 0) {
  851. forEach(animationsToCancel, function(operation) {
  852. operation.cancel();
  853. });
  854. }
  855. }
  856. if(runner.isClassBased && !runner.isSetClassOperation && !skipAnimation) {
  857. skipAnimation = (animationEvent == 'addClass') == element.hasClass(className); //opposite of XOR
  858. }
  859. if(skipAnimation) {
  860. fireDOMOperation();
  861. fireBeforeCallbackAsync();
  862. fireAfterCallbackAsync();
  863. fireDoneCallbackAsync();
  864. return;
  865. }
  866. if(animationEvent == 'leave') {
  867. //there's no need to ever remove the listener since the element
  868. //will be removed (destroyed) after the leave animation ends or
  869. //is cancelled midway
  870. element.one('$destroy', function(e) {
  871. var element = angular.element(this);
  872. var state = element.data(NG_ANIMATE_STATE);
  873. if(state) {
  874. var activeLeaveAnimation = state.active['ng-leave'];
  875. if(activeLeaveAnimation) {
  876. activeLeaveAnimation.cancel();
  877. cleanup(element, 'ng-leave');
  878. }
  879. }
  880. });
  881. }
  882. //the ng-animate class does nothing, but it's here to allow for
  883. //parent animations to find and cancel child animations when needed
  884. element.addClass(NG_ANIMATE_CLASS_NAME);
  885. var localAnimationCount = globalAnimationCounter++;
  886. totalActiveAnimations++;
  887. runningAnimations[className] = runner;
  888. element.data(NG_ANIMATE_STATE, {
  889. last : runner,
  890. active : runningAnimations,
  891. index : localAnimationCount,
  892. totalActive : totalActiveAnimations
  893. });
  894. //first we run the before animations and when all of those are complete
  895. //then we perform the DOM operation and run the next set of animations
  896. fireBeforeCallbackAsync();
  897. runner.before(function(cancelled) {
  898. var data = element.data(NG_ANIMATE_STATE);
  899. cancelled = cancelled ||
  900. !data || !data.active[className] ||
  901. (runner.isClassBased && data.active[className].event != animationEvent);
  902. fireDOMOperation();
  903. if(cancelled === true) {
  904. closeAnimation();
  905. } else {
  906. fireAfterCallbackAsync();
  907. runner.after(closeAnimation);
  908. }
  909. });
  910. function fireDOMCallback(animationPhase) {
  911. var eventName = '$animate:' + animationPhase;
  912. if(elementEvents && elementEvents[eventName] && elementEvents[eventName].length > 0) {
  913. $$asyncCallback(function() {
  914. element.triggerHandler(eventName, {
  915. event : animationEvent,
  916. className : className
  917. });
  918. });
  919. }
  920. }
  921. function fireBeforeCallbackAsync() {
  922. fireDOMCallback('before');
  923. }
  924. function fireAfterCallbackAsync() {
  925. fireDOMCallback('after');
  926. }
  927. function fireDoneCallbackAsync() {
  928. fireDOMCallback('close');
  929. if(doneCallback) {
  930. $$asyncCallback(function() {
  931. doneCallback();
  932. });
  933. }
  934. }
  935. //it is less complicated to use a flag than managing and canceling
  936. //timeouts containing multiple callbacks.
  937. function fireDOMOperation() {
  938. if(!fireDOMOperation.hasBeenRun) {
  939. fireDOMOperation.hasBeenRun = true;
  940. domOperation();
  941. }
  942. }
  943. function closeAnimation() {
  944. if(!closeAnimation.hasBeenRun) {
  945. closeAnimation.hasBeenRun = true;
  946. var data = element.data(NG_ANIMATE_STATE);
  947. if(data) {
  948. /* only structural animations wait for reflow before removing an
  949. animation, but class-based animations don't. An example of this
  950. failing would be when a parent HTML tag has a ng-class attribute
  951. causing ALL directives below to skip animations during the digest */
  952. if(runner && runner.isClassBased) {
  953. cleanup(element, className);
  954. } else {
  955. $$asyncCallback(function() {
  956. var data = element.data(NG_ANIMATE_STATE) || {};
  957. if(localAnimationCount == data.index) {
  958. cleanup(element, className, animationEvent);
  959. }
  960. });
  961. element.data(NG_ANIMATE_STATE, data);
  962. }
  963. }
  964. fireDoneCallbackAsync();
  965. }
  966. }
  967. }
  968. function cancelChildAnimations(element) {
  969. var node = extractElementNode(element);
  970. if (node) {
  971. var nodes = angular.isFunction(node.getElementsByClassName) ?
  972. node.getElementsByClassName(NG_ANIMATE_CLASS_NAME) :
  973. node.querySelectorAll('.' + NG_ANIMATE_CLASS_NAME);
  974. forEach(nodes, function(element) {
  975. element = angular.element(element);
  976. var data = element.data(NG_ANIMATE_STATE);
  977. if(data && data.active) {
  978. forEach(data.active, function(runner) {
  979. runner.cancel();
  980. });
  981. }
  982. });
  983. }
  984. }
  985. function cleanup(element, className) {
  986. if(isMatchingElement(element, $rootElement)) {
  987. if(!rootAnimateState.disabled) {
  988. rootAnimateState.running = false;
  989. rootAnimateState.structural = false;
  990. }
  991. } else if(className) {
  992. var data = element.data(NG_ANIMATE_STATE) || {};
  993. var removeAnimations = className === true;
  994. if(!removeAnimations && data.active && data.active[className]) {
  995. data.totalActive--;
  996. delete data.active[className];
  997. }
  998. if(removeAnimations || !data.totalActive) {
  999. element.removeClass(NG_ANIMATE_CLASS_NAME);
  1000. element.removeData(NG_ANIMATE_STATE);
  1001. }
  1002. }
  1003. }
  1004. function animationsDisabled(element, parentElement) {
  1005. if (rootAnimateState.disabled) {
  1006. return true;
  1007. }
  1008. if (isMatchingElement(element, $rootElement)) {
  1009. return rootAnimateState.running;
  1010. }
  1011. var allowChildAnimations, parentRunningAnimation, hasParent;
  1012. do {
  1013. //the element did not reach the root element which means that it
  1014. //is not apart of the DOM. Therefore there is no reason to do
  1015. //any animations on it
  1016. if (parentElement.length === 0) break;
  1017. var isRoot = isMatchingElement(parentElement, $rootElement);
  1018. var state = isRoot ? rootAnimateState : (parentElement.data(NG_ANIMATE_STATE) || {});
  1019. if (state.disabled) {
  1020. return true;
  1021. }
  1022. //no matter what, for an animation to work it must reach the root element
  1023. //this implies that the element is attached to the DOM when the animation is run
  1024. if (isRoot) {
  1025. hasParent = true;
  1026. }
  1027. //once a flag is found that is strictly false then everything before
  1028. //it will be discarded and all child animations will be restricted
  1029. if (allowChildAnimations !== false) {
  1030. var animateChildrenFlag = parentElement.data(NG_ANIMATE_CHILDREN);
  1031. if(angular.isDefined(animateChildrenFlag)) {
  1032. allowChildAnimations = animateChildrenFlag;
  1033. }
  1034. }
  1035. parentRunningAnimation = parentRunningAnimation ||
  1036. state.running ||
  1037. (state.last && !state.last.isClassBased);
  1038. }
  1039. while(parentElement = parentElement.parent());
  1040. return !hasParent || (!allowChildAnimations && parentRunningAnimation);
  1041. }
  1042. }]);
  1043. $animateProvider.register('', ['$window', '$sniffer', '$timeout', '$$animateReflow',
  1044. function($window, $sniffer, $timeout, $$animateReflow) {
  1045. // Detect proper transitionend/animationend event names.
  1046. var CSS_PREFIX = '', TRANSITION_PROP, TRANSITIONEND_EVENT, ANIMATION_PROP, ANIMATIONEND_EVENT;
  1047. // If unprefixed events are not supported but webkit-prefixed are, use the latter.
  1048. // Otherwise, just use W3C names, browsers not supporting them at all will just ignore them.
  1049. // Note: Chrome implements `window.onwebkitanimationend` and doesn't implement `window.onanimationend`
  1050. // but at the same time dispatches the `animationend` event and not `webkitAnimationEnd`.
  1051. // Register both events in case `window.onanimationend` is not supported because of that,
  1052. // do the same for `transitionend` as Safari is likely to exhibit similar behavior.
  1053. // Also, the only modern browser that uses vendor prefixes for transitions/keyframes is webkit
  1054. // therefore there is no reason to test anymore for other vendor prefixes: http://caniuse.com/#search=transition
  1055. if (window.ontransitionend === undefined && window.onwebkittransitionend !== undefined) {
  1056. CSS_PREFIX = '-webkit-';
  1057. TRANSITION_PROP = 'WebkitTransition';
  1058. TRANSITIONEND_EVENT = 'webkitTransitionEnd transitionend';
  1059. } else {
  1060. TRANSITION_PROP = 'transition';
  1061. TRANSITIONEND_EVENT = 'transitionend';
  1062. }
  1063. if (window.onanimationend === undefined && window.onwebkitanimationend !== undefined) {
  1064. CSS_PREFIX = '-webkit-';
  1065. ANIMATION_PROP = 'WebkitAnimation';
  1066. ANIMATIONEND_EVENT = 'webkitAnimationEnd animationend';
  1067. } else {
  1068. ANIMATION_PROP = 'animation';
  1069. ANIMATIONEND_EVENT = 'animationend';
  1070. }
  1071. var DURATION_KEY = 'Duration';
  1072. var PROPERTY_KEY = 'Property';
  1073. var DELAY_KEY = 'Delay';
  1074. var ANIMATION_ITERATION_COUNT_KEY = 'IterationCount';
  1075. var NG_ANIMATE_PARENT_KEY = '$$ngAnimateKey';
  1076. var NG_ANIMATE_CSS_DATA_KEY = '$$ngAnimateCSS3Data';
  1077. var NG_ANIMATE_BLOCK_CLASS_NAME = 'ng-animate-block-transitions';
  1078. var ELAPSED_TIME_MAX_DECIMAL_PLACES = 3;
  1079. var CLOSING_TIME_BUFFER = 1.5;
  1080. var ONE_SECOND = 1000;
  1081. var lookupCache = {};
  1082. var parentCounter = 0;
  1083. var animationReflowQueue = [];
  1084. var cancelAnimationReflow;
  1085. function clearCacheAfterReflow() {
  1086. if (!cancelAnimationReflow) {
  1087. cancelAnimationReflow = $$animateReflow(function() {
  1088. animationReflowQueue = [];
  1089. cancelAnimationReflow = null;
  1090. lookupCache = {};
  1091. });
  1092. }
  1093. }
  1094. function afterReflow(element, callback) {
  1095. if(cancelAnimationReflow) {
  1096. cancelAnimationReflow();
  1097. }
  1098. animationReflowQueue.push(callback);
  1099. cancelAnimationReflow = $$animateReflow(function() {
  1100. forEach(animationReflowQueue, function(fn) {
  1101. fn();
  1102. });
  1103. animationReflowQueue = [];
  1104. cancelAnimationReflow = null;
  1105. lookupCache = {};
  1106. });
  1107. }
  1108. var closingTimer = null;
  1109. var closingTimestamp = 0;
  1110. var animationElementQueue = [];
  1111. function animationCloseHandler(element, totalTime) {
  1112. var node = extractElementNode(element);
  1113. element = angular.element(node);
  1114. //this item will be garbage collected by the closing
  1115. //animation timeout
  1116. animationElementQueue.push(element);
  1117. //but it may not need to cancel out the existing timeout
  1118. //if the timestamp is less than the previous one
  1119. var futureTimestamp = Date.now() + totalTime;
  1120. if(futureTimestamp <= closingTimestamp) {
  1121. return;
  1122. }
  1123. $timeout.cancel(closingTimer);
  1124. closingTimestamp = futureTimestamp;
  1125. closingTimer = $timeout(function() {
  1126. closeAllAnimations(animationElementQueue);
  1127. animationElementQueue = [];
  1128. }, totalTime, false);
  1129. }
  1130. function closeAllAnimations(elements) {
  1131. forEach(elements, function(element) {
  1132. var elementData = element.data(NG_ANIMATE_CSS_DATA_KEY);
  1133. if(elementData) {
  1134. (elementData.closeAnimationFn || noop)();
  1135. }
  1136. });
  1137. }
  1138. function getElementAnimationDetails(element, cacheKey) {
  1139. var data = cacheKey ? lookupCache[cacheKey] : null;
  1140. if(!data) {
  1141. var transitionDuration = 0;
  1142. var transitionDelay = 0;
  1143. var animationDuration = 0;
  1144. var animationDelay = 0;
  1145. var transitionDelayStyle;
  1146. var animationDelayStyle;
  1147. var transitionDurationStyle;
  1148. var transitionPropertyStyle;
  1149. //we want all the styles defined before and after
  1150. forEach(element, function(element) {
  1151. if (element.nodeType == ELEMENT_NODE) {
  1152. var elementStyles = $window.getComputedStyle(element) || {};
  1153. transitionDurationStyle = elementStyles[TRANSITION_PROP + DURATION_KEY];
  1154. transitionDuration = Math.max(parseMaxTime(transitionDurationStyle), transitionDuration);
  1155. transitionPropertyStyle = elementStyles[TRANSITION_PROP + PROPERTY_KEY];
  1156. transitionDelayStyle = elementStyles[TRANSITION_PROP + DELAY_KEY];
  1157. transitionDelay = Math.max(parseMaxTime(transitionDelayStyle), transitionDelay);
  1158. animationDelayStyle = elementStyles[ANIMATION_PROP + DELAY_KEY];
  1159. animationDelay = Math.max(parseMaxTime(animationDelayStyle), animationDelay);
  1160. var aDuration = parseMaxTime(elementStyles[ANIMATION_PROP + DURATION_KEY]);
  1161. if(aDuration > 0) {
  1162. aDuration *= parseInt(elementStyles[ANIMATION_PROP + ANIMATION_ITERATION_COUNT_KEY], 10) || 1;
  1163. }
  1164. animationDuration = Math.max(aDuration, animationDuration);
  1165. }
  1166. });
  1167. data = {
  1168. total : 0,
  1169. transitionPropertyStyle: transitionPropertyStyle,
  1170. transitionDurationStyle: transitionDurationStyle,
  1171. transitionDelayStyle: transitionDelayStyle,
  1172. transitionDelay: transitionDelay,
  1173. transitionDuration: transitionDuration,
  1174. animationDelayStyle: animationDelayStyle,
  1175. animationDelay: animationDelay,
  1176. animationDuration: animationDuration
  1177. };
  1178. if(cacheKey) {
  1179. lookupCache[cacheKey] = data;
  1180. }
  1181. }
  1182. return data;
  1183. }
  1184. function parseMaxTime(str) {
  1185. var maxValue = 0;
  1186. var values = angular.isString(str) ?
  1187. str.split(/\s*,\s*/) :
  1188. [];
  1189. forEach(values, function(value) {
  1190. maxValue = Math.max(parseFloat(value) || 0, maxValue);
  1191. });
  1192. return maxValue;
  1193. }
  1194. function getCacheKey(element) {
  1195. var parentElement = element.parent();
  1196. var parentID = parentElement.data(NG_ANIMATE_PARENT_KEY);
  1197. if(!parentID) {
  1198. parentElement.data(NG_ANIMATE_PARENT_KEY, ++parentCounter);
  1199. parentID = parentCounter;
  1200. }
  1201. return parentID + '-' + extractElementNode(element).getAttribute('class');
  1202. }
  1203. function animateSetup(animationEvent, element, className, calculationDecorator) {
  1204. var cacheKey = getCacheKey(element);
  1205. var eventCacheKey = cacheKey + ' ' + className;
  1206. var itemIndex = lookupCache[eventCacheKey] ? ++lookupCache[eventCacheKey].total : 0;
  1207. var stagger = {};
  1208. if(itemIndex > 0) {
  1209. var staggerClassName = className + '-stagger';
  1210. var staggerCacheKey = cacheKey + ' ' + staggerClassName;
  1211. var applyClasses = !lookupCache[staggerCacheKey];
  1212. applyClasses && element.addClass(staggerClassName);
  1213. stagger = getElementAnimationDetails(element, staggerCacheKey);
  1214. applyClasses && element.removeClass(staggerClassName);
  1215. }
  1216. /* the animation itself may need to add/remove special CSS classes
  1217. * before calculating the anmation styles */
  1218. calculationDecorator = calculationDecorator ||
  1219. function(fn) { return fn(); };
  1220. element.addClass(className);
  1221. var formerData = element.data(NG_ANIMATE_CSS_DATA_KEY) || {};
  1222. var timings = calculationDecorator(function() {
  1223. return getElementAnimationDetails(element, eventCacheKey);
  1224. });
  1225. var transitionDuration = timings.transitionDuration;
  1226. var animationDuration = timings.animationDuration;
  1227. if(transitionDuration === 0 && animationDuration === 0) {
  1228. element.removeClass(className);
  1229. return false;
  1230. }
  1231. element.data(NG_ANIMATE_CSS_DATA_KEY, {
  1232. running : formerData.running || 0,
  1233. itemIndex : itemIndex,
  1234. stagger : stagger,
  1235. timings : timings,
  1236. closeAnimationFn : noop
  1237. });
  1238. //temporarily disable the transition so that the enter styles
  1239. //don't animate twice (this is here to avoid a bug in Chrome/FF).
  1240. var isCurrentlyAnimating = formerData.running > 0 || animationEvent == 'setClass';
  1241. if(transitionDuration > 0) {
  1242. blockTransitions(element, className, isCurrentlyAnimating);
  1243. }
  1244. //staggering keyframe animations work by adjusting the `animation-delay` CSS property
  1245. //on the given element, however, the delay value can only calculated after the reflow
  1246. //since by that time $animate knows how many elements are being animated. Therefore,
  1247. //until the reflow occurs the element needs to be blocked (where the keyframe animation
  1248. //is set to `none 0s`). This blocking mechanism should only be set for when a stagger
  1249. //animation is detected and when the element item index is greater than 0.
  1250. if(animationDuration > 0 && stagger.animationDelay > 0 && stagger.animationDuration === 0) {
  1251. blockKeyframeAnimations(element);
  1252. }
  1253. return true;
  1254. }
  1255. function isStructuralAnimation(className) {
  1256. return className == 'ng-enter' || className == 'ng-move' || className == 'ng-leave';
  1257. }
  1258. function blockTransitions(element, className, isAnimating) {
  1259. if(isStructuralAnimation(className) || !isAnimating) {
  1260. extractElementNode(element).style[TRANSITION_PROP + PROPERTY_KEY] = 'none';
  1261. } else {
  1262. element.addClass(NG_ANIMATE_BLOCK_CLASS_NAME);
  1263. }
  1264. }
  1265. function blockKeyframeAnimations(element) {
  1266. extractElementNode(element).style[ANIMATION_PROP] = 'none 0s';
  1267. }
  1268. function unblockTransitions(element, className) {
  1269. var prop = TRANSITION_PROP + PROPERTY_KEY;
  1270. var node = extractElementNode(element);
  1271. if(node.style[prop] && node.style[prop].length > 0) {
  1272. node.style[prop] = '';
  1273. }
  1274. element.removeClass(NG_ANIMATE_BLOCK_CLASS_NAME);
  1275. }
  1276. function unblockKeyframeAnimations(element) {
  1277. var prop = ANIMATION_PROP;
  1278. var node = extractElementNode(element);
  1279. if(node.style[prop] && node.style[prop].length > 0) {
  1280. node.style[prop] = '';
  1281. }
  1282. }
  1283. function animateRun(animationEvent, element, className, activeAnimationComplete) {
  1284. var node = extractElementNode(element);
  1285. var elementData = element.data(NG_ANIMATE_CSS_DATA_KEY);
  1286. if(node.getAttribute('class').indexOf(className) == -1 || !elementData) {
  1287. activeAnimationComplete();
  1288. return;
  1289. }
  1290. var activeClassName = '';
  1291. forEach(className.split(' '), function(klass, i) {
  1292. activeClassName += (i > 0 ? ' ' : '') + klass + '-active';
  1293. });
  1294. var stagger = elementData.stagger;
  1295. var timings = elementData.timings;
  1296. var itemIndex = elementData.itemIndex;
  1297. var maxDuration = Math.max(timings.transitionDuration, timings.animationDuration);
  1298. var maxDelay = Math.max(timings.transitionDelay, timings.animationDelay);
  1299. var maxDelayTime = maxDelay * ONE_SECOND;
  1300. var startTime = Date.now();
  1301. var css3AnimationEvents = ANIMATIONEND_EVENT + ' ' + TRANSITIONEND_EVENT;
  1302. var style = '', appliedStyles = [];
  1303. if(timings.transitionDuration > 0) {
  1304. var propertyStyle = timings.transitionPropertyStyle;
  1305. if(propertyStyle.indexOf('all') == -1) {
  1306. style += CSS_PREFIX + 'transition-property: ' + propertyStyle + ';';
  1307. style += CSS_PREFIX + 'transition-duration: ' + timings.transitionDurationStyle + ';';
  1308. appliedStyles.push(CSS_PREFIX + 'transition-property');
  1309. appliedStyles.push(CSS_PREFIX + 'transition-duration');
  1310. }
  1311. }
  1312. if(itemIndex > 0) {
  1313. if(stagger.transitionDelay > 0 && stagger.transitionDuration === 0) {
  1314. var delayStyle = timings.transitionDelayStyle;
  1315. style += CSS_PREFIX + 'transition-delay: ' +
  1316. prepareStaggerDelay(delayStyle, stagger.transitionDelay, itemIndex) + '; ';
  1317. appliedStyles.push(CSS_PREFIX + 'transition-delay');
  1318. }
  1319. if(stagger.animationDelay > 0 && stagger.animationDuration === 0) {
  1320. style += CSS_PREFIX + 'animation-delay: ' +
  1321. prepareStaggerDelay(timings.animationDelayStyle, stagger.animationDelay, itemIndex) + '; ';
  1322. appliedStyles.push(CSS_PREFIX + 'animation-delay');
  1323. }
  1324. }
  1325. if(appliedStyles.length > 0) {
  1326. //the element being animated may sometimes contain comment nodes in
  1327. //the jqLite object, so we're safe to use a single variable to house
  1328. //the styles since there is always only one element being animated
  1329. var oldStyle = node.getAttribute('style') || '';
  1330. node.setAttribute('style', oldStyle + '; ' + style);
  1331. }
  1332. element.on(css3AnimationEvents, onAnimationProgress);
  1333. element.addClass(activeClassName);
  1334. elementData.closeAnimationFn = function() {
  1335. onEnd();
  1336. activeAnimationComplete();
  1337. };
  1338. var staggerTime = itemIndex * (Math.max(stagger.animationDelay, stagger.transitionDelay) || 0);
  1339. var animationTime = (maxDelay + maxDuration) * CLOSING_TIME_BUFFER;
  1340. var totalTime = (staggerTime + animationTime) * ONE_SECOND;
  1341. elementData.running++;
  1342. animationCloseHandler(element, totalTime);
  1343. return onEnd;
  1344. // This will automatically be called by $animate so
  1345. // there is no need to attach this internally to the
  1346. // timeout done method.
  1347. function onEnd(cancelled) {
  1348. element.off(css3AnimationEvents, onAnimationProgress);
  1349. element.removeClass(activeClassName);
  1350. animateClose(element, className);
  1351. var node = extractElementNode(element);
  1352. for (var i in appliedStyles) {
  1353. node.style.removeProperty(appliedStyles[i]);
  1354. }
  1355. }
  1356. function onAnimationProgress(event) {
  1357. event.stopPropagation();
  1358. var ev = event.originalEvent || event;
  1359. var timeStamp = ev.$manualTimeStamp || Date.now();
  1360. /* Firefox (or possibly just Gecko) likes to not round values up
  1361. * when a ms measurement is used for the animation */
  1362. var elapsedTime = parseFloat(ev.elapsedTime.toFixed(ELAPSED_TIME_MAX_DECIMAL_PLACES));
  1363. /* $manualTimeStamp is a mocked timeStamp value which is set
  1364. * within browserTrigger(). This is only here so that tests can
  1365. * mock animations properly. Real events fallback to Date.now(),
  1366. * or, if they don't, then a timeStamp is automatically created for them.
  1367. * We're checking to see if the timeStamp surpasses the expected delay,
  1368. * but we're using elapsedTime instead of the timeStamp on the 2nd
  1369. * pre-condition since animations sometimes close off early */
  1370. if(Math.max(timeStamp - startTime, 0) >= maxDelayTime && elapsedTime >= maxDuration) {
  1371. activeAnimationComplete();
  1372. }
  1373. }
  1374. }
  1375. function prepareStaggerDelay(delayStyle, staggerDelay, index) {
  1376. var style = '';
  1377. forEach(delayStyle.split(','), function(val, i) {
  1378. style += (i > 0 ? ',' : '') +
  1379. (index * staggerDelay + parseInt(val, 10)) + 's';
  1380. });
  1381. return style;
  1382. }
  1383. function animateBefore(animationEvent, element, className, calculationDecorator) {
  1384. if(animateSetup(animationEvent, element, className, calculationDecorator)) {
  1385. return function(cancelled) {
  1386. cancelled && animateClose(element, className);
  1387. };
  1388. }
  1389. }
  1390. function animateAfter(animationEvent, element, className, afterAnimationComplete) {
  1391. if(element.data(NG_ANIMATE_CSS_DATA_KEY)) {
  1392. return animateRun(animationEvent, element, className, afterAnimationComplete);
  1393. } else {
  1394. animateClose(element, className);
  1395. afterAnimationComplete();
  1396. }
  1397. }
  1398. function animate(animationEvent, element, className, animationComplete) {
  1399. //If the animateSetup function doesn't bother returning a
  1400. //cancellation function then it means that there is no animation
  1401. //to perform at all
  1402. var preReflowCancellation = animateBefore(animationEvent, element, className);
  1403. if (!preReflowCancellation) {
  1404. clearCacheAfterReflow();
  1405. animationComplete();
  1406. return;
  1407. }
  1408. //There are two cancellation functions: one is before the first
  1409. //reflow animation and the second is during the active state
  1410. //animation. The first function will take care of removing the
  1411. //data from the element which will not make the 2nd animation
  1412. //happen in the first place
  1413. var cancel = preReflowCancellation;
  1414. afterReflow(element, function() {
  1415. unblockTransitions(element, className);
  1416. unblockKeyframeAnimations(element);
  1417. //once the reflow is complete then we point cancel to
  1418. //the new cancellation function which will remove all of the
  1419. //animation properties from the active animation
  1420. cancel = animateAfter(animationEvent, element, className, animationComplete);
  1421. });
  1422. return function(cancelled) {
  1423. (cancel || noop)(cancelled);
  1424. };
  1425. }
  1426. function animateClose(element, className) {
  1427. element.removeClass(className);
  1428. var data = element.data(NG_ANIMATE_CSS_DATA_KEY);
  1429. if(data) {
  1430. if(data.running) {
  1431. data.running--;
  1432. }
  1433. if(!data.running || data.running === 0) {
  1434. element.removeData(NG_ANIMATE_CSS_DATA_KEY);
  1435. }
  1436. }
  1437. }
  1438. return {
  1439. enter : function(element, animationCompleted) {
  1440. return animate('enter', element, 'ng-enter', animationCompleted);
  1441. },
  1442. leave : function(element, animationCompleted) {
  1443. return animate('leave', element, 'ng-leave', animationCompleted);
  1444. },
  1445. move : function(element, animationCompleted) {
  1446. return animate('move', element, 'ng-move', animationCompleted);
  1447. },
  1448. beforeSetClass : function(element, add, remove, animationCompleted) {
  1449. var className = suffixClasses(remove, '-remove') + ' ' +
  1450. suffixClasses(add, '-add');
  1451. var cancellationMethod = animateBefore('setClass', element, className, function(fn) {
  1452. /* when classes are removed from an element then the transition style
  1453. * that is applied is the transition defined on the element without the
  1454. * CSS class being there. This is how CSS3 functions outside of ngAnimate.
  1455. * http://plnkr.co/edit/j8OzgTNxHTb4n3zLyjGW?p=preview */
  1456. var klass = element.attr('class');
  1457. element.removeClass(remove);
  1458. element.addClass(add);
  1459. var timings = fn();
  1460. element.attr('class', klass);
  1461. return timings;
  1462. });
  1463. if(cancellationMethod) {
  1464. afterReflow(element, function() {
  1465. unblockTransitions(element, className);
  1466. unblockKeyframeAnimations(element);
  1467. animationCompleted();
  1468. });
  1469. return cancellationMethod;
  1470. }
  1471. clearCacheAfterReflow();
  1472. animationCompleted();
  1473. },
  1474. beforeAddClass : function(element, className, animationCompleted) {
  1475. var cancellationMethod = animateBefore('addClass', element, suffixClasses(className, '-add'), function(fn) {
  1476. /* when a CSS class is added to an element then the transition style that
  1477. * is applied is the transition defined on the element when the CSS class
  1478. * is added at the time of the animation. This is how CSS3 functions
  1479. * outside of ngAnimate. */
  1480. element.addClass(className);
  1481. var timings = fn();
  1482. element.removeClass(className);
  1483. return timings;
  1484. });
  1485. if(cancellationMethod) {
  1486. afterReflow(element, function() {
  1487. unblockTransitions(element, className);
  1488. unblockKeyframeAnimations(element);
  1489. animationCompleted();
  1490. });
  1491. return cancellationMethod;
  1492. }
  1493. clearCacheAfterReflow();
  1494. animationCompleted();
  1495. },
  1496. setClass : function(element, add, remove, animationCompleted) {
  1497. remove = suffixClasses(remove, '-remove');
  1498. add = suffixClasses(add, '-add');
  1499. var className = remove + ' ' + add;
  1500. return animateAfter('setClass', element, className, animationCompleted);
  1501. },
  1502. addClass : function(element, className, animationCompleted) {
  1503. return animateAfter('addClass', element, suffixClasses(className, '-add'), animationCompleted);
  1504. },
  1505. beforeRemoveClass : function(element, className, animationCompleted) {
  1506. var cancellationMethod = animateBefore('removeClass', element, suffixClasses(className, '-remove'), function(fn) {
  1507. /* when classes are removed from an element then the transition style
  1508. * that is applied is the transition defined on the element without the
  1509. * CSS class being there. This is how CSS3 functions outside of ngAnimate.
  1510. * http://plnkr.co/edit/j8OzgTNxHTb4n3zLyjGW?p=preview */
  1511. var klass = element.attr('class');
  1512. element.removeClass(className);
  1513. var timings = fn();
  1514. element.attr('class', klass);
  1515. return timings;
  1516. });
  1517. if(cancellationMethod) {
  1518. afterReflow(element, function() {
  1519. unblockTransitions(element, className);
  1520. unblockKeyframeAnimations(element);
  1521. animationCompleted();
  1522. });
  1523. return cancellationMethod;
  1524. }
  1525. animationCompleted();
  1526. },
  1527. removeClass : function(element, className, animationCompleted) {
  1528. return animateAfter('removeClass', element, suffixClasses(className, '-remove'), animationCompleted);
  1529. }
  1530. };
  1531. function suffixClasses(classes, suffix) {
  1532. var className = '';
  1533. classes = angular.isArray(classes) ? classes : classes.split(/\s+/);
  1534. forEach(classes, function(klass, i) {
  1535. if(klass && klass.length > 0) {
  1536. className += (i > 0 ? ' ' : '') + klass + suffix;
  1537. }
  1538. });
  1539. return className;
  1540. }
  1541. }]);
  1542. }]);
  1543. })(window, window.angular);