Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / field_ui / field_ui.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, drupalSettings) {
9   Drupal.behaviors.fieldUIFieldStorageAddForm = {
10     attach: function attach(context) {
11       var $form = $(context).find('[data-drupal-selector="field-ui-field-storage-add-form"]').once('field_ui_add');
12       if ($form.length) {
13         $form.find('.js-form-item-label label,' + '.js-form-item-field-name label,' + '.js-form-item-existing-storage-label label').addClass('js-form-required form-required');
14
15         var $newFieldType = $form.find('select[name="new_storage_type"]');
16         var $existingStorageName = $form.find('select[name="existing_storage_name"]');
17         var $existingStorageLabel = $form.find('input[name="existing_storage_label"]');
18
19         $newFieldType.on('change', function () {
20           if ($(this).val() !== '') {
21             $existingStorageName.val('').trigger('change');
22           }
23         });
24
25         $existingStorageName.on('change', function () {
26           var value = $(this).val();
27           if (value !== '') {
28             $newFieldType.val('').trigger('change');
29
30             if (typeof drupalSettings.existingFieldLabels[value] !== 'undefined') {
31               $existingStorageLabel.val(drupalSettings.existingFieldLabels[value]);
32             }
33           }
34         });
35       }
36     }
37   };
38
39   Drupal.behaviors.fieldUIDisplayOverview = {
40     attach: function attach(context, settings) {
41       $(context).find('table#field-display-overview').once('field-display-overview').each(function () {
42         Drupal.fieldUIOverview.attach(this, settings.fieldUIRowsData, Drupal.fieldUIDisplayOverview);
43       });
44     }
45   };
46
47   Drupal.fieldUIOverview = {
48     attach: function attach(table, rowsData, rowHandlers) {
49       var tableDrag = Drupal.tableDrag[table.id];
50
51       tableDrag.onDrop = this.onDrop;
52       tableDrag.row.prototype.onSwap = this.onSwap;
53
54       $(table).find('tr.draggable').each(function () {
55         var row = this;
56         if (row.id in rowsData) {
57           var data = rowsData[row.id];
58           data.tableDrag = tableDrag;
59
60           var rowHandler = new rowHandlers[data.rowHandler](row, data);
61           $(row).data('fieldUIRowHandler', rowHandler);
62         }
63       });
64     },
65     onChange: function onChange() {
66       var $trigger = $(this);
67       var $row = $trigger.closest('tr');
68       var rowHandler = $row.data('fieldUIRowHandler');
69
70       var refreshRows = {};
71       refreshRows[rowHandler.name] = $trigger.get(0);
72
73       var region = rowHandler.getRegion();
74       if (region !== rowHandler.region) {
75         $row.find('select.js-field-parent').val('');
76
77         $.extend(refreshRows, rowHandler.regionChange(region));
78
79         rowHandler.region = region;
80       }
81
82       Drupal.fieldUIOverview.AJAXRefreshRows(refreshRows);
83     },
84     onDrop: function onDrop() {
85       var dragObject = this;
86       var row = dragObject.rowObject.element;
87       var $row = $(row);
88       var rowHandler = $row.data('fieldUIRowHandler');
89       if (typeof rowHandler !== 'undefined') {
90         var regionRow = $row.prevAll('tr.region-message').get(0);
91         var region = regionRow.className.replace(/([^ ]+[ ]+)*region-([^ ]+)-message([ ]+[^ ]+)*/, '$2');
92
93         if (region !== rowHandler.region) {
94           var refreshRows = rowHandler.regionChange(region);
95
96           rowHandler.region = region;
97
98           Drupal.fieldUIOverview.AJAXRefreshRows(refreshRows);
99         }
100       }
101     },
102     onSwap: function onSwap(draggedRow) {
103       var rowObject = this;
104       $(rowObject.table).find('tr.region-message').each(function () {
105         var $this = $(this);
106
107         if ($this.prev('tr').get(0) === rowObject.group[rowObject.group.length - 1]) {
108           if (rowObject.method !== 'keyboard' || rowObject.direction === 'down') {
109             rowObject.swap('after', this);
110           }
111         }
112
113         if ($this.next('tr').is(':not(.draggable)') || $this.next('tr').length === 0) {
114           $this.removeClass('region-populated').addClass('region-empty');
115         } else if ($this.is('.region-empty')) {
116             $this.removeClass('region-empty').addClass('region-populated');
117           }
118       });
119     },
120     AJAXRefreshRows: function AJAXRefreshRows(rows) {
121       var rowNames = [];
122       var ajaxElements = [];
123       Object.keys(rows || {}).forEach(function (rowName) {
124         rowNames.push(rowName);
125         ajaxElements.push(rows[rowName]);
126       });
127
128       if (rowNames.length) {
129         $(ajaxElements).after('<div class="ajax-progress ajax-progress-throbber"><div class="throbber">&nbsp;</div></div>');
130
131         $('input[name=refresh_rows]').val(rowNames.join(' '));
132         $('input[data-drupal-selector="edit-refresh"]').trigger('mousedown');
133
134         $(ajaxElements).prop('disabled', true);
135       }
136     }
137   };
138
139   Drupal.fieldUIDisplayOverview = {};
140
141   Drupal.fieldUIDisplayOverview.field = function (row, data) {
142     this.row = row;
143     this.name = data.name;
144     this.region = data.region;
145     this.tableDrag = data.tableDrag;
146     this.defaultPlugin = data.defaultPlugin;
147
148     this.$pluginSelect = $(row).find('.field-plugin-type');
149     this.$pluginSelect.on('change', Drupal.fieldUIOverview.onChange);
150
151     this.$regionSelect = $(row).find('select.field-region');
152     this.$regionSelect.on('change', Drupal.fieldUIOverview.onChange);
153
154     return this;
155   };
156
157   Drupal.fieldUIDisplayOverview.field.prototype = {
158     getRegion: function getRegion() {
159       return this.$regionSelect.val();
160     },
161     regionChange: function regionChange(region) {
162       region = region.replace(/-/g, '_');
163
164       this.$regionSelect.val(region);
165
166       var value = typeof this.defaultPlugin !== 'undefined' ? this.defaultPlugin : this.$pluginSelect.find('option').val();
167
168       if (typeof value !== 'undefined') {
169         this.$pluginSelect.val(value);
170       }
171
172       var refreshRows = {};
173       refreshRows[this.name] = this.$pluginSelect.get(0);
174
175       return refreshRows;
176     }
177   };
178 })(jQuery, Drupal, drupalSettings);