I would like to replace the native javascript alert() with my own, so that I would be able to control the theme and have it more JQueryUI look and feel. I\'ve tried numerous alt
The native alert()
brings the browser to a dead halt. You will not find any third party libraries that do that, because it's not possible.*
I threw together a quick demo of how you can use a single jQuery dialog instead of an alert.
var alertManager = (function() {
var _queue = [],
_opts = {
modal: true,
autoOpen: false,
buttons: {
OK: function ()
{
$(this).dialog('close');
var next = _queue.shift();
if (typeof next === 'string')
{
_dialog.text(next).dialog('open');
}
}
}
},
_dialog = $('').dialog(_opts),
_self = {};
_self.show = function (message) {
if (_dialog.dialog('isOpen')) {
_queue.push(String(message));
}
else {
_dialog.text(message).dialog('open');
}
}
return _self;
}());
$('#clicky').click(function ()
{
alertManager.show('alert numero uno');
alertManager.show('alert #2');
alertManager.show({foo: 'bar'});
alertManager.show(document.getElementById('clicky'));
alertManager.show('last one');
});
You could also turn this into a jQuery plugin pretty easily.
*though you could fake it with a while
loop that spins while the dialog is open. I do not recommend this.