Skip to content

Instantly share code, notes, and snippets.

@triple-j
Created November 20, 2013 20:34
Show Gist options
  • Save triple-j/7570519 to your computer and use it in GitHub Desktop.
Save triple-j/7570519 to your computer and use it in GitHub Desktop.
jQuery UI dialog based alert / confirm / prompt
(function( $, window, undefined ) {
"use strict";
/**
* display jqueryui dialog based alert
*/
window.dialog_alert = function( message, options ) {
var defaultOpts = {
title : "Alert",
btnText : "OK"
}
options = $.extend( {}, defaultOpts, options );
var $dialogElm = $('<div/>',{
title : options.title,
html : message
});
$dialogElm.prepend( $('<span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 0 0;">') );
var buttonDefs = {};
buttonDefs[options.btnText] = function() { $( this ).dialog( "close" ); $( this ).remove(); };
$dialogElm.dialog({
resizable : false,
modal : true,
buttons : buttonDefs,
close : function() { $( this ).remove(); }
});
};
/**
* display jqueryui dialog based confirm
*/
window.dialog_confirm = function( message, options ) {
var defaultOpts = {
title : "Confirm",
success : function() {},
btnText : "OK",
btnCancel : "Cancel"
}
options = $.extend( {}, defaultOpts, options );
var $dialogElm = $('<div/>',{
title : options.title,
html : message
});
$dialogElm.prepend( $('<span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 0 0;">') );
var buttonDefs = {};
buttonDefs[options.btnText] = function() { options.success(); $( this ).dialog( "close" ); };
buttonDefs[options.btnCancel] = function() { $( this ).dialog( "close" ); };
$dialogElm.dialog({
resizable : false,
modal : true,
buttons : buttonDefs,
close : function() { $( this ).remove(); }
});
};
/**
* TODO: display jqueryui dialog based prompt
*/
window.dialog_prompt = function( message, options ) {};
})( jQuery, window );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment