Namespacing for controllers and views

This commit is contained in:
Max Lynch
2013-09-23 00:07:41 -05:00
parent 63e268f171
commit c77128eeae
8 changed files with 339 additions and 329 deletions

View File

@ -1,105 +1,108 @@
(function(ionic) {
NavController = function(opts) {
var _this = this;
this.navBar = opts.navBar;
this.content = opts.content;
this.controllers = opts.controllers || [];
ionic.controllers = ionic.controllers || {};
ionic.controllers.NavController = function(opts) {
var _this = 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() {
_this.pop();
}
};
ionic.controllers.NavController.prototype = {
getControllers: function() {
return this.controllers;
},
getTopController: function() {
return this.controllers[this.controllers.length-1];
},
push: function(controller) {
var last = this.controllers[this.controllers.length - 1];
this.controllers.push(controller);
// Indicate we are switching controllers
var shouldSwitch = this.switchingController && this.switchingController(controller) || true;
// Return if navigation cancelled
if(shouldSwitch === false)
return;
// Actually switch the active controllers
// 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);
next.isVisible = true;
next.visibilityChanged && next.visibilityChanged();
this._updateNavBar();
// TODO: Is this the best way?
this.navBar.shouldGoBack = function() {
_this.pop();
return controller;
},
pop: function() {
var next, last;
// Make sure we keep one on the stack at all times
if(this.controllers.length < 2) {
return;
}
};
NavController.prototype = {
getControllers: function() {
return this.controllers;
},
getTopController: function() {
return this.controllers[this.controllers.length-1];
},
push: function(controller) {
var last = this.controllers[this.controllers.length - 1];
// Grab the controller behind the top one on the stack
last = this.controllers.pop();
if(last) {
last.isVisible = false;
last.visibilityChanged && last.visibilityChanged();
}
// Remove the old one
//last && last.detach();
this.controllers.push(controller);
next = this.controllers[this.controllers.length - 1];
// Indicate we are switching controllers
var shouldSwitch = this.switchingController && this.switchingController(controller) || true;
// TODO: No DOM stuff here
//this.content.el.appendChild(next.el);
next.isVisible = true;
next.visibilityChanged && next.visibilityChanged();
// Return if navigation cancelled
if(shouldSwitch === false)
return;
// Switch to it (TODO: Animate or such things here)
// Actually switch the active controllers
this._updateNavBar();
// Remove the old one
//last && last.detach();
if(last) {
last.isVisible = false;
last.visibilityChanged && last.visibilityChanged();
}
return last;
},
// Grab the top controller on the stack
var next = this.controllers[this.controllers.length - 1];
_updateNavBar: function() {
if(!this.getTopController()) {
return;
}
// TODO: No DOM stuff here
//this.content.el.appendChild(next.el);
next.isVisible = true;
next.visibilityChanged && next.visibilityChanged();
this.navBar.setTitle(this.getTopController().title);
this._updateNavBar();
if(this.controllers.length > 1) {
this.navBar.showBackButton(true);
} else {
this.navBar.showBackButton(false);
}
},
return controller;
},
pop: function() {
var next, last;
// Make sure we keep one on the stack at all times
if(this.controllers.length < 2) {
return;
}
// Grab the controller behind the top one on the stack
last = this.controllers.pop();
if(last) {
last.isVisible = false;
last.visibilityChanged && last.visibilityChanged();
}
// Remove the old one
//last && last.detach();
next = this.controllers[this.controllers.length - 1];
// TODO: No DOM stuff here
//this.content.el.appendChild(next.el);
next.isVisible = true;
next.visibilityChanged && next.visibilityChanged();
// Switch to it (TODO: Animate or such things here)
this._updateNavBar();
return last;
},
_updateNavBar: function() {
if(!this.getTopController()) {
return;
}
this.navBar.setTitle(this.getTopController().title);
if(this.controllers.length > 1) {
this.navBar.showBackButton(true);
} else {
this.navBar.showBackButton(false);
}
},
};
};
})(ionic = window.ionic || {});