@@ -12,6 +12,14 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
1212 join : [ ]
1313 } ;
1414
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+
1523 function isAllowed ( ruleType , element , currentAnimation , previousAnimation ) {
1624 return rules [ ruleType ] . some ( function ( fn ) {
1725 return fn ( element , currentAnimation , previousAnimation ) ;
@@ -59,11 +67,38 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
5967 } ) ;
6068
6169 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+ }
64100
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 ;
67102 } ) ;
68103
69104 this . $get = [ '$$rAF' , '$rootScope' , '$rootElement' , '$document' , '$$HashMap' ,
0 commit comments