Skip to content

Instantly share code, notes, and snippets.

@tonylukasavage
Created August 16, 2012 16:33
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 tonylukasavage/3371493 to your computer and use it in GitHub Desktop.
Save tonylukasavage/3371493 to your computer and use it in GitHub Desktop.
revised Alloy controller format
"Window": {
backgroundColor: '#fff'
},
"Label": {
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
color: "#000",
font: {
fontSize: '32dp'
}
},
"#ad": {
buttonNames: ['OK'],
title: 'Label Text'
}
var args = arguments[0] || {};
$.ad.message = args.message;
// "exported" functions attached to each dialog controller instance
exports.showDialog = function() {
$.ad.show();
}
exports.hideDialog = function() {
$.ad.hide();
}
<Alloy>
<AlertDialog id="ad"/>
</Alloy>
$.index.open();
/*
* "exported" functions are attached to each instance and are made
* available inside the controller code as well.
* - "exports" can call and access other "exports"
* - "exports" also have full access to the $ variable
*/
exports.showAlert = function(text) {
var dialogController = Alloy.getController('dialog', { message:text });
dialogController.showDialog();
// or you can access the AlertDialog directly with getView(id)
//
// dialogController.getView('ad').show();
//
// getView() called with no id will get the first top-level view
//
// dialogController.getView().show();
// hide the dialog after 3 seconds using the exposed "hideDialog" function
setTimeout(function() {
dialogController.hideDialog();
}, 3000);
}
/*
* markup event handler
*/
function doClick(e) {
exports.showAlert($.label.text);
}
<Alloy>
<Window>
<Label id="label" onClick="doClick">Hello, World</Label>
</Window>
</Alloy>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment