Created
November 20, 2013 20:34
-
-
Save triple-j/7570519 to your computer and use it in GitHub Desktop.
jQuery UI dialog based alert / confirm / prompt
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
(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