Skip to content

Commit

Permalink
added doAnimate to ui-view so when child views are loaded along with …
Browse files Browse the repository at this point in the history
…parent views, they get animated as a hole and not individually
  • Loading branch information
jeme committed Apr 22, 2013
1 parent 9690f83 commit b627e0c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ build
node_modules
.DS_Store
*~

# webstorm files
.idea
2 changes: 1 addition & 1 deletion sample/contacts.detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ <h2>{{contact.name}}</h2>
<a href="#/contacts/{{contact.id}}/item/{{item.id}}">{{item.type}}</a>
</li>
</ul>
<div ui-view></div>
<div ui-view ng-animate="{enter:'fade-enter'}"></div>
</div>
2 changes: 1 addition & 1 deletion sample/contacts.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
<div ui-view="menu"></div>
</div>
</div>
<div class="span9" ui-view></div>
<div class="span9" ui-view ng-animate="{enter:'fade-enter'}"></div>
</div>
17 changes: 9 additions & 8 deletions src/viewDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ function $ViewDirective( $state, $compile, $controller, $injector, $an
terminal: true,
link: function(scope, element, attr) {
var viewScope, viewLocals,
name = attr[directive.name] || attr.name || '',
onloadExp = attr.onload || '',
animate = $animator && $animator(scope, attr);
name = attr[directive.name] || attr.name || '',
onloadExp = attr.onload || '',
doAnimate = isDefined($animator),
animate = $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 @@ -21,16 +22,16 @@ function $ViewDirective( $state, $compile, $controller, $injector, $an
var view = { name: name, state: null };
element.data('$uiView', view);

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

function updateView() {
function updateView(doAnimate) {
var locals = $state.$current && $state.$current.locals[name];
if (locals === viewLocals) return; // nothing to do

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

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

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

0 comments on commit b627e0c

Please sign in to comment.