angular-animate.js 131 KB

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