@@ -205,9 +205,9 @@ angular.module('ngAnimate', ['ng'])
205205 var ELEMENT_NODE = 1 ;
206206 var NG_ANIMATE_STATE = '$$ngAnimateState' ;
207207 var NG_ANIMATE_CLASS_NAME = 'ng-animate' ;
208- var rootAnimateState = { running :true } ;
209- $provide . decorator ( '$animate' , [ '$delegate' , '$injector' , '$sniffer' , '$rootElement' , '$timeout' , '$rootScope' ,
210- function ( $delegate , $injector , $sniffer , $rootElement , $timeout , $rootScope ) {
208+ var rootAnimateState = { disabled :true } ;
209+ $provide . decorator ( '$animate' , [ '$delegate' , '$injector' , '$sniffer' , '$rootElement' , '$timeout' , '$rootScope' , '$document' ,
210+ function ( $delegate , $injector , $sniffer , $rootElement , $timeout , $rootScope , $document ) {
211211
212212 $rootElement . data ( NG_ANIMATE_STATE , rootAnimateState ) ;
213213
@@ -466,18 +466,17 @@ angular.module('ngAnimate', ['ng'])
466466 }
467467 else {
468468 var data = element . data ( NG_ANIMATE_STATE ) || { } ;
469- data . structural = true ;
470- data . running = true ;
469+ data . disabled = true ;
471470 element . data ( NG_ANIMATE_STATE , data ) ;
472471 }
473472 break ;
474473
475474 case 1 :
476- rootAnimateState . running = ! value ;
475+ rootAnimateState . disabled = ! value ;
477476 break ;
478477
479478 default :
480- value = ! rootAnimateState . running ;
479+ value = ! rootAnimateState . disabled ;
481480 break ;
482481 }
483482 return ! ! value ;
@@ -498,7 +497,6 @@ angular.module('ngAnimate', ['ng'])
498497 parent = after ? after . parent ( ) : element . parent ( ) ;
499498 }
500499
501- var disabledAnimation = { running : true } ;
502500 var matches = lookup ( animationLookup ) ;
503501 var isClassBased = event == 'addClass' || event == 'removeClass' ;
504502 var ngAnimateState = element . data ( NG_ANIMATE_STATE ) || { } ;
@@ -507,7 +505,7 @@ angular.module('ngAnimate', ['ng'])
507505 //the element is not currently attached to the document body or then completely close
508506 //the animation if any matching animations are not found at all.
509507 //NOTE: IE8 + IE9 should close properly (run done()) in case a NO animation is not found.
510- if ( ( parent . inheritedData ( NG_ANIMATE_STATE ) || disabledAnimation ) . running || matches . length == 0 ) {
508+ if ( animationsDisabled ( element , parent ) || matches . length = == 0 ) {
511509 done ( ) ;
512510 return ;
513511 }
@@ -528,7 +526,7 @@ angular.module('ngAnimate', ['ng'])
528526
529527 //this would mean that an animation was not allowed so let the existing
530528 //animation do it's thing and close this one early
531- if ( animations . length == 0 ) {
529+ if ( animations . length === 0 ) {
532530 onComplete && onComplete ( ) ;
533531 return ;
534532 }
@@ -622,8 +620,39 @@ angular.module('ngAnimate', ['ng'])
622620 }
623621
624622 function cleanup ( element ) {
625- element . removeClass ( NG_ANIMATE_CLASS_NAME ) ;
626- element . removeData ( NG_ANIMATE_STATE ) ;
623+ if ( element [ 0 ] == $rootElement [ 0 ] ) {
624+ if ( ! rootAnimateState . disabled ) {
625+ rootAnimateState . running = false ;
626+ rootAnimateState . structural = false ;
627+ }
628+ }
629+ else {
630+ element . removeClass ( NG_ANIMATE_CLASS_NAME ) ;
631+ element . removeData ( NG_ANIMATE_STATE ) ;
632+ }
633+ }
634+
635+ function animationsDisabled ( element , parent ) {
636+ if ( element == $rootElement ) {
637+ return rootAnimateState . disabled || rootAnimateState . running ;
638+ }
639+
640+ var validState ;
641+ do {
642+ //the element did not reach the root element which means that it
643+ //is not apart of the DOM. Therefore there is no reason to do
644+ //any animations on it
645+ if ( parent . length === 0 || parent [ 0 ] == $document [ 0 ] ) return true ;
646+
647+ var state = parent . data ( NG_ANIMATE_STATE ) ;
648+ if ( state && ( state . disabled != null || state . running != null ) ) {
649+ validState = state ;
650+ break ;
651+ }
652+ }
653+ while ( parent = parent . parent ( ) ) ;
654+
655+ return validState ? ( validState . disabled || validState . running ) : true ;
627656 }
628657 } ] ) ;
629658
0 commit comments