@@ -5,13 +5,37 @@ var NG_ANIMATE_PIN_DATA = '$ngAnimatePin';
5
5
var $$AnimateQueueProvider = [ '$animateProvider' , function ( $animateProvider ) {
6
6
var PRE_DIGEST_STATE = 1 ;
7
7
var RUNNING_STATE = 2 ;
8
+ var ONE_SPACE = ' ' ;
8
9
9
10
var rules = this . rules = {
10
11
skip : [ ] ,
11
12
cancel : [ ] ,
12
13
join : [ ]
13
14
} ;
14
15
16
+ function makeTruthyCssClassMap ( classString ) {
17
+ if ( ! classString ) {
18
+ return null ;
19
+ }
20
+
21
+ var keys = classString . split ( ONE_SPACE ) ;
22
+ var map = Object . create ( null ) ;
23
+
24
+ forEach ( keys , function ( key ) {
25
+ map [ key ] = true ;
26
+ } ) ;
27
+ return map ;
28
+ }
29
+
30
+ function hasMatchingClasses ( newClassString , currentClassString ) {
31
+ if ( newClassString && currentClassString ) {
32
+ var currentClassMap = makeTruthyCssClassMap ( currentClassString ) ;
33
+ return newClassString . split ( ONE_SPACE ) . some ( function ( className ) {
34
+ return currentClassMap [ className ] ;
35
+ } ) ;
36
+ }
37
+ }
38
+
15
39
function isAllowed ( ruleType , element , currentAnimation , previousAnimation ) {
16
40
return rules [ ruleType ] . some ( function ( fn ) {
17
41
return fn ( element , currentAnimation , previousAnimation ) ;
@@ -59,11 +83,19 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
59
83
} ) ;
60
84
61
85
rules . cancel . push ( function ( element , newAnimation , currentAnimation ) {
62
- var nO = newAnimation . options ;
63
- var cO = currentAnimation . options ;
64
86
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 ) ;
87
+
88
+ var nA = newAnimation . options . addClass ;
89
+ var nR = newAnimation . options . removeClass ;
90
+ var cA = currentAnimation . options . addClass ;
91
+ var cR = currentAnimation . options . removeClass ;
92
+
93
+ // early detection to save the global CPU shortage :)
94
+ if ( ( isUndefined ( nA ) && isUndefined ( nR ) ) || ( isUndefined ( cA ) && isUndefined ( cR ) ) ) {
95
+ return false ;
96
+ }
97
+
98
+ return ( hasMatchingClasses ( nA , cR ) ) || ( hasMatchingClasses ( nR , cA ) ) ;
67
99
} ) ;
68
100
69
101
this . $get = [ '$$rAF' , '$rootScope' , '$rootElement' , '$document' , '$$HashMap' ,
0 commit comments