2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function ($, Drupal) {
9 Drupal.behaviors.dialog = {
10 attach: function attach(context, settings) {
11 var $context = $(context);
13 if (!$('#drupal-modal').length) {
14 $('<div id="drupal-modal" class="ui-front"/>').hide().appendTo('body');
17 var $dialog = $context.closest('.ui-dialog-content');
19 if ($dialog.dialog('option', 'drupalAutoButtons')) {
20 $dialog.trigger('dialogButtonsChange');
23 $dialog.dialog('widget').trigger('focus');
26 var originalClose = settings.dialog.close;
28 settings.dialog.close = function (event) {
29 for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
30 args[_key - 1] = arguments[_key];
33 originalClose.apply(settings.dialog, [event].concat(args));
34 $(event.target).remove();
37 prepareDialogButtons: function prepareDialogButtons($dialog) {
39 var $buttons = $dialog.find('.form-actions input[type=submit], .form-actions a.button');
40 $buttons.each(function () {
41 var $originalButton = $(this).css({
50 text: $originalButton.html() || $originalButton.attr('value'),
51 class: $originalButton.attr('class'),
52 click: function click(e) {
53 if ($originalButton.is('a')) {
54 $originalButton[0].click();
56 $originalButton.trigger('mousedown').trigger('mouseup').trigger('click');
66 Drupal.AjaxCommands.prototype.openDialog = function (ajax, response, status) {
67 if (!response.selector) {
70 var $dialog = $(response.selector);
71 if (!$dialog.length) {
72 $dialog = $('<div id="' + response.selector.replace(/^#/, '') + '" class="ui-front"/>').appendTo('body');
76 ajax.wrapper = $dialog.attr('id');
79 response.command = 'insert';
80 response.method = 'html';
81 ajax.commands.insert(ajax, response, status);
83 if (!response.dialogOptions.buttons) {
84 response.dialogOptions.drupalAutoButtons = true;
85 response.dialogOptions.buttons = Drupal.behaviors.dialog.prepareDialogButtons($dialog);
88 $dialog.on('dialogButtonsChange', function () {
89 var buttons = Drupal.behaviors.dialog.prepareDialogButtons($dialog);
90 $dialog.dialog('option', 'buttons', buttons);
93 response.dialogOptions = response.dialogOptions || {};
94 var dialog = Drupal.dialog($dialog.get(0), response.dialogOptions);
95 if (response.dialogOptions.modal) {
101 $dialog.parent().find('.ui-dialog-buttonset').addClass('form-actions');
104 Drupal.AjaxCommands.prototype.closeDialog = function (ajax, response, status) {
105 var $dialog = $(response.selector);
106 if ($dialog.length) {
107 Drupal.dialog($dialog.get(0)).close();
108 if (!response.persist) {
113 $dialog.off('dialogButtonsChange');
116 Drupal.AjaxCommands.prototype.setDialogOption = function (ajax, response, status) {
117 var $dialog = $(response.selector);
118 if ($dialog.length) {
119 $dialog.dialog('option', response.optionName, response.optionValue);
123 $(window).on('dialog:aftercreate', function (e, dialog, $element, settings) {
124 $element.on('click.dialog', '.dialog-cancel', function (e) {
125 dialog.close('cancel');
131 $(window).on('dialog:beforeclose', function (e, dialog, $element) {
132 $element.off('.dialog');