dialog.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * DO NOT EDIT THIS FILE.
  3. * See the following change record for more information,
  4. * https://www.drupal.org/node/2815083
  5. * @preserve
  6. **/
  7. (function ($, Drupal, drupalSettings) {
  8. drupalSettings.dialog = {
  9. autoOpen: true,
  10. dialogClass: '',
  11. buttonClass: 'button',
  12. buttonPrimaryClass: 'button--primary',
  13. close: function close(event) {
  14. Drupal.dialog(event.target).close();
  15. Drupal.detachBehaviors(event.target, null, 'unload');
  16. }
  17. };
  18. Drupal.dialog = function (element, options) {
  19. var undef = void 0;
  20. var $element = $(element);
  21. var dialog = {
  22. open: false,
  23. returnValue: undef,
  24. show: function show() {
  25. openDialog({ modal: false });
  26. },
  27. showModal: function showModal() {
  28. openDialog({ modal: true });
  29. },
  30. close: closeDialog
  31. };
  32. function openDialog(settings) {
  33. settings = $.extend({}, drupalSettings.dialog, options, settings);
  34. $(window).trigger('dialog:beforecreate', [dialog, $element, settings]);
  35. $element.dialog(settings);
  36. dialog.open = true;
  37. $(window).trigger('dialog:aftercreate', [dialog, $element, settings]);
  38. }
  39. function closeDialog(value) {
  40. $(window).trigger('dialog:beforeclose', [dialog, $element]);
  41. $element.dialog('close');
  42. dialog.returnValue = value;
  43. dialog.open = false;
  44. $(window).trigger('dialog:afterclose', [dialog, $element]);
  45. }
  46. return dialog;
  47. };
  48. })(jQuery, Drupal, drupalSettings);