Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Titanium Commonjs Example
var MainWindow = require('MainWindow');
var mainWin = new MainWindow();
mainWin.open();
function BarWindow() {
var self = Ti.UI.createWindow({
backgroundColor:'#f0f0f0',
layout:'vertical'
});
var lbl = Ti.UI.createLabel({
text:'Bar Window',
color:'#000',
top:20
});
lbl.addEventListener('click', function() {
self.close();
});
self.add(lbl);
var btnFoo = Ti.UI.createButton({
title:'Open FooWindow',
top:25
});
btnFoo.addEventListener('click', function() {
var FooWindow = require('FooWindow');
var fooWin = new FooWindow();
fooWin.open();
});
self.add(btnFoo);
return self;
};
module.exports = BarWindow;
function FooWindow() {
var self = Ti.UI.createWindow({
backgroundColor:'#dfdfdf',
layout:'vertical'
});
var lbl = Ti.UI.createLabel({
text:'Foo Window',
color:'#000',
top:20
});
lbl.addEventListener('click', function() {
self.close();
});
self.add(lbl);
var btnBar = Ti.UI.createButton({
title:'Open BarWindow',
top:25
});
btnBar.addEventListener('click', function() {
var BarWindow = require('BarWindow');
var barWin = new BarWindow();
barWin.open();
});
self.add(btnBar);
return self;
};
module.exports = FooWindow;
function MainWindow() {
var self = Ti.UI.createWindow({
backgroundColor:'#fff',
layout:'vertical'
});
var lbl = Ti.UI.createLabel({
text:'Main Window',
color:'#000',
top:'20'
});
self.add(lbl);
var btnFoo = Ti.UI.createButton({
title:'Open FooWindow',
top:25
});
btnFoo.addEventListener('click', function() {
var FooWindow = require('FooWindow');
var fooWin = new FooWindow();
fooWin.open();
});
self.add(btnFoo);
var btnBar = Ti.UI.createButton({
title:'Open BarWindow',
top:25
});
btnBar.addEventListener('click', function() {
var BarWindow = require('BarWindow');
var barWin = new BarWindow();
barWin.open();
});
self.add(btnBar);
return self;
};
module.exports = MainWindow;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment