Skip to content

Instantly share code, notes, and snippets.

@pec1985
Created June 13, 2011 17:43
Show Gist options
  • Select an option

  • Save pec1985/1023281 to your computer and use it in GitHub Desktop.

Select an option

Save pec1985/1023281 to your computer and use it in GitHub Desktop.
Simple Single-Context app
// namespace for the windows
var W = {};
// namespace for custom UI
var UI = {};
// store the tabs in this array for later use
var tabs = [];
// include the necessary files to run the app
Ti.include('ui.js');
Ti.include('other.js');
Ti.include('window1.js');
Ti.include('window2.js');
Ti.include('tabgroup.js');
W.TabGroup().open();
W.OtherWin = function(){
var win = UI.Win();
var label = Ti.UI.createLabel({
backgroundColor:'purple',
color:'black',
text:'this is another window',
width:'auto',
height:'auto'
});
win.add(label);
return win;
}
W.TabGroup = function(){
var tabGroup = Ti.UI.createTabGroup();
tabs[0] = Ti.UI.createTab({
window:W.Window1(),
title:'green'
});
tabs[1] = Ti.UI.createTab({
window:W.Window2(),
title:'blue'
});
tabGroup.addTab(tabs[0]);
tabGroup.addTab(tabs[1]);
return tabGroup;
};
UI.Win = function(a){
a = a || {};
var win = Ti.UI.createWindow(a);
win.orientationModes = [1,2,3,4];
return win;
}
W.Window1 = function(){
var win = UI.Win({
backgroundColor:'#999'
});
var button = Ti.UI.createButton({
backgroundColor:'green',
color:'black',
title:'this is window 1',
width:100,
height:40
});
button.addEventListener('click', function(){
tabs[0].open(W.OtherWin());
});
win.add(button);
return win;
};
W.Window2 = function(){
var win = UI.Win();
var label = Ti.UI.createLabel({
backgroundColor:'blue',
color:'black',
text:'this is window 2',
width:'auto',
height:'auto'
});
win.add(label);
return win;
}
@snout-o

snout-o commented Jun 28, 2011

Copy link
Copy Markdown

Should there not be a

return win;

on Window1.js?

@pec1985

pec1985 commented Jun 28, 2011

Copy link
Copy Markdown
Author

Yes, sorry. It's fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment