mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-06 22:29:44 +08:00
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
(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 || {});
|