Skip to content

Instantly share code, notes, and snippets.

@FokkeZB
Created May 3, 2013 11:06
Show Gist options
  • Save FokkeZB/5508530 to your computer and use it in GitHub Desktop.
Save FokkeZB/5508530 to your computer and use it in GitHub Desktop.
Replacement for Titanium's alert()
function alert(message, title, callback) {
var dialog = Ti.UI.createAlertDialog({
title: title || 'Alert',
message: message
});
if (callback) {
dialog.addEventListener('click', callback);
}
dialog.show();
return;
}
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = alert;
}
exports.alert = alert;
}

I guess just like me you like to do alert('My message'); instead of:

Ti.UI.createAlertDialog({
        message: 'My message'
}).show();

But I'd even more like to do alert('My message', 'My title', myCallback); instead of:

var dialog = Ti.UI.createAlertDialog({
        title: 'My title',
        message: 'My message'
});

dialog.addEventListener('click', myCallback);
dialog.show();

So, that's why I use the following drop-in replacement, which is fully compatible with Titanium's.

var alert = require('alert');
alert('Do you like?', 'I am replaced', function () { alert('Good!'); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment