dialog.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * A utility object for quickly and conveniently generating dialog boxes.
  3. * Unfortunately, this doesn't dynamically create new boxes; it reuses the same one
  4. * over and over again. It turns out dynamically generating new dialog boxes
  5. * is a pain! So we can't stack them.
  6. *
  7. * @constructor
  8. * @this {BlockPyDialog}
  9. * @param {Object} main - The main BlockPy instance
  10. * @param {HTMLElement} tag - The HTML object this is attached to.
  11. */
  12. function BlockPyDialog(main, tag) {
  13. this.main = main;
  14. this.tag = tag;
  15. this.titleTag = tag.find('.modal-title');
  16. this.bodyTag = tag.find('.modal-body');
  17. }
  18. /**
  19. * A simple externally available function for popping up a dialog
  20. * message. This menu will be draggable by its title.
  21. *
  22. * @param {String} title - The title of the message dialog. Can have HTML.
  23. * @param {String} body - The body of the message dialog. Can have HTML.
  24. * @param {function} onclose - A function to be run when the user closes the dialog.
  25. */
  26. BlockPyDialog.prototype.show = function(title, body, onclose) {
  27. this.titleTag.html(title);
  28. this.bodyTag.html(body);
  29. this.tag.modal('open');
  30. // this.tag.draggable({
  31. // 'handle': '.modal-title'
  32. // });
  33. this.tag.on('hidden.bs.modal', function (e) {
  34. if (onclose !== undefined) {
  35. onclose();
  36. }
  37. });
  38. }