Configurable nav controller anims

This commit is contained in:
Max Lynch
2013-10-31 22:16:29 -05:00
parent ea026b3e03
commit 7d0c075d82
7 changed files with 81 additions and 63 deletions

View File

@ -48,21 +48,7 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges
// Compile the template with the new scrope, and append it to the navigation's content area
var el = $compile(templateString)(childScope, function(cloned, scope) {
var content = $element[0].querySelector('.content');
var title = $element.parent().parent().parent()[0].querySelector('.title');
var newTitle = angular.element(title.cloneNode());
$compile(newTitle)(childScope);
title.parentNode.insertBefore(newTitle[0], title.nextSibling);
console.log(newTitle);
$animate.enter(cloned, angular.element(content));
$animate.addClass(angular.element(newTitle), 'slide-in-left-fade', function() {
$animate.removeClass(angular.element(newTitle), 'slide-in-left-fade', function() {
newTitle.scope().$destroy();
newTitle.remove();
});
});
});
});
};
@ -110,7 +96,7 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges
};
})
.directive('navContent', ['Gesture', '$animate', function(Gesture, $animate) {
.directive('navContent', ['Gesture', '$animate', '$compile', function(Gesture, $animate, $compile) {
return {
restrict: 'ECA',
require: '^navs',
@ -121,6 +107,8 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges
var lastParent, lastIndex, childScope, childElement;
$scope.title = $attr.title;
$scope.slideAnimation = $attr.slideAnimation || '';
$scope.slideTitleAnimation = $attr.slideTitleAnimation || '';
if($attr.navBar === "false") {
navCtrl.hideNavBar();
@ -130,20 +118,31 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges
$scope.pushController($scope, $element);
var title = angular.element($element.parent().parent().parent()[0].querySelector('.title'));
var newTitle = angular.element(title.clone());
$compile(newTitle)($scope);
title.after(newTitle);
console.log(newTitle);
$animate.addClass(newTitle, $scope.slideTitleAnimation, function() {
$animate.removeClass(newTitle, $scope.slideTitleAnimation, function() {
newTitle.scope().$destroy();
newTitle.remove();
});
});
$scope.$watch('isVisible', function(value) {
if(childElement) {
$animate.leave(childElement);
childElement = undefined;
}
if(childScope) {
childScope.$destroy();
childScope = undefined;
}
if(value) {
childScope = $scope.$new();
transclude(childScope, function(clone) {
childElement = clone;
clone.addClass($scope.slideAnimation);
/*
Gesture.on('drag', function(e) {
//navCtrl.handleDrag(e);
console.log('Content drag', e);
@ -152,14 +151,24 @@ angular.module('ionic.ui.nav', ['ionic.service.templateLoad', 'ionic.service.ges
Gesture.on('release', function(e) {
//navCtrl._endDrag(e);
}, childElement[0]);
*/
var title = $element.parent().parent().parent()[0].querySelector('.title');
$animate.enter(clone, $element.parent(), $element);
$animate.addClass(angular.element(title), 'slide-left-fade', function() {
$animate.removeClass(angular.element(title), 'slide-left-fade', function() {
$animate.addClass(angular.element(title), $scope.slideTitleAnimation, function() {
$animate.removeClass(angular.element(title), $scope.slideTitleAnimation, function() {
});
});
});
} else {
if(childElement) {
$animate.leave(childElement);
childElement = undefined;
}
if(childScope) {
childScope.$destroy();
childScope = undefined;
}
}
});
}

View File

@ -7,9 +7,9 @@
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<link href="/vendor/font-awesome/css/font-awesome.css" rel="stylesheet">
<link rel="stylesheet" href="../../../../dist/css/ionic.css">
<script src="/vendor/angular/angular-1.2.0rc2.min.js"></script>
<script src="/vendor/angular/angular-touch.js"></script>
<script src="/vendor/angular/angular-animate.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.3/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.3/angular-touch.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.3/angular-animate.js"></script>
<style>
.view {
position: fixed;
@ -34,12 +34,12 @@
<navs>
<nav-bar></nav-bar>
<content has-header="true" ng-controller="AppCtrl" class="slide-in-slide-out">
<content has-header="true" ng-controller="AppCtrl">
</content>
</navs>
<script id="page.html" type="text/ng-template">
<div title="Home" ng-controller="CatsCtrl" class="nav-content slide-in-slide-out">
<div title="Home" ng-controller="CatsCtrl" class="nav-content" slide-animation="slide-in-slide-out" slide-title-animation="slide-left-fade">
<h1></h1>
<a href="#" class="button button-success" ng-click="goNext()">Next</a>
<list><list-item ng-repeat="item in items" on-select="goNext()">Test</list-item></list>