aboutsummaryrefslogtreecommitdiffstats
path: root/src/ngAnimate
diff options
context:
space:
mode:
authorMatias Niemelä2014-01-13 21:51:08 -0500
committerMatias Niemelä2014-01-14 13:21:28 -0500
commitdde1b2949727c297e214c99960141bfad438d7a4 (patch)
treea433c7813bacdf98fa04f075becec0604b0b155c /src/ngAnimate
parent4ae3184c5915aac9aa00889aa2153c8e84c14966 (diff)
downloadangular.js-dde1b2949727c297e214c99960141bfad438d7a4.tar.bz2
feat($animate): provide support for DOM callbacks
Diffstat (limited to 'src/ngAnimate')
-rw-r--r--src/ngAnimate/animate.js41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/ngAnimate/animate.js b/src/ngAnimate/animate.js
index 0417f18e..4f243220 100644
--- a/src/ngAnimate/animate.js
+++ b/src/ngAnimate/animate.js
@@ -317,6 +317,10 @@ angular.module('ngAnimate', ['ng'])
return classNameFilter.test(className);
};
+ function async(fn) {
+ return $timeout(fn, 0, false);
+ }
+
function lookup(name) {
if (name) {
var matches = [],
@@ -608,6 +612,8 @@ angular.module('ngAnimate', ['ng'])
//best to catch this early on to prevent any animation operations from occurring
if(!node || !isAnimatableClassName(classes)) {
fireDOMOperation();
+ fireBeforeCallbackAsync();
+ fireAfterCallbackAsync();
closeAnimation();
return;
}
@@ -627,6 +633,8 @@ angular.module('ngAnimate', ['ng'])
//NOTE: IE8 + IE9 should close properly (run closeAnimation()) in case a NO animation is not found.
if (animationsDisabled(element, parentElement) || matches.length === 0) {
fireDOMOperation();
+ fireBeforeCallbackAsync();
+ fireAfterCallbackAsync();
closeAnimation();
return;
}
@@ -665,6 +673,8 @@ angular.module('ngAnimate', ['ng'])
//animation do it's thing and close this one early
if(animations.length === 0) {
fireDOMOperation();
+ fireBeforeCallbackAsync();
+ fireAfterCallbackAsync();
fireDoneCallbackAsync();
return;
}
@@ -718,6 +728,8 @@ angular.module('ngAnimate', ['ng'])
if((animationEvent == 'addClass' && futureClassName.indexOf(classNameToken) >= 0) ||
(animationEvent == 'removeClass' && futureClassName.indexOf(classNameToken) == -1)) {
fireDOMOperation();
+ fireBeforeCallbackAsync();
+ fireAfterCallbackAsync();
fireDoneCallbackAsync();
return;
}
@@ -758,6 +770,10 @@ angular.module('ngAnimate', ['ng'])
}
function invokeRegisteredAnimationFns(animations, phase, allAnimationFnsComplete) {
+ phase == 'after' ?
+ fireAfterCallbackAsync() :
+ fireBeforeCallbackAsync();
+
var endFnName = phase + 'End';
forEach(animations, function(animation, index) {
var animationPhaseCompleted = function() {
@@ -794,8 +810,27 @@ angular.module('ngAnimate', ['ng'])
}
}
+ function fireDOMCallback(animationPhase) {
+ element.triggerHandler('$animate:' + animationPhase, {
+ event : animationEvent,
+ className : className
+ });
+ }
+
+ function fireBeforeCallbackAsync() {
+ async(function() {
+ fireDOMCallback('before');
+ });
+ }
+
+ function fireAfterCallbackAsync() {
+ async(function() {
+ fireDOMCallback('after');
+ });
+ }
+
function fireDoneCallbackAsync() {
- doneCallback && $timeout(doneCallback, 0, false);
+ doneCallback && async(doneCallback);
}
//it is less complicated to use a flag than managing and cancelling
@@ -819,9 +854,9 @@ angular.module('ngAnimate', ['ng'])
if(isClassBased) {
cleanup(element);
} else {
- data.closeAnimationTimeout = $timeout(function() {
+ data.closeAnimationTimeout = async(function() {
cleanup(element);
- }, 0, false);
+ });
element.data(NG_ANIMATE_STATE, data);
}
}