@@ -1043,7 +1043,7 @@ angular.module('ngAnimate', ['ng'])
10431043 return parentID + '-' + extractElementNode ( element ) . className ;
10441044 }
10451045
1046- function animateSetup ( element , className ) {
1046+ function animateSetup ( element , className , calculationDecorator ) {
10471047 var cacheKey = getCacheKey ( element ) ;
10481048 var eventCacheKey = cacheKey + ' ' + className ;
10491049 var stagger = { } ;
@@ -1061,9 +1061,16 @@ angular.module('ngAnimate', ['ng'])
10611061 applyClasses && element . removeClass ( staggerClassName ) ;
10621062 }
10631063
1064+ /* the animation itself may need to add/remove special CSS classes
1065+ * before calculating the anmation styles */
1066+ calculationDecorator = calculationDecorator ||
1067+ function ( fn ) { return fn ( ) ; } ;
1068+
10641069 element . addClass ( className ) ;
10651070
1066- var timings = getElementAnimationDetails ( element , eventCacheKey ) ;
1071+ var timings = calculationDecorator ( function ( ) {
1072+ return getElementAnimationDetails ( element , eventCacheKey ) ;
1073+ } ) ;
10671074
10681075 /* there is no point in performing a reflow if the animation
10691076 timeout is empty (this would cause a flicker bug normally
@@ -1228,8 +1235,8 @@ angular.module('ngAnimate', ['ng'])
12281235 return style ;
12291236 }
12301237
1231- function animateBefore ( element , className ) {
1232- if ( animateSetup ( element , className ) ) {
1238+ function animateBefore ( element , className , calculationDecorator ) {
1239+ if ( animateSetup ( element , className , calculationDecorator ) ) {
12331240 return function ( cancelled ) {
12341241 cancelled && animateClose ( element , className ) ;
12351242 } ;
@@ -1324,7 +1331,18 @@ angular.module('ngAnimate', ['ng'])
13241331 } ,
13251332
13261333 beforeAddClass : function ( element , className , animationCompleted ) {
1327- var cancellationMethod = animateBefore ( element , suffixClasses ( className , '-add' ) ) ;
1334+ var cancellationMethod = animateBefore ( element , suffixClasses ( className , '-add' ) , function ( fn ) {
1335+
1336+ /* when a CSS class is added to an element then the transition style that
1337+ * is applied is the transition defined on the element when the CSS class
1338+ * is added at the time of the animation. This is how CSS3 functions
1339+ * outside of ngAnimate. */
1340+ element . addClass ( className ) ;
1341+ var timings = fn ( ) ;
1342+ element . removeClass ( className ) ;
1343+ return timings ;
1344+ } ) ;
1345+
13281346 if ( cancellationMethod ) {
13291347 afterReflow ( element , function ( ) {
13301348 unblockTransitions ( element ) ;
@@ -1341,7 +1359,18 @@ angular.module('ngAnimate', ['ng'])
13411359 } ,
13421360
13431361 beforeRemoveClass : function ( element , className , animationCompleted ) {
1344- var cancellationMethod = animateBefore ( element , suffixClasses ( className , '-remove' ) ) ;
1362+ var cancellationMethod = animateBefore ( element , suffixClasses ( className , '-remove' ) , function ( fn ) {
1363+ /* when classes are removed from an element then the transition style
1364+ * that is applied is the transition defined on the element without the
1365+ * CSS class being there. This is how CSS3 functions outside of ngAnimate.
1366+ * http://plnkr.co/edit/j8OzgTNxHTb4n3zLyjGW?p=preview */
1367+ var klass = element . attr ( 'class' ) ;
1368+ element . removeClass ( className ) ;
1369+ var timings = fn ( ) ;
1370+ element . attr ( 'class' , klass ) ;
1371+ return timings ;
1372+ } ) ;
1373+
13451374 if ( cancellationMethod ) {
13461375 afterReflow ( element , function ( ) {
13471376 unblockTransitions ( element ) ;
0 commit comments