mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-06 22:29:44 +08:00
Nav controller tests
This commit is contained in:
@ -16,6 +16,7 @@ angular.module('ionic.ui', ['ngTouch'])
|
|||||||
.controller('NavCtrl', function($scope) {
|
.controller('NavCtrl', function($scope) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
|
|
||||||
angular.extend(this, NavController.prototype);
|
angular.extend(this, NavController.prototype);
|
||||||
|
|
||||||
NavController.call(this, {
|
NavController.call(this, {
|
||||||
@ -25,11 +26,20 @@ angular.module('ionic.ui', ['ngTouch'])
|
|||||||
shouldGoBack: function() {
|
shouldGoBack: function() {
|
||||||
},
|
},
|
||||||
setTitle: function(title) {
|
setTitle: function(title) {
|
||||||
|
$scope.title = title;
|
||||||
},
|
},
|
||||||
showBackButton: function(show) {
|
showBackButton: function(show) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$scope.controllers = this.controllers;
|
||||||
|
|
||||||
|
$scope.getTopController = function() {
|
||||||
|
return $scope.controllers[$scope.controllers.length-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.push = this.push;
|
||||||
})
|
})
|
||||||
|
|
||||||
.directive('navController', function() {
|
.directive('navController', function() {
|
||||||
@ -41,7 +51,7 @@ angular.module('ionic.ui', ['ngTouch'])
|
|||||||
controller: 'NavCtrl',
|
controller: 'NavCtrl',
|
||||||
//templateUrl: 'ext/angular/tmpl/ionicTabBar.tmpl.html',
|
//templateUrl: 'ext/angular/tmpl/ionicTabBar.tmpl.html',
|
||||||
template: '<div class="view"><div ng-transclude></div></div>',
|
template: '<div class="view"><div ng-transclude></div></div>',
|
||||||
compile: function(element, attr, transclude, tabsCtrl) {
|
compile: function(element, attr, transclude, navCtrl) {
|
||||||
return function($scope, $element, $attr) {
|
return function($scope, $element, $attr) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -54,6 +64,8 @@ angular.module('ionic.ui', ['ngTouch'])
|
|||||||
require: '^navController',
|
require: '^navController',
|
||||||
transclude: true,
|
transclude: true,
|
||||||
replace: true,
|
replace: true,
|
||||||
|
scope: {
|
||||||
|
},
|
||||||
template: '<header id="nav-bar" class="bar bar-header bar-dark">' +
|
template: '<header id="nav-bar" class="bar bar-header bar-dark">' +
|
||||||
'<h1 class="title">{{title}}</h1>' +
|
'<h1 class="title">{{title}}</h1>' +
|
||||||
'</header>'
|
'</header>'
|
||||||
@ -62,18 +74,13 @@ angular.module('ionic.ui', ['ngTouch'])
|
|||||||
|
|
||||||
.directive('navContent', function() {
|
.directive('navContent', function() {
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'C',
|
||||||
require: '^navController',
|
require: '^navController',
|
||||||
scope: {
|
|
||||||
title: '='
|
|
||||||
},
|
|
||||||
transclude: true,
|
transclude: true,
|
||||||
replace: true,
|
replace: true,
|
||||||
template: '<div ng-transclude></div>',
|
template: '<div ng-transclude></div>',
|
||||||
link: function(scope, element, attrs, tabsCtrl) {
|
link: function(scope, element, attrs, navCtrl) {
|
||||||
scope.$watch('title', function(value) {
|
navCtrl.push(scope);
|
||||||
console.log('Title chnaged', value);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -2,10 +2,13 @@
|
|||||||
NavController = function(opts) {
|
NavController = function(opts) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
|
console.log('CONSTRUCTOR', this);
|
||||||
|
|
||||||
this.navBar = opts.navBar;
|
this.navBar = opts.navBar;
|
||||||
this.content = opts.content;
|
this.content = opts.content;
|
||||||
this.controllers = opts.controllers || [];
|
this.controllers = opts.controllers || [];
|
||||||
|
|
||||||
|
this._updateNavBar();
|
||||||
|
|
||||||
// TODO: Is this the best way?
|
// TODO: Is this the best way?
|
||||||
this.navBar.shouldGoBack = function() {
|
this.navBar.shouldGoBack = function() {
|
||||||
@ -18,10 +21,12 @@
|
|||||||
return this.controllers;
|
return this.controllers;
|
||||||
},
|
},
|
||||||
getTopController: function() {
|
getTopController: function() {
|
||||||
return this.topController;
|
return this.controllers[this.controllers.length-1];
|
||||||
},
|
},
|
||||||
push: function(controller) {
|
push: function(controller) {
|
||||||
var last = this.topController;
|
console.log('PUSHING');
|
||||||
|
|
||||||
|
var last = this.controllers[this.controllers.length - 1];
|
||||||
|
|
||||||
this.controllers.push(controller);
|
this.controllers.push(controller);
|
||||||
|
|
||||||
@ -36,15 +41,17 @@
|
|||||||
|
|
||||||
// Remove the old one
|
// Remove the old one
|
||||||
//last && last.detach();
|
//last && last.detach();
|
||||||
|
if(last) {
|
||||||
|
last.isVisible = false;
|
||||||
|
last.visibilityChanged && last.visibilityChanged();
|
||||||
|
}
|
||||||
|
|
||||||
// Grab the top controller on the stack
|
// Grab the top controller on the stack
|
||||||
var next = this.controllers[this.controllers.length - 1];
|
var next = this.controllers[this.controllers.length - 1];
|
||||||
|
|
||||||
// TODO: No DOM stuff here
|
// TODO: No DOM stuff here
|
||||||
//this.content.el.appendChild(next.el);
|
//this.content.el.appendChild(next.el);
|
||||||
|
console.log('Top controller modified', this.topController);
|
||||||
// Switch to it (TODO: Animate or such things here)
|
|
||||||
this.topController = next;
|
|
||||||
|
|
||||||
this._updateNavBar();
|
this._updateNavBar();
|
||||||
|
|
||||||
@ -72,6 +79,7 @@
|
|||||||
|
|
||||||
// Switch to it (TODO: Animate or such things here)
|
// Switch to it (TODO: Animate or such things here)
|
||||||
this.topController = next;
|
this.topController = next;
|
||||||
|
console.log('Top controller modified', this.topController);
|
||||||
|
|
||||||
this._updateNavBar();
|
this._updateNavBar();
|
||||||
|
|
||||||
@ -79,6 +87,10 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_updateNavBar: function() {
|
_updateNavBar: function() {
|
||||||
|
if(!this.topController) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.navBar.setTitle(this.topController.title);
|
this.navBar.setTitle(this.topController.title);
|
||||||
|
|
||||||
if(this.controllers.length > 1) {
|
if(this.controllers.length > 1) {
|
||||||
|
|||||||
@ -31,6 +31,11 @@ angular.module('ionic.ui', ['ngTouch'])
|
|||||||
});
|
});
|
||||||
|
|
||||||
$scope.controllers = this.controllers;
|
$scope.controllers = this.controllers;
|
||||||
|
|
||||||
|
$scope.$watch('controllers', function(newV, oldV) {
|
||||||
|
console.log("CControlelrs changed", newV, oldV);
|
||||||
|
$scope.$apply();
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
.directive('tabs', function() {
|
.directive('tabs', function() {
|
||||||
|
|||||||
@ -14,13 +14,14 @@
|
|||||||
|
|
||||||
<nav-controller>
|
<nav-controller>
|
||||||
<header id="nav-bar" class="bar bar-header bar-dark">
|
<header id="nav-bar" class="bar bar-header bar-dark">
|
||||||
<h1 class="title"></h1>
|
<h1 class="title">{{getTopController().title}}</h1>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<content class="has-header content" id="content">
|
<content has-header="true">
|
||||||
<nav-content title="Home">
|
<div class="nav-content" title="Home" ng-controller="CatsCtrl">
|
||||||
<h1>{{title}}</h1>
|
<h1>Cats cradle</h2>
|
||||||
</nav-content>
|
<a href="#" class="button button-success" ng-click="goNext()">Next</a>
|
||||||
|
</div>
|
||||||
</content>
|
</content>
|
||||||
</nav-controller>
|
</nav-controller>
|
||||||
|
|
||||||
@ -28,7 +29,13 @@
|
|||||||
<script src="NavAngular.js"></script>
|
<script src="NavAngular.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
angular.module('navTest', ['ionic.ui']);
|
angular.module('navTest', ['ionic.ui'])
|
||||||
|
|
||||||
|
.controller('CatsCtrl', function($scope) {
|
||||||
|
$scope.goNext = function() {
|
||||||
|
console.log('Going next', $scope);
|
||||||
|
};
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user