@@ -12,6 +12,14 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
12
12
join : [ ]
13
13
} ;
14
14
15
+ function makeTruthyMapFromKeys ( keys ) {
16
+ var map = Object . create ( null ) ;
17
+ forEach ( keys , function ( key ) {
18
+ map [ key ] = true ;
19
+ } ) ;
20
+ return map ;
21
+ }
22
+
15
23
function isAllowed ( ruleType , element , currentAnimation , previousAnimation ) {
16
24
return rules [ ruleType ] . some ( function ( fn ) {
17
25
return fn ( element , currentAnimation , previousAnimation ) ;
@@ -59,11 +67,38 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
59
67
} ) ;
60
68
61
69
rules . cancel . push ( function ( element , newAnimation , currentAnimation ) {
62
- var nO = newAnimation . options ;
63
- var cO = currentAnimation . options ;
70
+ var ONE_SPACE = ' ' ;
71
+
72
+ var nA = newAnimation . options . addClass ;
73
+ var nR = newAnimation . options . removeClass ;
74
+ var cA = currentAnimation . options . addClass ;
75
+ var cR = currentAnimation . options . removeClass ;
76
+
77
+ // early detection to save the global CPU shortage :)
78
+ if ( ( ! isDefined ( nA ) && ! isDefined ( nR ) ) || ( ! isDefined ( cA ) && ! isDefined ( cR ) ) ) {
79
+ return false ;
80
+ }
81
+
82
+ var cancelSomething = false ;
83
+
84
+ cA = cA ? makeTruthyMapFromKeys ( cA . split ( ONE_SPACE ) ) : null ;
85
+ cR = cR ? makeTruthyMapFromKeys ( cR . split ( ONE_SPACE ) ) : null ;
86
+
87
+ if ( cR && nA ) {
88
+ cancelSomething = nA . split ( ONE_SPACE ) . some ( function ( className ) {
89
+ return cR [ className ] ;
90
+ } ) ;
91
+
92
+ if ( cancelSomething ) return true ;
93
+ }
94
+
95
+ if ( cA && nR ) {
96
+ cancelSomething = nR . split ( ONE_SPACE ) . some ( function ( className ) {
97
+ return cA [ className ] ;
98
+ } ) ;
99
+ }
64
100
65
- // if the exact same CSS class is added/removed then it's safe to cancel it
66
- return ( nO . addClass && nO . addClass === cO . removeClass ) || ( nO . removeClass && nO . removeClass === cO . addClass ) ;
101
+ return cancelSomething ;
67
102
} ) ;
68
103
69
104
this . $get = [ '$$rAF' , '$rootScope' , '$rootElement' , '$document' , '$$HashMap' ,
0 commit comments