@@ -1043,7 +1043,7 @@ angular.module('ngAnimate', ['ng'])
1043
1043
return parentID + '-' + extractElementNode ( element ) . className ;
1044
1044
}
1045
1045
1046
- function animateSetup ( element , className ) {
1046
+ function animateSetup ( element , className , calculationDecorator ) {
1047
1047
var cacheKey = getCacheKey ( element ) ;
1048
1048
var eventCacheKey = cacheKey + ' ' + className ;
1049
1049
var stagger = { } ;
@@ -1061,9 +1061,16 @@ angular.module('ngAnimate', ['ng'])
1061
1061
applyClasses && element . removeClass ( staggerClassName ) ;
1062
1062
}
1063
1063
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
+
1064
1069
element . addClass ( className ) ;
1065
1070
1066
- var timings = getElementAnimationDetails ( element , eventCacheKey ) ;
1071
+ var timings = calculationDecorator ( function ( ) {
1072
+ return getElementAnimationDetails ( element , eventCacheKey ) ;
1073
+ } ) ;
1067
1074
1068
1075
/* there is no point in performing a reflow if the animation
1069
1076
timeout is empty (this would cause a flicker bug normally
@@ -1228,8 +1235,8 @@ angular.module('ngAnimate', ['ng'])
1228
1235
return style ;
1229
1236
}
1230
1237
1231
- function animateBefore ( element , className ) {
1232
- if ( animateSetup ( element , className ) ) {
1238
+ function animateBefore ( element , className , calculationDecorator ) {
1239
+ if ( animateSetup ( element , className , calculationDecorator ) ) {
1233
1240
return function ( cancelled ) {
1234
1241
cancelled && animateClose ( element , className ) ;
1235
1242
} ;
@@ -1324,7 +1331,18 @@ angular.module('ngAnimate', ['ng'])
1324
1331
} ,
1325
1332
1326
1333
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
+
1328
1346
if ( cancellationMethod ) {
1329
1347
afterReflow ( element , function ( ) {
1330
1348
unblockTransitions ( element ) ;
@@ -1341,7 +1359,18 @@ angular.module('ngAnimate', ['ng'])
1341
1359
} ,
1342
1360
1343
1361
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
+
1345
1374
if ( cancellationMethod ) {
1346
1375
afterReflow ( element , function ( ) {
1347
1376
unblockTransitions ( element ) ;
0 commit comments