@@ -377,6 +377,7 @@ angular.module('ngAnimate', ['ng'])
377
377
var forEach = angular . forEach ;
378
378
var selectors = $animateProvider . $$selectors ;
379
379
var isArray = angular . isArray ;
380
+ var isString = angular . isString ;
380
381
381
382
var ELEMENT_NODE = 1 ;
382
383
var NG_ANIMATE_STATE = '$$ngAnimateState' ;
@@ -467,6 +468,14 @@ angular.module('ngAnimate', ['ng'])
467
468
return defer . promise ;
468
469
}
469
470
471
+ function parseAnimateOptions ( options ) {
472
+ // some plugin code may still be passing in the callback
473
+ // function as the last param for the $animate methods so
474
+ // it's best to only allow string or array values for now
475
+ if ( isArray ( options ) ) return options ;
476
+ if ( isString ( options ) ) return [ options ] ;
477
+ }
478
+
470
479
function resolveElementClasses ( element , cache , runningAnimations ) {
471
480
runningAnimations = runningAnimations || { } ;
472
481
@@ -784,15 +793,16 @@ angular.module('ngAnimate', ['ng'])
784
793
* @param {DOMElement } afterElement the sibling element (which is the previous element) of the element that will be the focus of the enter animation
785
794
* @return {Promise } the animation callback promise
786
795
*/
787
- enter : function ( element , parentElement , afterElement ) {
796
+ enter : function ( element , parentElement , afterElement , options ) {
797
+ options = parseAnimateOptions ( options ) ;
788
798
element = angular . element ( element ) ;
789
799
parentElement = prepareElement ( parentElement ) ;
790
800
afterElement = prepareElement ( afterElement ) ;
791
801
792
802
classBasedAnimationsBlocked ( element , true ) ;
793
803
$delegate . enter ( element , parentElement , afterElement ) ;
794
804
return runAnimationPostDigest ( function ( done ) {
795
- return performAnimation ( 'enter' , 'ng-enter' , stripCommentsFromElement ( element ) , parentElement , afterElement , noop , done ) ;
805
+ return performAnimation ( 'enter' , 'ng-enter' , stripCommentsFromElement ( element ) , parentElement , afterElement , noop , options , done ) ;
796
806
} ) ;
797
807
} ,
798
808
@@ -826,15 +836,16 @@ angular.module('ngAnimate', ['ng'])
826
836
* @param {DOMElement } element the element that will be the focus of the leave animation
827
837
* @return {Promise } the animation callback promise
828
838
*/
829
- leave : function ( element ) {
839
+ leave : function ( element , options ) {
840
+ options = parseAnimateOptions ( options ) ;
830
841
element = angular . element ( element ) ;
831
842
832
843
cancelChildAnimations ( element ) ;
833
844
classBasedAnimationsBlocked ( element , true ) ;
834
845
return runAnimationPostDigest ( function ( done ) {
835
846
return performAnimation ( 'leave' , 'ng-leave' , stripCommentsFromElement ( element ) , null , null , function ( ) {
836
847
$delegate . leave ( element ) ;
837
- } , done ) ;
848
+ } , options , done ) ;
838
849
} ) ;
839
850
} ,
840
851
@@ -871,7 +882,8 @@ angular.module('ngAnimate', ['ng'])
871
882
* @param {DOMElement } afterElement the sibling element (which is the previous element) of the element that will be the focus of the move animation
872
883
* @return {Promise } the animation callback promise
873
884
*/
874
- move : function ( element , parentElement , afterElement ) {
885
+ move : function ( element , parentElement , afterElement , options ) {
886
+ options = parseAnimateOptions ( options ) ;
875
887
element = angular . element ( element ) ;
876
888
parentElement = prepareElement ( parentElement ) ;
877
889
afterElement = prepareElement ( afterElement ) ;
@@ -880,7 +892,7 @@ angular.module('ngAnimate', ['ng'])
880
892
classBasedAnimationsBlocked ( element , true ) ;
881
893
$delegate . move ( element , parentElement , afterElement ) ;
882
894
return runAnimationPostDigest ( function ( done ) {
883
- return performAnimation ( 'move' , 'ng-move' , stripCommentsFromElement ( element ) , parentElement , afterElement , noop , done ) ;
895
+ return performAnimation ( 'move' , 'ng-move' , stripCommentsFromElement ( element ) , parentElement , afterElement , noop , options , done ) ;
884
896
} ) ;
885
897
} ,
886
898
@@ -913,8 +925,8 @@ angular.module('ngAnimate', ['ng'])
913
925
* @param {string } className the CSS class that will be added to the element and then animated
914
926
* @return {Promise } the animation callback promise
915
927
*/
916
- addClass : function ( element , className ) {
917
- return this . setClass ( element , className , [ ] ) ;
928
+ addClass : function ( element , className , options ) {
929
+ return this . setClass ( element , className , [ ] , options ) ;
918
930
} ,
919
931
920
932
/**
@@ -946,8 +958,8 @@ angular.module('ngAnimate', ['ng'])
946
958
* @param {string } className the CSS class that will be animated and then removed from the element
947
959
* @return {Promise } the animation callback promise
948
960
*/
949
- removeClass : function ( element , className ) {
950
- return this . setClass ( element , [ ] , className ) ;
961
+ removeClass : function ( element , className , options ) {
962
+ return this . setClass ( element , [ ] , className , options ) ;
951
963
} ,
952
964
953
965
/**
@@ -977,7 +989,9 @@ angular.module('ngAnimate', ['ng'])
977
989
* CSS classes have been set on the element
978
990
* @return {Promise } the animation callback promise
979
991
*/
980
- setClass : function ( element , add , remove ) {
992
+ setClass : function ( element , add , remove , options ) {
993
+ options = parseAnimateOptions ( options ) ;
994
+
981
995
var STORAGE_KEY = '$$animateClasses' ;
982
996
element = angular . element ( element ) ;
983
997
element = stripCommentsFromElement ( element ) ;
@@ -1014,11 +1028,16 @@ angular.module('ngAnimate', ['ng'])
1014
1028
} ) ;
1015
1029
1016
1030
if ( hasCache ) {
1031
+ if ( options && cache . options ) {
1032
+ cache . options = cache . options . concat ( options ) ;
1033
+ }
1034
+
1017
1035
//the digest cycle will combine all the animations into one function
1018
1036
return cache . promise ;
1019
1037
} else {
1020
1038
element . data ( STORAGE_KEY , cache = {
1021
- classes : classes
1039
+ classes : classes ,
1040
+ options : options
1022
1041
} ) ;
1023
1042
}
1024
1043
@@ -1042,7 +1061,7 @@ angular.module('ngAnimate', ['ng'])
1042
1061
: performAnimation ( 'setClass' , classes , element , parentElement , null , function ( ) {
1043
1062
if ( classes [ 0 ] ) $delegate . $$addClassImmediately ( element , classes [ 0 ] ) ;
1044
1063
if ( classes [ 1 ] ) $delegate . $$removeClassImmediately ( element , classes [ 1 ] ) ;
1045
- } , done ) ;
1064
+ } , cache . options , done ) ;
1046
1065
} ) ;
1047
1066
} ,
1048
1067
@@ -1104,7 +1123,7 @@ angular.module('ngAnimate', ['ng'])
1104
1123
CSS code. Element, parentElement and afterElement are provided DOM elements for the animation
1105
1124
and the onComplete callback will be fired once the animation is fully complete.
1106
1125
*/
1107
- function performAnimation ( animationEvent , className , element , parentElement , afterElement , domOperation , doneCallback ) {
1126
+ function performAnimation ( animationEvent , className , element , parentElement , afterElement , domOperation , options , doneCallback ) {
1108
1127
1109
1128
var noopCancel = noop ;
1110
1129
var runner = animationRunner ( element , animationEvent , className ) ;
@@ -1212,6 +1231,11 @@ angular.module('ngAnimate', ['ng'])
1212
1231
//the ng-animate class does nothing, but it's here to allow for
1213
1232
//parent animations to find and cancel child animations when needed
1214
1233
element . addClass ( NG_ANIMATE_CLASS_NAME ) ;
1234
+ if ( isArray ( options ) ) {
1235
+ forEach ( options , function ( className ) {
1236
+ element . addClass ( className ) ;
1237
+ } ) ;
1238
+ }
1215
1239
1216
1240
var localAnimationCount = globalAnimationCounter ++ ;
1217
1241
totalActiveAnimations ++ ;
@@ -1281,8 +1305,15 @@ angular.module('ngAnimate', ['ng'])
1281
1305
function closeAnimation ( ) {
1282
1306
if ( ! closeAnimation . hasBeenRun ) {
1283
1307
closeAnimation . hasBeenRun = true ;
1308
+ if ( isArray ( options ) ) {
1309
+ forEach ( options , function ( className ) {
1310
+ element . removeClass ( className ) ;
1311
+ } ) ;
1312
+ }
1313
+
1284
1314
var data = element . data ( NG_ANIMATE_STATE ) ;
1285
1315
if ( data ) {
1316
+
1286
1317
/* only structural animations wait for reflow before removing an
1287
1318
animation, but class-based animations don't. An example of this
1288
1319
failing would be when a parent HTML tag has a ng-class attribute
@@ -1547,7 +1578,7 @@ angular.module('ngAnimate', ['ng'])
1547
1578
1548
1579
function parseMaxTime ( str ) {
1549
1580
var maxValue = 0 ;
1550
- var values = angular . isString ( str ) ?
1581
+ var values = isString ( str ) ?
1551
1582
str . split ( / \s * , \s * / ) :
1552
1583
[ ] ;
1553
1584
forEach ( values , function ( value ) {
0 commit comments