confirm() to jQuery UI Dialog


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /**
  2.  * Override javascript confirm() and wrap it into a jQuery-UI Dialog box
  3.  *
  4.  * @depends $.getOrCreateDialog
  5.  *
  6.  * @param { String } the alert message
  7.  * @param { String/Object } the confirm callback
  8.  * @param { Object } jQuery Dialog box options
  9.  */
  10. function confirm(message, callback, options) {
  11.  
  12. var defaults = {
  13. modal : true,
  14. resizable : false,
  15. buttons : {
  16. Ok: function() {
  17. $(this).dialog('close');
  18. return (typeof callback == 'string') ?
  19. window.location.href = callback :
  20. callback();
  21. },
  22. Cancel: function() {
  23. $(this).dialog('close');
  24. return false;
  25. }
  26. },
  27. show : 'fade',
  28. hide : 'fade',
  29. minHeight : 50,
  30. dialogClass : 'modal-shadow'
  31. }
  32.  
  33. $confirm = $.getOrCreateDialog('confirm');
  34. // set message
  35. $("p", $confirm).html(message);
  36. // init dialog
  37. $confirm.dialog($.extend({}, defaults, options));
  38. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.