Created
August 9, 2013 18:44
-
-
Save grantges/6196058 to your computer and use it in GitHub Desktop.
Simple navigation for Titanium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The contents of this file will be executed before any of | |
// your view controllers are ever executed, including the index. | |
// You have access to all functionality on the `Alloy` namespace. | |
// | |
// This is a great place to do any initialization for your app | |
// or create any global variables/functions that you'd like to | |
// make available throughout your app. You can easily make things | |
// accessible globally by attaching them to the `Alloy.Globals` | |
// object. For example: | |
// | |
// Alloy.Globals.someGlobalFunction = function(){}; | |
/* | |
* App Singleton | |
* @type {Object} | |
*/ | |
Alloy.Globals.App = { | |
Settings: { | |
menuWidth: "265dp" | |
}, | |
/** | |
* Setup the main content database | |
* @type {Object} | |
*/ | |
MainWindow: null, | |
/** | |
* Navigation Widget using for routing controllers | |
* @type {Object} | |
*/ | |
Navigator: { | |
menuView: null, | |
mainView: null, | |
contentView: null, | |
currentView: null, | |
currentController: null, | |
menuVisible: false, | |
init: function(_params){ | |
this.menuView =_params.menuView; | |
this.mainView = _params.mainView; | |
this.contentView = _params.contentView; | |
Ti.API.debug("Navigator.init - complete"); | |
}, | |
open: function(_controller, _options){ | |
if( _controller && this.contentView && (_controller !== this.currentController ) ) { | |
this.currentView = null; | |
var from =this.currentController; | |
this.currentController = _controller; | |
this.currentView = Alloy.createController(_controller, _options); | |
this.contentView.add(this.currentView.getView()); | |
Ti.Analytics.navEvent(from, this.currentController); | |
} | |
Ti.API.debug("Navigator.open - complete"); | |
}, | |
showhidemenu: function() { | |
this.mainView.width=Ti.Platform.displayCaps.platformWidth; | |
var l = !this.menuVisible ? Alloy.Globals.App.Settings.menuWidth : 0; | |
this.mainView.animate({ | |
left: l, | |
duration:100 | |
}); | |
this.menuVisible = !this.menuVisible | |
} | |
}, | |
/** | |
* Initialize the application | |
* NOTE: This should only be fired in index controller file and only once. | |
* @type {Function} | |
*/ | |
init: function() { | |
// TODO: Sanity Check to make sure globals are set properly | |
// Global system Events | |
Ti.App.addEventListener('pause', _.bind(this.exit, this)); | |
Ti.App.addEventListener('close', _.bind(this.exit, this)); | |
Ti.App.addEventListener('resume', _.bind(this.resume, this)); | |
} | |
/** | |
* Exit event observer | |
*/ | |
exit: function() { | |
this.log('debug', 'APP.exit'); | |
}, | |
/** | |
* Resume event observer | |
*/ | |
resume: function() { | |
this.log('debug', 'APP.resume'); | |
}, | |
/** | |
* Pause event observer | |
*/ | |
pause: function() { | |
this.log('debug', 'APP.pause'); | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment