Skip to content

Instantly share code, notes, and snippets.

@raulriera
Created September 9, 2012 11:08
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save raulriera/3683830 to your computer and use it in GitHub Desktop.
Save raulriera/3683830 to your computer and use it in GitHub Desktop.
CustomAlertDialog commonJS module for Titanium Appcelerator. Similar to the "Tweetbot" (but will need more makeup of course) where the information is displayed below the title bar instead of an intrusive popup
// Include the module
require("DialogWindow");
// Show the alert wherever (this is of course the one liner approach)
new DialogWindow("Oh oh, super error detected").open();
DialogWindow = function(message, type){
// Default params
var message = message || "How about you add some message to this? :)";
var type = type || "error";
var window = Titanium.UI.createWindow({
width: 320,
height: 44,
top: 44,
opacity: 0
});
var container = Titanium.UI.createView({
opacity: 0.8,
backgroundColor: type == "error" ? "#cc0000" : "#333333",
borderWidth: 2,
borderColor: type == "error" ? "#ff0000" : "#111111"
});
var message = Titanium.UI.createLabel({
text: message,
font: { fontSize: 11, fontWeight: "bold"},
color: "#ffffff",
shadowColor: "#111111",
shadowOffset: {x:0,y:1},
left: 12,
right: 12
});
// When the window opens
window.addEventListener("open", function(e){
window.animate({ opacity: 1, duration: 500 });
setTimeout(function(){
window.animate({ opacity: 0, duration: 500 });
}, 5500);
});
window.add(container);
window.add(message);
return window;
};
module.exports = DialogWindow;
@raulriera
Copy link
Author

For usage

require("/DialogWindow");
new DialogWindow("Hello there champ").open();

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