Skip to content

Instantly share code, notes, and snippets.

@Basster
Created April 4, 2013 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Basster/5310630 to your computer and use it in GitHub Desktop.
Save Basster/5310630 to your computer and use it in GitHub Desktop.
jQueryUi alert/confirm alternative
/**
* Creates a modal jQueryUi Dialog which displays a message.
* More or less a jQuery Styled alert().
*
* @param message The message to display
* @param [title] The title for the dialog box. Defaults to "Hinweis".
* @param [yesCallback]
* @param [noCallback]
*/
function jQueryConfirm(message, title, yesCallback, noCallback) {
"use strict";
var dialogTitle = 'Hinweis';
if (typeof title !== 'undefined') {
dialogTitle = title;
}
var dialog = $('<div id="jQueryAlert" title="' + dialogTitle + '"><p>' + message + '</p></div>');
var buttons = {};
if (typeof yesCallback !== 'function') {
yesCallback = function () {
$(this).dialog("close");
$(this).remove();
};
}
buttons.ok = { text: 'Ja', click: yesCallback };
buttons.cancel = { text: 'Nein' };
if (typeof noCallback !== 'function' && typeof noCallback !== 'boolean') {
noCallback = function () {
$(this).dialog("close");
$(this).remove();
};
}
if (typeof noCallback === 'function') {
buttons.cancel.click = noCallback;
}
else {
buttons.ok.text = 'OK';
delete(buttons.cancel);
}
$('body').prepend(dialog);
dialog.dialog({
modal: true,
resizable: false,
minWidth: 640,
buttons: buttons
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment