diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ng/directive/ngIf.js | 17 | ||||
| -rw-r--r-- | src/ng/directive/ngInclude.js | 12 | ||||
| -rw-r--r-- | src/ng/directive/ngSwitch.js | 25 | ||||
| -rw-r--r-- | src/ngAnimate/animate.js | 21 | ||||
| -rw-r--r-- | src/ngRoute/directive/ngView.js | 12 | 
5 files changed, 74 insertions, 13 deletions
| diff --git a/src/ng/directive/ngIf.js b/src/ng/directive/ngIf.js index 000fba82..a31015b2 100644 --- a/src/ng/directive/ngIf.js +++ b/src/ng/directive/ngIf.js @@ -84,7 +84,7 @@ var ngIfDirective = ['$animate', function($animate) {      restrict: 'A',      $$tlb: true,      link: function ($scope, $element, $attr, ctrl, $transclude) { -        var block, childScope; +        var block, childScope, previousElements;          $scope.$watch($attr.ngIf, function ngIfWatchAction(value) {            if (toBoolean(value)) { @@ -102,14 +102,19 @@ var ngIfDirective = ['$animate', function($animate) {                });              }            } else { - -            if (childScope) { +            if(previousElements) { +              previousElements.remove(); +              previousElements = null; +            } +            if(childScope) {                childScope.$destroy();                childScope = null;              } - -            if (block) { -              $animate.leave(getBlockElements(block.clone)); +            if(block) { +              previousElements = getBlockElements(block.clone); +              $animate.leave(previousElements, function() { +                previousElements = null; +              });                block = null;              }            } diff --git a/src/ng/directive/ngInclude.js b/src/ng/directive/ngInclude.js index 29e3abce..272e199a 100644 --- a/src/ng/directive/ngInclude.js +++ b/src/ng/directive/ngInclude.js @@ -177,15 +177,23 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$animate'        return function(scope, $element, $attr, ctrl, $transclude) {          var changeCounter = 0,              currentScope, +            previousElement,              currentElement;          var cleanupLastIncludeContent = function() { -          if (currentScope) { +          if(previousElement) { +            previousElement.remove(); +            previousElement = null; +          } +          if(currentScope) {              currentScope.$destroy();              currentScope = null;            }            if(currentElement) { -            $animate.leave(currentElement); +            $animate.leave(currentElement, function() { +              previousElement = null; +            }); +            previousElement = currentElement;              currentElement = null;            }          }; diff --git a/src/ng/directive/ngSwitch.js b/src/ng/directive/ngSwitch.js index 92594978..378c0b50 100644 --- a/src/ng/directive/ngSwitch.js +++ b/src/ng/directive/ngSwitch.js @@ -138,12 +138,31 @@ var ngSwitchDirective = ['$animate', function($animate) {        var watchExpr = attr.ngSwitch || attr.on,            selectedTranscludes,            selectedElements, +          previousElements,            selectedScopes = [];        scope.$watch(watchExpr, function ngSwitchWatchAction(value) { -        for (var i= 0, ii=selectedScopes.length; i<ii; i++) { -          selectedScopes[i].$destroy(); -          $animate.leave(selectedElements[i]); +        var i, ii = selectedScopes.length; +        if(ii > 0) { +          if(previousElements) { +            for (i = 0; i < ii; i++) { +              previousElements[i].remove(); +            } +            previousElements = null; +          } + +          previousElements = []; +          for (i= 0; i<ii; i++) { +            var selected = selectedElements[i]; +            selectedScopes[i].$destroy(); +            previousElements[i] = selected; +            $animate.leave(selected, function() { +              previousElements.splice(i, 1); +              if(previousElements.length === 0) { +                previousElements = null; +              } +            }); +          }          }          selectedElements = []; diff --git a/src/ngAnimate/animate.js b/src/ngAnimate/animate.js index c09e714e..6b1eedfc 100644 --- a/src/ngAnimate/animate.js +++ b/src/ngAnimate/animate.js @@ -764,6 +764,27 @@ angular.module('ngAnimate', ['ng'])            return;          } +        if(animationEvent == 'leave') { +          //there's no need to ever remove the listener since the element +          //will be removed (destroyed) after the leave animation ends or +          //is cancelled midway +          element.one('$destroy', function(e) { +            var element = angular.element(this); +            var state = element.data(NG_ANIMATE_STATE) || {}; +            var activeLeaveAnimation = state.active['ng-leave']; +            if(activeLeaveAnimation) { +              var animations = activeLeaveAnimation.animations; + +              //if the before animation is completed then the element will be +              //removed shortly after so there is no need to cancel the animation +              if(!animations[0].beforeComplete) { +                cancelAnimations(animations); +                cleanup(element, 'ng-leave'); +              } +            } +          }); +        } +          //the ng-animate class does nothing, but it's here to allow for          //parent animations to find and cancel child animations when needed          element.addClass(NG_ANIMATE_CLASS_NAME); diff --git a/src/ngRoute/directive/ngView.js b/src/ngRoute/directive/ngView.js index 3fa851a7..448e375c 100644 --- a/src/ngRoute/directive/ngView.js +++ b/src/ngRoute/directive/ngView.js @@ -189,6 +189,7 @@ function ngViewFactory(   $route,   $anchorScroll,   $animate) {      link: function(scope, $element, attr, ctrl, $transclude) {          var currentScope,              currentElement, +            previousElement,              autoScrollExp = attr.autoscroll,              onloadExp = attr.onload || ''; @@ -196,12 +197,19 @@ function ngViewFactory(   $route,   $anchorScroll,   $animate) {          update();          function cleanupLastView() { -          if (currentScope) { +          if(previousElement) { +            previousElement.remove(); +            previousElement = null; +          } +          if(currentScope) {              currentScope.$destroy();              currentScope = null;            }            if(currentElement) { -            $animate.leave(currentElement); +            $animate.leave(currentElement, function() { +              previousElement = null; +            }); +            previousElement = currentElement;              currentElement = null;            }          } | 
