Created
April 4, 2013 14:05
-
-
Save Basster/5310630 to your computer and use it in GitHub Desktop.
jQueryUi alert/confirm alternative
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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