Skip to content

Instantly share code, notes, and snippets.

@fael
Created September 12, 2011 20:44
Show Gist options
  • Save fael/1212350 to your computer and use it in GitHub Desktop.
Save fael/1212350 to your computer and use it in GitHub Desktop.
jQuery UI Alert (with alert() override)
getOrCreateDialog = function (id) {
$box = $('#' + id);
if (!$box.length) {
$box = $('<div id="' + id + '"><p></p></div>').hide().appendTo('body');
}
return $box;
}
customAlert(message, title, options, callback){
callback = callback || function(){};
var default = {
modal : true,
resizable : false,
buttons : {
Ok: function() {
$(this).dialog('close');
return (typeof callback == 'string') ?
window.location.href = callback :
callback();
}
},
show : 'fade',
hide : 'fade',
minHeight : 50,
dialogClass : 'modal-shadow'
}
$alert = getOrCreateDialog('alert');
$("p", $alert)
.attr("title", title)
.html(message);
$alert.dialog($.extend({}, default, opcoes));
}
window.alert = function (message) {
customAlert(message, 'Alert');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment