Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / quickedit / js / util.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.quickedit.util = Drupal.quickedit.util || {};
10
11   Drupal.quickedit.util.constants = {};
12
13   Drupal.quickedit.util.constants.transitionEnd = 'transitionEnd.quickedit webkitTransitionEnd.quickedit transitionend.quickedit msTransitionEnd.quickedit oTransitionEnd.quickedit';
14
15   Drupal.quickedit.util.buildUrl = function (id, urlFormat) {
16     var parts = id.split('/');
17     return Drupal.formatString(decodeURIComponent(urlFormat), {
18       '!entity_type': parts[0],
19       '!id': parts[1],
20       '!field_name': parts[2],
21       '!langcode': parts[3],
22       '!view_mode': parts[4]
23     });
24   };
25
26   Drupal.quickedit.util.networkErrorModal = function (title, message) {
27     var $message = $('<div>' + message + '</div>');
28     var networkErrorModal = Drupal.dialog($message.get(0), {
29       title: title,
30       dialogClass: 'quickedit-network-error',
31       buttons: [{
32         text: Drupal.t('OK'),
33         click: function click() {
34           networkErrorModal.close();
35         },
36
37         primary: true
38       }],
39       create: function create() {
40         $(this).parent().find('.ui-dialog-titlebar-close').remove();
41       },
42       close: function close(event) {
43         $(event.target).remove();
44       }
45     });
46     networkErrorModal.showModal();
47   };
48
49   Drupal.quickedit.util.form = {
50     load: function load(options, callback) {
51       var fieldID = options.fieldID;
52
53       var formLoaderAjax = Drupal.ajax({
54         url: Drupal.quickedit.util.buildUrl(fieldID, Drupal.url('quickedit/form/!entity_type/!id/!field_name/!langcode/!view_mode')),
55         submit: {
56           nocssjs: options.nocssjs,
57           reset: options.reset
58         },
59         error: function error(xhr, url) {
60           var fieldLabel = Drupal.quickedit.metadata.get(fieldID, 'label');
61           var message = Drupal.t('Could not load the form for <q>@field-label</q>, either due to a website problem or a network connection problem.<br>Please try again.', { '@field-label': fieldLabel });
62           Drupal.quickedit.util.networkErrorModal(Drupal.t('Network problem!'), message);
63
64           var fieldModel = Drupal.quickedit.app.model.get('activeField');
65           fieldModel.set('state', 'candidate');
66         }
67       });
68
69       formLoaderAjax.commands.quickeditFieldForm = function (ajax, response, status) {
70         callback(response.data, ajax);
71         Drupal.ajax.instances[this.instanceIndex] = null;
72       };
73
74       formLoaderAjax.execute();
75     },
76     ajaxifySaving: function ajaxifySaving(options, $submit) {
77       var settings = {
78         url: $submit.closest('form').attr('action'),
79         setClick: true,
80         event: 'click.quickedit',
81         progress: false,
82         submit: {
83           nocssjs: options.nocssjs,
84           other_view_modes: options.other_view_modes
85         },
86
87         success: function success(response, status) {
88           for (var i in response) {
89             if (response.hasOwnProperty(i) && response[i].command && this.commands[response[i].command]) {
90               this.commands[response[i].command](this, response[i], status);
91             }
92           }
93         },
94
95         base: $submit.attr('id'),
96         element: $submit[0]
97       };
98
99       return Drupal.ajax(settings);
100     },
101     unajaxifySaving: function unajaxifySaving(ajax) {
102       $(ajax.element).off('click.quickedit');
103     }
104   };
105 })(jQuery, Drupal);