Skip to content

Instantly share code, notes, and snippets.

@aaronksaunders
Created July 13, 2011 04:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronksaunders/1079742 to your computer and use it in GitHub Desktop.
Save aaronksaunders/1079742 to your computer and use it in GitHub Desktop.
beginnings of a NavGroup Module to give me top window and a way to pop all windows to go back home. Working on ability to go to specific window also
Ti.include('my_navgroup.js');
function createWindow(_title) {
var win1=Titanium.UI.createWindow({
width:'100%',
height:'100%',
title:_title,
id:"win-"+_title,
left:0,
top:0,
backButtonTitle:"Back"
});
var actionBtn = Titanium.UI.createButton({
title:"Next",
style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED,
});
actionBtn.addEventListener('click', function() {
Ti.API.debug("window clicked");
myNavGroup.openWindow(createWindow((new Date()).getTime()), {});
});
win1.rightNavButton = actionBtn;
var homeBtn = Titanium.UI.createButton({
title:"Home",
style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED,
width:100,
height:35
});
homeBtn.addEventListener('click', function() {
Ti.API.debug("home clicked");
myNavGroup.goHome();
});
win1.add(homeBtn);
return win1;
}
//
var win1=Titanium.UI.createWindow({
width:'100%',
height:'100%',
title:"Home",
id:"win-Home",
left:0,
top:0
});
var actionBtn = Titanium.UI.createButton({
title:"Next",
style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED,
});
actionBtn.addEventListener('click', function() {
Ti.API.debug("window clicked");
myNavGroup.openWindow(createWindow((new Date()).getTime()), {});
});
win1.rightNavButton = actionBtn;
myNavGroup.create(win1);
var myNavGroup = function() {
var _topWindow, _windowArray, _tab, _tabGroup;
_windowArray = [];
_tabGroup = Titanium.UI.createTabGroup();
/**
* @returns the top window
*/
function getTopWindow() {
return _windowArray[_windowArray.length-1];
};
/**
* @returns all the windows
*/
function windowList() {
return _windowArray
};
/**
* opens window
*/
function openWindow(window, params) {
window.tabBarHidden = true;
_tab.open(window, params);
_windowArray.push(window);
window.addEventListener('close', function(e) {
if (_windowArray.length != 1) {
_windowArray.pop();
}
Ti.API.debug("close: window array " + _windowArray);
Ti.API.debug("close: window top " + _windowArray[_windowArray.length-1]);
});
Ti.API.debug("open: window array " + _windowArray);
Ti.API.debug("open: window top " + _windowArray[_windowArray.length-1]);
};
/**
* creates the navigation group with the initial window
*/
function create(window, params) {
window.tabBarHidden = true;
_tab = Titanium.UI.createTab({
window:window
});
_tabGroup.addTab(_tab);
_tabGroup.open();
_windowArray.push(window);
return this;
};
/**
* pops all windows off, returns to home window
*/
function goHome(window, params) {
var len = _windowArray.length-1
for (var i=0; i < len; i++) {
_win = _windowArray.pop();
Ti.API.debug(i +" closing window "+_win);
_win.close({
animate:false
});
_win = null;
};
return _windowArray
};
/**
* pops all windows off, until it gets to a specific window specified
* by the window id
* @TODO
*/
function goToWindowById(_id) {
if (_windowArray[_windowArray.length-1].id == _id) {
return
}
};
/**
* pops all windows off, until it gets to a specific window specified
* by the window index
* @TODO
*/
function goToWindowByIndex(_index) {
if (_windowArray.length-1 == _index) {
return
}
};
return {
goHome : goHome,
create : create,
openWindow : openWindow,
windowList : windowList,
getTopWindow : getTopWindow
}
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment