Skip to content

Instantly share code, notes, and snippets.

@tannerburson
Created July 26, 2011 03:56
Show Gist options
  • Save tannerburson/1105936 to your computer and use it in GitHub Desktop.
Save tannerburson/1105936 to your computer and use it in GitHub Desktop.
Ti.include('underscore.js');
Ti.include('backbone.js');
Ti.include('keystone.js');
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
//
// create controls tab and root window
//
var Status = Backbone.Model.extend({
defaults: {
status: false
},
initialize : function() {
if(!this.get('status')){
this.set({status:this.defaults.status});
}
},
toggle : function() {
this.set({status:!(this.get('status'))});
}
});
var MyView = Keystone.View.extend({
_toggle : function() {
this.model.toggle();
},
open : function() {
this.obj.open();
},
_render : function() {
this.obj = Ti.UI.createWindow(_.extend({
title: 'Title',
backgroundColor : '#fff',
id : 'main_window'
},this.options));
this.statusLabel = Ti.UI.createLabel({
color : '#000',
width: 'auto',
height: '20',
textAlignt: 'center'
});
this._update(this.model);
this.observes(this.obj);
this.obj.add(this.statusLabel);
},
_update : function() {
var message = (this.model.get('status') ? "It's Up!" : "It's Down :(");
this.statusLabel.text = message;
},
events : {
'click #main_window' : '_toggle'
},
initialize : function(options) {
this.count = 0;
_.bindAll(this,'_update','_toggle');
this._render();
this.model.view = this;
this.model.bind('change',this._update);
setInterval(this._toggle,4000);
}
});
var view = new MyView({model : new Status});
view.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment