Security update for Core, with self-updated composer
[yaffs-website] / web / core / misc / dialog / dialog.ajax.js
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
8 (function ($, Drupal) {
9   Drupal.behaviors.dialog = {
10     attach: function attach(context, settings) {
11       var $context = $(context);
12
13       if (!$('#drupal-modal').length) {
14         $('<div id="drupal-modal" class="ui-front"/>').hide().appendTo('body');
15       }
16
17       var $dialog = $context.closest('.ui-dialog-content');
18       if ($dialog.length) {
19         if ($dialog.dialog('option', 'drupalAutoButtons')) {
20           $dialog.trigger('dialogButtonsChange');
21         }
22
23         $dialog.dialog('widget').trigger('focus');
24       }
25
26       var originalClose = settings.dialog.close;
27
28       settings.dialog.close = function (event) {
29         originalClose.apply(settings.dialog, arguments);
30         $(event.target).remove();
31       };
32     },
33     prepareDialogButtons: function prepareDialogButtons($dialog) {
34       var buttons = [];
35       var $buttons = $dialog.find('.form-actions input[type=submit], .form-actions a.button');
36       $buttons.each(function () {
37         var $originalButton = $(this).css({
38           display: 'block',
39           width: 0,
40           height: 0,
41           padding: 0,
42           border: 0,
43           overflow: 'hidden'
44         });
45         buttons.push({
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();
51             } else {
52               $originalButton.trigger('mousedown').trigger('mouseup').trigger('click');
53               e.preventDefault();
54             }
55           }
56         });
57       });
58       return buttons;
59     }
60   };
61
62   Drupal.AjaxCommands.prototype.openDialog = function (ajax, response, status) {
63     if (!response.selector) {
64       return false;
65     }
66     var $dialog = $(response.selector);
67     if (!$dialog.length) {
68       $dialog = $('<div id="' + response.selector.replace(/^#/, '') + '" class="ui-front"/>').appendTo('body');
69     }
70
71     if (!ajax.wrapper) {
72       ajax.wrapper = $dialog.attr('id');
73     }
74
75     response.command = 'insert';
76     response.method = 'html';
77     ajax.commands.insert(ajax, response, status);
78
79     if (!response.dialogOptions.buttons) {
80       response.dialogOptions.drupalAutoButtons = true;
81       response.dialogOptions.buttons = Drupal.behaviors.dialog.prepareDialogButtons($dialog);
82     }
83
84     $dialog.on('dialogButtonsChange', function () {
85       var buttons = Drupal.behaviors.dialog.prepareDialogButtons($dialog);
86       $dialog.dialog('option', 'buttons', buttons);
87     });
88
89     response.dialogOptions = response.dialogOptions || {};
90     var dialog = Drupal.dialog($dialog.get(0), response.dialogOptions);
91     if (response.dialogOptions.modal) {
92       dialog.showModal();
93     } else {
94       dialog.show();
95     }
96
97     $dialog.parent().find('.ui-dialog-buttonset').addClass('form-actions');
98   };
99
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) {
105         $dialog.remove();
106       }
107     }
108
109     $dialog.off('dialogButtonsChange');
110   };
111
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);
116     }
117   };
118
119   $(window).on('dialog:aftercreate', function (e, dialog, $element, settings) {
120     $element.on('click.dialog', '.dialog-cancel', function (e) {
121       dialog.close('cancel');
122       e.preventDefault();
123       e.stopPropagation();
124     });
125   });
126
127   $(window).on('dialog:beforeclose', function (e, dialog, $element) {
128     $element.off('.dialog');
129   });
130 })(jQuery, Drupal);