mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-07 15:07:13 +08:00
Basic NavController with Tests
This commit is contained in:
49
hacking/NavController.js
Normal file
49
hacking/NavController.js
Normal file
@ -0,0 +1,49 @@
|
||||
(function(window, document, ionic) {
|
||||
NavController = function(opts) {
|
||||
this.navBar = opts.navBar;
|
||||
this.controllers = opts.controllers || [];
|
||||
};
|
||||
|
||||
NavController.prototype = {
|
||||
getControllers: function() {
|
||||
return this.controllers;
|
||||
},
|
||||
getTopController: function() {
|
||||
return this.topController;
|
||||
},
|
||||
push: function(controller) {
|
||||
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
|
||||
|
||||
// Grab the top controller on the stack
|
||||
var next = this.controllers[this.controllers.length - 1];
|
||||
// Switch to it (TODO: Animate or such things here)
|
||||
this.topController = next;
|
||||
|
||||
return controller;
|
||||
},
|
||||
|
||||
|
||||
pop: function() {
|
||||
var next, last;
|
||||
|
||||
// Grab the controller behind the top one on the stack
|
||||
last = this.controllers.pop();
|
||||
|
||||
next = this.controllers[this.controllers.length - 1];
|
||||
|
||||
// Switch to it (TODO: Animate or such things here)
|
||||
this.topController = next;
|
||||
|
||||
return last;
|
||||
}
|
||||
};
|
||||
})(this, document, this.ionic || {});
|
||||
Reference in New Issue
Block a user