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 originalClose.apply(settings.dialog, arguments);
30 $(event.target).remove();
33 prepareDialogButtons: function prepareDialogButtons($dialog) {
35 var $buttons = $dialog.find('.form-actions input[type=submit], .form-actions a.button');
36 $buttons.each(function () {
37 var $originalButton = $(this).css({
46 text: $originalButton.html() || $originalButton.attr('value'),
47 class: $originalButton.attr('class'),
48 click: function click(e) {
49 if ($originalButton.is('a')) {
50 $originalButton[0].click();
52 $originalButton.trigger('mousedown').trigger('mouseup').trigger('click');
62 Drupal.AjaxCommands.prototype.openDialog = function (ajax, response, status) {
63 if (!response.selector) {
66 var $dialog = $(response.selector);
67 if (!$dialog.length) {
68 $dialog = $('<div id="' + response.selector.replace(/^#/, '') + '" class="ui-front"/>').appendTo('body');
72 ajax.wrapper = $dialog.attr('id');
75 response.command = 'insert';
76 response.method = 'html';
77 ajax.commands.insert(ajax, response, status);
79 if (!response.dialogOptions.buttons) {
80 response.dialogOptions.drupalAutoButtons = true;
81 response.dialogOptions.buttons = Drupal.behaviors.dialog.prepareDialogButtons($dialog);
84 $dialog.on('dialogButtonsChange', function () {
85 var buttons = Drupal.behaviors.dialog.prepareDialogButtons($dialog);
86 $dialog.dialog('option', 'buttons', buttons);
89 response.dialogOptions = response.dialogOptions || {};
90 var dialog = Drupal.dialog($dialog.get(0), response.dialogOptions);
91 if (response.dialogOptions.modal) {
97 $dialog.parent().find('.ui-dialog-buttonset').addClass('form-actions');
100 Drupal.AjaxCommands.prototype.closeDialog = function (ajax, response, status) {
101 var $dialog = $(response.selector);
102 if ($dialog.length) {
103 Drupal.dialog($dialog.get(0)).close();
104 if (!response.persist) {
109 $dialog.off('dialogButtonsChange');
112 Drupal.AjaxCommands.prototype.setDialogOption = function (ajax, response, status) {
113 var $dialog = $(response.selector);
114 if ($dialog.length) {
115 $dialog.dialog('option', response.optionName, response.optionValue);
119 $(window).on('dialog:aftercreate', function (e, dialog, $element, settings) {
120 $element.on('click.dialog', '.dialog-cancel', function (e) {
121 dialog.close('cancel');
127 $(window).on('dialog:beforeclose', function (e, dialog, $element) {
128 $element.off('.dialog');