Skip to content

Commit

Permalink
Some ng-animate tweaks (see #85)
Browse files Browse the repository at this point in the history
Still need to guard against $animator not being defined. Also avoid
having two variables 'doAnimate' in scope to make the code clearer.
  • Loading branch information
ksperling committed Apr 24, 2013
1 parent 35b83e0 commit 3485089
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/viewDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ function $ViewDirective( $state, $compile, $controller, $injector, $an
var viewScope, viewLocals,
name = attr[directive.name] || attr.name || '',
onloadExp = attr.onload || '',
doAnimate = isDefined($animator),
animate = $animator(scope, attr);
animate = isDefined($animator) && $animator(scope, attr);

// Find the details of the parent view directive (if any) and use it
// to derive our own qualified view name, then hang our own details
Expand All @@ -22,7 +21,7 @@ function $ViewDirective( $state, $compile, $controller, $injector, $an
var view = { name: name, state: null };
element.data('$uiView', view);

scope.$on('$stateChangeSuccess', function() { updateView(doAnimate); });
scope.$on('$stateChangeSuccess', function() { updateView(true); });
updateView(false);

function updateView(doAnimate) {
Expand All @@ -31,7 +30,7 @@ function $ViewDirective( $state, $compile, $controller, $injector, $an

// Destroy previous view scope and remove content (if any)
if (viewScope) {
if (doAnimate) animate.leave(element.contents(), element);
if (animate && doAnimate) animate.leave(element.contents(), element);
else element.html('');

viewScope.$destroy();
Expand All @@ -43,7 +42,7 @@ function $ViewDirective( $state, $compile, $controller, $injector, $an
view.state = locals.$$state;

var contents;
if (doAnimate) {
if (animate && doAnimate) {
contents = angular.element('<div></div>').html(locals.$template).contents();
animate.enter(contents, element);
} else {
Expand Down

0 comments on commit 3485089

Please sign in to comment.