Nav controller tests

This commit is contained in:
Max Lynch
2013-09-18 22:10:11 -05:00
parent 41139cbd42
commit 30547511e8
4 changed files with 51 additions and 20 deletions

View File

@ -2,10 +2,13 @@
NavController = function(opts) {
var _this = this;
console.log('CONSTRUCTOR', this);
this.navBar = opts.navBar;
this.content = opts.content;
this.controllers = opts.controllers || [];
this._updateNavBar();
// TODO: Is this the best way?
this.navBar.shouldGoBack = function() {
@ -18,10 +21,12 @@
return this.controllers;
},
getTopController: function() {
return this.topController;
return this.controllers[this.controllers.length-1];
},
push: function(controller) {
var last = this.topController;
console.log('PUSHING');
var last = this.controllers[this.controllers.length - 1];
this.controllers.push(controller);
@ -36,15 +41,17 @@
// Remove the old one
//last && last.detach();
if(last) {
last.isVisible = false;
last.visibilityChanged && last.visibilityChanged();
}
// Grab the top controller on the stack
var next = this.controllers[this.controllers.length - 1];
// TODO: No DOM stuff here
//this.content.el.appendChild(next.el);
// Switch to it (TODO: Animate or such things here)
this.topController = next;
console.log('Top controller modified', this.topController);
this._updateNavBar();
@ -72,6 +79,7 @@
// Switch to it (TODO: Animate or such things here)
this.topController = next;
console.log('Top controller modified', this.topController);
this._updateNavBar();
@ -79,6 +87,10 @@
},
_updateNavBar: function() {
if(!this.topController) {
return;
}
this.navBar.setTitle(this.topController.title);
if(this.controllers.length > 1) {