Chris@0
|
1 /**
|
Chris@0
|
2 * DO NOT EDIT THIS FILE.
|
Chris@0
|
3 * See the following change record for more information,
|
Chris@0
|
4 * https://www.drupal.org/node/2815083
|
Chris@0
|
5 * @preserve
|
Chris@0
|
6 **/
|
Chris@17
|
7 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
Chris@0
|
8
|
Chris@0
|
9 (function ($, Drupal, drupalSettings) {
|
Chris@0
|
10 var showWeight = JSON.parse(localStorage.getItem('Drupal.tableDrag.showWeight'));
|
Chris@0
|
11
|
Chris@0
|
12 Drupal.behaviors.tableDrag = {
|
Chris@0
|
13 attach: function attach(context, settings) {
|
Chris@0
|
14 function initTableDrag(table, base) {
|
Chris@0
|
15 if (table.length) {
|
Chris@0
|
16 Drupal.tableDrag[base] = new Drupal.tableDrag(table[0], settings.tableDrag[base]);
|
Chris@0
|
17 }
|
Chris@0
|
18 }
|
Chris@0
|
19
|
Chris@14
|
20 Object.keys(settings.tableDrag || {}).forEach(function (base) {
|
Chris@14
|
21 initTableDrag($(context).find('#' + base).once('tabledrag'), base);
|
Chris@14
|
22 });
|
Chris@0
|
23 }
|
Chris@0
|
24 };
|
Chris@0
|
25
|
Chris@0
|
26 Drupal.tableDrag = function (table, tableSettings) {
|
Chris@14
|
27 var _this = this;
|
Chris@14
|
28
|
Chris@0
|
29 var self = this;
|
Chris@0
|
30 var $table = $(table);
|
Chris@0
|
31
|
Chris@0
|
32 this.$table = $(table);
|
Chris@0
|
33
|
Chris@0
|
34 this.table = table;
|
Chris@0
|
35
|
Chris@0
|
36 this.tableSettings = tableSettings;
|
Chris@0
|
37
|
Chris@0
|
38 this.dragObject = null;
|
Chris@0
|
39
|
Chris@0
|
40 this.rowObject = null;
|
Chris@0
|
41
|
Chris@0
|
42 this.oldRowElement = null;
|
Chris@0
|
43
|
Chris@0
|
44 this.oldY = 0;
|
Chris@0
|
45
|
Chris@0
|
46 this.changed = false;
|
Chris@0
|
47
|
Chris@0
|
48 this.maxDepth = 0;
|
Chris@0
|
49
|
Chris@0
|
50 this.rtl = $(this.table).css('direction') === 'rtl' ? -1 : 1;
|
Chris@0
|
51
|
Chris@0
|
52 this.striping = $(this.table).data('striping') === 1;
|
Chris@0
|
53
|
Chris@0
|
54 this.scrollSettings = { amount: 4, interval: 50, trigger: 70 };
|
Chris@0
|
55
|
Chris@0
|
56 this.scrollInterval = null;
|
Chris@0
|
57
|
Chris@0
|
58 this.scrollY = 0;
|
Chris@0
|
59
|
Chris@0
|
60 this.windowHeight = 0;
|
Chris@0
|
61
|
Chris@0
|
62 this.indentEnabled = false;
|
Chris@14
|
63 Object.keys(tableSettings || {}).forEach(function (group) {
|
Chris@14
|
64 Object.keys(tableSettings[group] || {}).forEach(function (n) {
|
Chris@14
|
65 if (tableSettings[group][n].relationship === 'parent') {
|
Chris@14
|
66 _this.indentEnabled = true;
|
Chris@0
|
67 }
|
Chris@14
|
68 if (tableSettings[group][n].limit > 0) {
|
Chris@14
|
69 _this.maxDepth = tableSettings[group][n].limit;
|
Chris@14
|
70 }
|
Chris@14
|
71 });
|
Chris@14
|
72 });
|
Chris@0
|
73 if (this.indentEnabled) {
|
Chris@0
|
74 this.indentCount = 1;
|
Chris@0
|
75
|
Chris@0
|
76 var indent = Drupal.theme('tableDragIndentation');
|
Chris@0
|
77 var testRow = $('<tr/>').addClass('draggable').appendTo(table);
|
Chris@0
|
78 var testCell = $('<td/>').appendTo(testRow).prepend(indent).prepend(indent);
|
Chris@0
|
79 var $indentation = testCell.find('.js-indentation');
|
Chris@0
|
80
|
Chris@0
|
81 this.indentAmount = $indentation.get(1).offsetLeft - $indentation.get(0).offsetLeft;
|
Chris@0
|
82 testRow.remove();
|
Chris@0
|
83 }
|
Chris@0
|
84
|
Chris@0
|
85 $table.find('> tr.draggable, > tbody > tr.draggable').each(function () {
|
Chris@0
|
86 self.makeDraggable(this);
|
Chris@0
|
87 });
|
Chris@0
|
88
|
Chris@18
|
89 $table.before($('<button type="button" class="link tabledrag-toggle-weight"></button>').on('click', $.proxy(function (e) {
|
Chris@0
|
90 e.preventDefault();
|
Chris@0
|
91 this.toggleColumns();
|
Chris@0
|
92 }, this)).wrap('<div class="tabledrag-toggle-weight-wrapper"></div>').parent());
|
Chris@0
|
93
|
Chris@0
|
94 self.initColumns();
|
Chris@0
|
95
|
Chris@0
|
96 $(document).on('touchmove', function (event) {
|
Chris@0
|
97 return self.dragRow(event.originalEvent.touches[0], self);
|
Chris@0
|
98 });
|
Chris@0
|
99 $(document).on('touchend', function (event) {
|
Chris@0
|
100 return self.dropRow(event.originalEvent.touches[0], self);
|
Chris@0
|
101 });
|
Chris@0
|
102 $(document).on('mousemove pointermove', function (event) {
|
Chris@0
|
103 return self.dragRow(event, self);
|
Chris@0
|
104 });
|
Chris@0
|
105 $(document).on('mouseup pointerup', function (event) {
|
Chris@0
|
106 return self.dropRow(event, self);
|
Chris@0
|
107 });
|
Chris@0
|
108
|
Chris@0
|
109 $(window).on('storage', $.proxy(function (e) {
|
Chris@0
|
110 if (e.originalEvent.key === 'Drupal.tableDrag.showWeight') {
|
Chris@0
|
111 showWeight = JSON.parse(e.originalEvent.newValue);
|
Chris@0
|
112 this.displayColumns(showWeight);
|
Chris@0
|
113 }
|
Chris@0
|
114 }, this));
|
Chris@0
|
115 };
|
Chris@0
|
116
|
Chris@0
|
117 Drupal.tableDrag.prototype.initColumns = function () {
|
Chris@14
|
118 var _this2 = this;
|
Chris@14
|
119
|
Chris@0
|
120 var $table = this.$table;
|
Chris@0
|
121 var hidden = void 0;
|
Chris@0
|
122 var cell = void 0;
|
Chris@0
|
123 var columnIndex = void 0;
|
Chris@14
|
124 Object.keys(this.tableSettings || {}).forEach(function (group) {
|
Chris@17
|
125 Object.keys(_this2.tableSettings[group]).some(function (tableSetting) {
|
Chris@17
|
126 var field = $table.find('.' + _this2.tableSettings[group][tableSetting].target).eq(0);
|
Chris@17
|
127 if (field.length && _this2.tableSettings[group][tableSetting].hidden) {
|
Chris@17
|
128 hidden = _this2.tableSettings[group][tableSetting].hidden;
|
Chris@17
|
129 cell = field.closest('td');
|
Chris@17
|
130 return true;
|
Chris@0
|
131 }
|
Chris@17
|
132 return false;
|
Chris@17
|
133 });
|
Chris@0
|
134
|
Chris@14
|
135 if (hidden && cell[0]) {
|
Chris@14
|
136 columnIndex = cell.parent().find('> td').index(cell.get(0)) + 1;
|
Chris@14
|
137 $table.find('> thead > tr, > tbody > tr, > tr').each(_this2.addColspanClass(columnIndex));
|
Chris@0
|
138 }
|
Chris@14
|
139 });
|
Chris@0
|
140 this.displayColumns(showWeight);
|
Chris@0
|
141 };
|
Chris@0
|
142
|
Chris@0
|
143 Drupal.tableDrag.prototype.addColspanClass = function (columnIndex) {
|
Chris@0
|
144 return function () {
|
Chris@0
|
145 var $row = $(this);
|
Chris@0
|
146 var index = columnIndex;
|
Chris@0
|
147 var cells = $row.children();
|
Chris@0
|
148 var cell = void 0;
|
Chris@0
|
149 cells.each(function (n) {
|
Chris@0
|
150 if (n < index && this.colSpan && this.colSpan > 1) {
|
Chris@0
|
151 index -= this.colSpan - 1;
|
Chris@0
|
152 }
|
Chris@0
|
153 });
|
Chris@0
|
154 if (index > 0) {
|
Chris@0
|
155 cell = cells.filter(':nth-child(' + index + ')');
|
Chris@0
|
156 if (cell[0].colSpan && cell[0].colSpan > 1) {
|
Chris@0
|
157 cell.addClass('tabledrag-has-colspan');
|
Chris@0
|
158 } else {
|
Chris@0
|
159 cell.addClass('tabledrag-hide');
|
Chris@0
|
160 }
|
Chris@0
|
161 }
|
Chris@0
|
162 };
|
Chris@0
|
163 };
|
Chris@0
|
164
|
Chris@0
|
165 Drupal.tableDrag.prototype.displayColumns = function (displayWeight) {
|
Chris@0
|
166 if (displayWeight) {
|
Chris@0
|
167 this.showColumns();
|
Chris@0
|
168 } else {
|
Chris@0
|
169 this.hideColumns();
|
Chris@0
|
170 }
|
Chris@0
|
171
|
Chris@0
|
172 $('table').findOnce('tabledrag').trigger('columnschange', !!displayWeight);
|
Chris@0
|
173 };
|
Chris@0
|
174
|
Chris@0
|
175 Drupal.tableDrag.prototype.toggleColumns = function () {
|
Chris@0
|
176 showWeight = !showWeight;
|
Chris@0
|
177 this.displayColumns(showWeight);
|
Chris@0
|
178 if (showWeight) {
|
Chris@0
|
179 localStorage.setItem('Drupal.tableDrag.showWeight', showWeight);
|
Chris@0
|
180 } else {
|
Chris@0
|
181 localStorage.removeItem('Drupal.tableDrag.showWeight');
|
Chris@0
|
182 }
|
Chris@0
|
183 };
|
Chris@0
|
184
|
Chris@0
|
185 Drupal.tableDrag.prototype.hideColumns = function () {
|
Chris@0
|
186 var $tables = $('table').findOnce('tabledrag');
|
Chris@0
|
187
|
Chris@0
|
188 $tables.find('.tabledrag-hide').css('display', 'none');
|
Chris@0
|
189
|
Chris@0
|
190 $tables.find('.tabledrag-handle').css('display', '');
|
Chris@0
|
191
|
Chris@0
|
192 $tables.find('.tabledrag-has-colspan').each(function () {
|
Chris@0
|
193 this.colSpan = this.colSpan - 1;
|
Chris@0
|
194 });
|
Chris@0
|
195
|
Chris@0
|
196 $('.tabledrag-toggle-weight').text(Drupal.t('Show row weights'));
|
Chris@0
|
197 };
|
Chris@0
|
198
|
Chris@0
|
199 Drupal.tableDrag.prototype.showColumns = function () {
|
Chris@0
|
200 var $tables = $('table').findOnce('tabledrag');
|
Chris@0
|
201
|
Chris@0
|
202 $tables.find('.tabledrag-hide').css('display', '');
|
Chris@0
|
203
|
Chris@0
|
204 $tables.find('.tabledrag-handle').css('display', 'none');
|
Chris@0
|
205
|
Chris@0
|
206 $tables.find('.tabledrag-has-colspan').each(function () {
|
Chris@0
|
207 this.colSpan = this.colSpan + 1;
|
Chris@0
|
208 });
|
Chris@0
|
209
|
Chris@0
|
210 $('.tabledrag-toggle-weight').text(Drupal.t('Hide row weights'));
|
Chris@0
|
211 };
|
Chris@0
|
212
|
Chris@0
|
213 Drupal.tableDrag.prototype.rowSettings = function (group, row) {
|
Chris@0
|
214 var field = $(row).find('.' + group);
|
Chris@0
|
215 var tableSettingsGroup = this.tableSettings[group];
|
Chris@17
|
216 return Object.keys(tableSettingsGroup).map(function (delta) {
|
Chris@17
|
217 var targetClass = tableSettingsGroup[delta].target;
|
Chris@17
|
218 var rowSettings = void 0;
|
Chris@17
|
219 if (field.is('.' + targetClass)) {
|
Chris@17
|
220 rowSettings = {};
|
Chris@17
|
221 Object.keys(tableSettingsGroup[delta]).forEach(function (n) {
|
Chris@17
|
222 rowSettings[n] = tableSettingsGroup[delta][n];
|
Chris@17
|
223 });
|
Chris@0
|
224 }
|
Chris@17
|
225 return rowSettings;
|
Chris@17
|
226 }).filter(function (rowSetting) {
|
Chris@17
|
227 return rowSetting;
|
Chris@17
|
228 })[0];
|
Chris@0
|
229 };
|
Chris@0
|
230
|
Chris@0
|
231 Drupal.tableDrag.prototype.makeDraggable = function (item) {
|
Chris@0
|
232 var self = this;
|
Chris@0
|
233 var $item = $(item);
|
Chris@0
|
234
|
Chris@0
|
235 $item.find('td:first-of-type').find('a').addClass('menu-item__link');
|
Chris@0
|
236
|
Chris@0
|
237 var handle = $('<a href="#" class="tabledrag-handle"><div class="handle"> </div></a>').attr('title', Drupal.t('Drag to re-order'));
|
Chris@0
|
238
|
Chris@0
|
239 var $indentationLast = $item.find('td:first-of-type').find('.js-indentation').eq(-1);
|
Chris@0
|
240 if ($indentationLast.length) {
|
Chris@0
|
241 $indentationLast.after(handle);
|
Chris@0
|
242
|
Chris@0
|
243 self.indentCount = Math.max($item.find('.js-indentation').length, self.indentCount);
|
Chris@0
|
244 } else {
|
Chris@0
|
245 $item.find('td').eq(0).prepend(handle);
|
Chris@0
|
246 }
|
Chris@0
|
247
|
Chris@0
|
248 handle.on('mousedown touchstart pointerdown', function (event) {
|
Chris@0
|
249 event.preventDefault();
|
Chris@0
|
250 if (event.originalEvent.type === 'touchstart') {
|
Chris@0
|
251 event = event.originalEvent.touches[0];
|
Chris@0
|
252 }
|
Chris@0
|
253 self.dragStart(event, self, item);
|
Chris@0
|
254 });
|
Chris@0
|
255
|
Chris@0
|
256 handle.on('click', function (e) {
|
Chris@0
|
257 e.preventDefault();
|
Chris@0
|
258 });
|
Chris@0
|
259
|
Chris@0
|
260 handle.on('focus', function () {
|
Chris@0
|
261 self.safeBlur = true;
|
Chris@0
|
262 });
|
Chris@0
|
263
|
Chris@0
|
264 handle.on('blur', function (event) {
|
Chris@0
|
265 if (self.rowObject && self.safeBlur) {
|
Chris@0
|
266 self.dropRow(event, self);
|
Chris@0
|
267 }
|
Chris@0
|
268 });
|
Chris@0
|
269
|
Chris@0
|
270 handle.on('keydown', function (event) {
|
Chris@0
|
271 if (event.keyCode !== 9 && !self.rowObject) {
|
Chris@0
|
272 self.rowObject = new self.row(item, 'keyboard', self.indentEnabled, self.maxDepth, true);
|
Chris@0
|
273 }
|
Chris@0
|
274
|
Chris@0
|
275 var keyChange = false;
|
Chris@0
|
276 var groupHeight = void 0;
|
Chris@0
|
277
|
Chris@0
|
278 switch (event.keyCode) {
|
Chris@0
|
279 case 37:
|
Chris@0
|
280 case 63234:
|
Chris@0
|
281 keyChange = true;
|
Chris@0
|
282 self.rowObject.indent(-1 * self.rtl);
|
Chris@0
|
283 break;
|
Chris@0
|
284
|
Chris@0
|
285 case 38:
|
Chris@0
|
286 case 63232:
|
Chris@14
|
287 {
|
Chris@17
|
288 var $previousRow = $(self.rowObject.element).prev('tr').eq(0);
|
Chris@14
|
289 var previousRow = $previousRow.get(0);
|
Chris@14
|
290 while (previousRow && $previousRow.is(':hidden')) {
|
Chris@17
|
291 $previousRow = $(previousRow).prev('tr').eq(0);
|
Chris@14
|
292 previousRow = $previousRow.get(0);
|
Chris@14
|
293 }
|
Chris@14
|
294 if (previousRow) {
|
Chris@14
|
295 self.safeBlur = false;
|
Chris@14
|
296 self.rowObject.direction = 'up';
|
Chris@14
|
297 keyChange = true;
|
Chris@14
|
298
|
Chris@14
|
299 if ($(item).is('.tabledrag-root')) {
|
Chris@14
|
300 groupHeight = 0;
|
Chris@14
|
301 while (previousRow && $previousRow.find('.js-indentation').length) {
|
Chris@17
|
302 $previousRow = $(previousRow).prev('tr').eq(0);
|
Chris@14
|
303 previousRow = $previousRow.get(0);
|
Chris@14
|
304 groupHeight += $previousRow.is(':hidden') ? 0 : previousRow.offsetHeight;
|
Chris@14
|
305 }
|
Chris@14
|
306 if (previousRow) {
|
Chris@14
|
307 self.rowObject.swap('before', previousRow);
|
Chris@14
|
308
|
Chris@14
|
309 window.scrollBy(0, -groupHeight);
|
Chris@14
|
310 }
|
Chris@14
|
311 } else if (self.table.tBodies[0].rows[0] !== previousRow || $previousRow.is('.draggable')) {
|
Chris@14
|
312 self.rowObject.swap('before', previousRow);
|
Chris@14
|
313 self.rowObject.interval = null;
|
Chris@14
|
314 self.rowObject.indent(0);
|
Chris@14
|
315 window.scrollBy(0, -parseInt(item.offsetHeight, 10));
|
Chris@14
|
316 }
|
Chris@14
|
317
|
Chris@14
|
318 handle.trigger('focus');
|
Chris@14
|
319 }
|
Chris@14
|
320 break;
|
Chris@0
|
321 }
|
Chris@0
|
322
|
Chris@0
|
323 case 39:
|
Chris@0
|
324 case 63235:
|
Chris@0
|
325 keyChange = true;
|
Chris@0
|
326 self.rowObject.indent(self.rtl);
|
Chris@0
|
327 break;
|
Chris@0
|
328
|
Chris@0
|
329 case 40:
|
Chris@0
|
330 case 63233:
|
Chris@14
|
331 {
|
Chris@17
|
332 var $nextRow = $(self.rowObject.group).eq(-1).next('tr').eq(0);
|
Chris@14
|
333 var nextRow = $nextRow.get(0);
|
Chris@14
|
334 while (nextRow && $nextRow.is(':hidden')) {
|
Chris@17
|
335 $nextRow = $(nextRow).next('tr').eq(0);
|
Chris@14
|
336 nextRow = $nextRow.get(0);
|
Chris@14
|
337 }
|
Chris@14
|
338 if (nextRow) {
|
Chris@14
|
339 self.safeBlur = false;
|
Chris@14
|
340 self.rowObject.direction = 'down';
|
Chris@14
|
341 keyChange = true;
|
Chris@14
|
342
|
Chris@14
|
343 if ($(item).is('.tabledrag-root')) {
|
Chris@14
|
344 groupHeight = 0;
|
Chris@14
|
345 var nextGroup = new self.row(nextRow, 'keyboard', self.indentEnabled, self.maxDepth, false);
|
Chris@14
|
346 if (nextGroup) {
|
Chris@14
|
347 $(nextGroup.group).each(function () {
|
Chris@14
|
348 groupHeight += $(this).is(':hidden') ? 0 : this.offsetHeight;
|
Chris@14
|
349 });
|
Chris@14
|
350 var nextGroupRow = $(nextGroup.group).eq(-1).get(0);
|
Chris@14
|
351 self.rowObject.swap('after', nextGroupRow);
|
Chris@14
|
352
|
Chris@14
|
353 window.scrollBy(0, parseInt(groupHeight, 10));
|
Chris@14
|
354 }
|
Chris@14
|
355 } else {
|
Chris@14
|
356 self.rowObject.swap('after', nextRow);
|
Chris@14
|
357 self.rowObject.interval = null;
|
Chris@14
|
358 self.rowObject.indent(0);
|
Chris@14
|
359 window.scrollBy(0, parseInt(item.offsetHeight, 10));
|
Chris@14
|
360 }
|
Chris@14
|
361
|
Chris@14
|
362 handle.trigger('focus');
|
Chris@14
|
363 }
|
Chris@14
|
364 break;
|
Chris@0
|
365 }
|
Chris@0
|
366 }
|
Chris@0
|
367
|
Chris@0
|
368 if (self.rowObject && self.rowObject.changed === true) {
|
Chris@0
|
369 $(item).addClass('drag');
|
Chris@0
|
370 if (self.oldRowElement) {
|
Chris@0
|
371 $(self.oldRowElement).removeClass('drag-previous');
|
Chris@0
|
372 }
|
Chris@0
|
373 self.oldRowElement = item;
|
Chris@0
|
374 if (self.striping === true) {
|
Chris@0
|
375 self.restripeTable();
|
Chris@0
|
376 }
|
Chris@0
|
377 self.onDrag();
|
Chris@0
|
378 }
|
Chris@0
|
379
|
Chris@0
|
380 if (keyChange) {
|
Chris@0
|
381 return false;
|
Chris@0
|
382 }
|
Chris@0
|
383 });
|
Chris@0
|
384
|
Chris@0
|
385 handle.on('keypress', function (event) {
|
Chris@0
|
386
|
Chris@0
|
387 switch (event.keyCode) {
|
Chris@0
|
388 case 37:
|
Chris@0
|
389 case 38:
|
Chris@0
|
390 case 39:
|
Chris@0
|
391 case 40:
|
Chris@0
|
392 return false;
|
Chris@0
|
393 }
|
Chris@0
|
394 });
|
Chris@0
|
395 };
|
Chris@0
|
396
|
Chris@0
|
397 Drupal.tableDrag.prototype.dragStart = function (event, self, item) {
|
Chris@0
|
398 self.dragObject = {};
|
Chris@0
|
399 self.dragObject.initOffset = self.getPointerOffset(item, event);
|
Chris@0
|
400 self.dragObject.initPointerCoords = self.pointerCoords(event);
|
Chris@0
|
401 if (self.indentEnabled) {
|
Chris@0
|
402 self.dragObject.indentPointerPos = self.dragObject.initPointerCoords;
|
Chris@0
|
403 }
|
Chris@0
|
404
|
Chris@0
|
405 if (self.rowObject) {
|
Chris@0
|
406 $(self.rowObject.element).find('a.tabledrag-handle').trigger('blur');
|
Chris@0
|
407 }
|
Chris@0
|
408
|
Chris@0
|
409 self.rowObject = new self.row(item, 'pointer', self.indentEnabled, self.maxDepth, true);
|
Chris@0
|
410
|
Chris@0
|
411 self.table.topY = $(self.table).offset().top;
|
Chris@0
|
412 self.table.bottomY = self.table.topY + self.table.offsetHeight;
|
Chris@0
|
413
|
Chris@0
|
414 $(item).addClass('drag');
|
Chris@0
|
415
|
Chris@0
|
416 $('body').addClass('drag');
|
Chris@0
|
417 if (self.oldRowElement) {
|
Chris@0
|
418 $(self.oldRowElement).removeClass('drag-previous');
|
Chris@0
|
419 }
|
Chris@0
|
420 };
|
Chris@0
|
421
|
Chris@0
|
422 Drupal.tableDrag.prototype.dragRow = function (event, self) {
|
Chris@0
|
423 if (self.dragObject) {
|
Chris@0
|
424 self.currentPointerCoords = self.pointerCoords(event);
|
Chris@0
|
425 var y = self.currentPointerCoords.y - self.dragObject.initOffset.y;
|
Chris@0
|
426 var x = self.currentPointerCoords.x - self.dragObject.initOffset.x;
|
Chris@0
|
427
|
Chris@0
|
428 if (y !== self.oldY) {
|
Chris@0
|
429 self.rowObject.direction = y > self.oldY ? 'down' : 'up';
|
Chris@0
|
430
|
Chris@0
|
431 self.oldY = y;
|
Chris@0
|
432
|
Chris@0
|
433 var scrollAmount = self.checkScroll(self.currentPointerCoords.y);
|
Chris@0
|
434
|
Chris@0
|
435 clearInterval(self.scrollInterval);
|
Chris@0
|
436
|
Chris@0
|
437 if (scrollAmount > 0 && self.rowObject.direction === 'down' || scrollAmount < 0 && self.rowObject.direction === 'up') {
|
Chris@0
|
438 self.setScroll(scrollAmount);
|
Chris@0
|
439 }
|
Chris@0
|
440
|
Chris@0
|
441 var currentRow = self.findDropTargetRow(x, y);
|
Chris@0
|
442 if (currentRow) {
|
Chris@0
|
443 if (self.rowObject.direction === 'down') {
|
Chris@0
|
444 self.rowObject.swap('after', currentRow, self);
|
Chris@0
|
445 } else {
|
Chris@0
|
446 self.rowObject.swap('before', currentRow, self);
|
Chris@0
|
447 }
|
Chris@0
|
448 if (self.striping === true) {
|
Chris@0
|
449 self.restripeTable();
|
Chris@0
|
450 }
|
Chris@0
|
451 }
|
Chris@0
|
452 }
|
Chris@0
|
453
|
Chris@0
|
454 if (self.indentEnabled) {
|
Chris@0
|
455 var xDiff = self.currentPointerCoords.x - self.dragObject.indentPointerPos.x;
|
Chris@0
|
456
|
Chris@0
|
457 var indentDiff = Math.round(xDiff / self.indentAmount);
|
Chris@0
|
458
|
Chris@0
|
459 var indentChange = self.rowObject.indent(indentDiff);
|
Chris@0
|
460
|
Chris@0
|
461 self.dragObject.indentPointerPos.x += self.indentAmount * indentChange * self.rtl;
|
Chris@0
|
462 self.indentCount = Math.max(self.indentCount, self.rowObject.indents);
|
Chris@0
|
463 }
|
Chris@0
|
464
|
Chris@0
|
465 return false;
|
Chris@0
|
466 }
|
Chris@0
|
467 };
|
Chris@0
|
468
|
Chris@0
|
469 Drupal.tableDrag.prototype.dropRow = function (event, self) {
|
Chris@0
|
470 var droppedRow = void 0;
|
Chris@0
|
471 var $droppedRow = void 0;
|
Chris@0
|
472
|
Chris@0
|
473 if (self.rowObject !== null) {
|
Chris@0
|
474 droppedRow = self.rowObject.element;
|
Chris@0
|
475 $droppedRow = $(droppedRow);
|
Chris@0
|
476
|
Chris@0
|
477 if (self.rowObject.changed === true) {
|
Chris@0
|
478 self.updateFields(droppedRow);
|
Chris@0
|
479
|
Chris@14
|
480 Object.keys(self.tableSettings || {}).forEach(function (group) {
|
Chris@14
|
481 var rowSettings = self.rowSettings(group, droppedRow);
|
Chris@14
|
482 if (rowSettings.relationship === 'group') {
|
Chris@14
|
483 Object.keys(self.rowObject.children || {}).forEach(function (n) {
|
Chris@14
|
484 self.updateField(self.rowObject.children[n], group);
|
Chris@14
|
485 });
|
Chris@0
|
486 }
|
Chris@14
|
487 });
|
Chris@0
|
488
|
Chris@0
|
489 self.rowObject.markChanged();
|
Chris@0
|
490 if (self.changed === false) {
|
Chris@0
|
491 $(Drupal.theme('tableDragChangedWarning')).insertBefore(self.table).hide().fadeIn('slow');
|
Chris@0
|
492 self.changed = true;
|
Chris@0
|
493 }
|
Chris@0
|
494 }
|
Chris@0
|
495
|
Chris@0
|
496 if (self.indentEnabled) {
|
Chris@0
|
497 self.rowObject.removeIndentClasses();
|
Chris@0
|
498 }
|
Chris@0
|
499 if (self.oldRowElement) {
|
Chris@0
|
500 $(self.oldRowElement).removeClass('drag-previous');
|
Chris@0
|
501 }
|
Chris@0
|
502 $droppedRow.removeClass('drag').addClass('drag-previous');
|
Chris@0
|
503 self.oldRowElement = droppedRow;
|
Chris@0
|
504 self.onDrop();
|
Chris@0
|
505 self.rowObject = null;
|
Chris@0
|
506 }
|
Chris@0
|
507
|
Chris@0
|
508 if (self.dragObject !== null) {
|
Chris@0
|
509 self.dragObject = null;
|
Chris@0
|
510 $('body').removeClass('drag');
|
Chris@0
|
511 clearInterval(self.scrollInterval);
|
Chris@0
|
512 }
|
Chris@0
|
513 };
|
Chris@0
|
514
|
Chris@0
|
515 Drupal.tableDrag.prototype.pointerCoords = function (event) {
|
Chris@0
|
516 if (event.pageX || event.pageY) {
|
Chris@0
|
517 return { x: event.pageX, y: event.pageY };
|
Chris@0
|
518 }
|
Chris@0
|
519 return {
|
Chris@0
|
520 x: event.clientX + document.body.scrollLeft - document.body.clientLeft,
|
Chris@0
|
521 y: event.clientY + document.body.scrollTop - document.body.clientTop
|
Chris@0
|
522 };
|
Chris@0
|
523 };
|
Chris@0
|
524
|
Chris@0
|
525 Drupal.tableDrag.prototype.getPointerOffset = function (target, event) {
|
Chris@0
|
526 var docPos = $(target).offset();
|
Chris@0
|
527 var pointerPos = this.pointerCoords(event);
|
Chris@0
|
528 return { x: pointerPos.x - docPos.left, y: pointerPos.y - docPos.top };
|
Chris@0
|
529 };
|
Chris@0
|
530
|
Chris@0
|
531 Drupal.tableDrag.prototype.findDropTargetRow = function (x, y) {
|
Chris@17
|
532 var _this3 = this;
|
Chris@17
|
533
|
Chris@0
|
534 var rows = $(this.table.tBodies[0].rows).not(':hidden');
|
Chris@17
|
535
|
Chris@17
|
536 var _loop = function _loop(n) {
|
Chris@0
|
537 var row = rows[n];
|
Chris@0
|
538 var $row = $(row);
|
Chris@0
|
539 var rowY = $row.offset().top;
|
Chris@14
|
540 var rowHeight = void 0;
|
Chris@0
|
541
|
Chris@0
|
542 if (row.offsetHeight === 0) {
|
Chris@0
|
543 rowHeight = parseInt(row.firstChild.offsetHeight, 10) / 2;
|
Chris@0
|
544 } else {
|
Chris@0
|
545 rowHeight = parseInt(row.offsetHeight, 10) / 2;
|
Chris@0
|
546 }
|
Chris@0
|
547
|
Chris@0
|
548 if (y > rowY - rowHeight && y < rowY + rowHeight) {
|
Chris@17
|
549 if (_this3.indentEnabled) {
|
Chris@17
|
550 if (Object.keys(_this3.rowObject.group).some(function (o) {
|
Chris@17
|
551 return _this3.rowObject.group[o] === row;
|
Chris@17
|
552 })) {
|
Chris@17
|
553 return {
|
Chris@17
|
554 v: null
|
Chris@17
|
555 };
|
Chris@0
|
556 }
|
Chris@17
|
557 } else if (row === _this3.rowObject.element) {
|
Chris@17
|
558 return {
|
Chris@17
|
559 v: null
|
Chris@17
|
560 };
|
Chris@0
|
561 }
|
Chris@0
|
562
|
Chris@17
|
563 if (!_this3.rowObject.isValidSwap(row)) {
|
Chris@17
|
564 return {
|
Chris@17
|
565 v: null
|
Chris@17
|
566 };
|
Chris@0
|
567 }
|
Chris@0
|
568
|
Chris@0
|
569 while ($row.is(':hidden') && $row.prev('tr').is(':hidden')) {
|
Chris@0
|
570 $row = $row.prev('tr:first-of-type');
|
Chris@0
|
571 row = $row.get(0);
|
Chris@0
|
572 }
|
Chris@17
|
573 return {
|
Chris@17
|
574 v: row
|
Chris@17
|
575 };
|
Chris@0
|
576 }
|
Chris@17
|
577 };
|
Chris@17
|
578
|
Chris@17
|
579 for (var n = 0; n < rows.length; n++) {
|
Chris@17
|
580 var _ret = _loop(n);
|
Chris@17
|
581
|
Chris@17
|
582 if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
|
Chris@0
|
583 }
|
Chris@0
|
584 return null;
|
Chris@0
|
585 };
|
Chris@0
|
586
|
Chris@0
|
587 Drupal.tableDrag.prototype.updateFields = function (changedRow) {
|
Chris@17
|
588 var _this4 = this;
|
Chris@14
|
589
|
Chris@14
|
590 Object.keys(this.tableSettings || {}).forEach(function (group) {
|
Chris@17
|
591 _this4.updateField(changedRow, group);
|
Chris@14
|
592 });
|
Chris@0
|
593 };
|
Chris@0
|
594
|
Chris@0
|
595 Drupal.tableDrag.prototype.updateField = function (changedRow, group) {
|
Chris@0
|
596 var rowSettings = this.rowSettings(group, changedRow);
|
Chris@0
|
597 var $changedRow = $(changedRow);
|
Chris@0
|
598 var sourceRow = void 0;
|
Chris@0
|
599 var $previousRow = void 0;
|
Chris@0
|
600 var previousRow = void 0;
|
Chris@0
|
601 var useSibling = void 0;
|
Chris@0
|
602
|
Chris@0
|
603 if (rowSettings.relationship === 'self' || rowSettings.relationship === 'group') {
|
Chris@0
|
604 sourceRow = changedRow;
|
Chris@0
|
605 } else if (rowSettings.relationship === 'sibling') {
|
Chris@0
|
606 $previousRow = $changedRow.prev('tr:first-of-type');
|
Chris@0
|
607 previousRow = $previousRow.get(0);
|
Chris@0
|
608 var $nextRow = $changedRow.next('tr:first-of-type');
|
Chris@0
|
609 var nextRow = $nextRow.get(0);
|
Chris@0
|
610 sourceRow = changedRow;
|
Chris@0
|
611 if ($previousRow.is('.draggable') && $previousRow.find('.' + group).length) {
|
Chris@0
|
612 if (this.indentEnabled) {
|
Chris@0
|
613 if ($previousRow.find('.js-indentations').length === $changedRow.find('.js-indentations').length) {
|
Chris@0
|
614 sourceRow = previousRow;
|
Chris@0
|
615 }
|
Chris@0
|
616 } else {
|
Chris@0
|
617 sourceRow = previousRow;
|
Chris@0
|
618 }
|
Chris@0
|
619 } else if ($nextRow.is('.draggable') && $nextRow.find('.' + group).length) {
|
Chris@0
|
620 if (this.indentEnabled) {
|
Chris@0
|
621 if ($nextRow.find('.js-indentations').length === $changedRow.find('.js-indentations').length) {
|
Chris@0
|
622 sourceRow = nextRow;
|
Chris@0
|
623 }
|
Chris@0
|
624 } else {
|
Chris@0
|
625 sourceRow = nextRow;
|
Chris@0
|
626 }
|
Chris@0
|
627 }
|
Chris@0
|
628 } else if (rowSettings.relationship === 'parent') {
|
Chris@0
|
629 $previousRow = $changedRow.prev('tr');
|
Chris@0
|
630 previousRow = $previousRow;
|
Chris@0
|
631 while ($previousRow.length && $previousRow.find('.js-indentation').length >= this.rowObject.indents) {
|
Chris@0
|
632 $previousRow = $previousRow.prev('tr');
|
Chris@0
|
633 previousRow = $previousRow;
|
Chris@0
|
634 }
|
Chris@0
|
635
|
Chris@0
|
636 if ($previousRow.length) {
|
Chris@0
|
637 sourceRow = $previousRow.get(0);
|
Chris@0
|
638 } else {
|
Chris@0
|
639 sourceRow = $(this.table).find('tr.draggable:first-of-type').get(0);
|
Chris@0
|
640 if (sourceRow === this.rowObject.element) {
|
Chris@0
|
641 sourceRow = $(this.rowObject.group[this.rowObject.group.length - 1]).next('tr.draggable').get(0);
|
Chris@0
|
642 }
|
Chris@0
|
643 useSibling = true;
|
Chris@0
|
644 }
|
Chris@0
|
645 }
|
Chris@0
|
646
|
Chris@0
|
647 this.copyDragClasses(sourceRow, changedRow, group);
|
Chris@0
|
648 rowSettings = this.rowSettings(group, changedRow);
|
Chris@0
|
649
|
Chris@0
|
650 if (useSibling) {
|
Chris@0
|
651 rowSettings.relationship = 'sibling';
|
Chris@0
|
652 rowSettings.source = rowSettings.target;
|
Chris@0
|
653 }
|
Chris@0
|
654
|
Chris@0
|
655 var targetClass = '.' + rowSettings.target;
|
Chris@0
|
656 var targetElement = $changedRow.find(targetClass).get(0);
|
Chris@0
|
657
|
Chris@0
|
658 if (targetElement) {
|
Chris@0
|
659 var sourceClass = '.' + rowSettings.source;
|
Chris@0
|
660 var sourceElement = $(sourceClass, sourceRow).get(0);
|
Chris@0
|
661 switch (rowSettings.action) {
|
Chris@0
|
662 case 'depth':
|
Chris@0
|
663 targetElement.value = $(sourceElement).closest('tr').find('.js-indentation').length;
|
Chris@0
|
664 break;
|
Chris@0
|
665
|
Chris@0
|
666 case 'match':
|
Chris@0
|
667 targetElement.value = sourceElement.value;
|
Chris@0
|
668 break;
|
Chris@0
|
669
|
Chris@0
|
670 case 'order':
|
Chris@14
|
671 {
|
Chris@14
|
672 var siblings = this.rowObject.findSiblings(rowSettings);
|
Chris@14
|
673 if ($(targetElement).is('select')) {
|
Chris@14
|
674 var values = [];
|
Chris@14
|
675 $(targetElement).find('option').each(function () {
|
Chris@14
|
676 values.push(this.value);
|
Chris@14
|
677 });
|
Chris@14
|
678 var maxVal = values[values.length - 1];
|
Chris@0
|
679
|
Chris@14
|
680 $(siblings).find(targetClass).each(function () {
|
Chris@14
|
681 if (values.length > 0) {
|
Chris@14
|
682 this.value = values.shift();
|
Chris@14
|
683 } else {
|
Chris@14
|
684 this.value = maxVal;
|
Chris@14
|
685 }
|
Chris@14
|
686 });
|
Chris@14
|
687 } else {
|
Chris@14
|
688 var weight = parseInt($(siblings[0]).find(targetClass).val(), 10) || 0;
|
Chris@14
|
689 $(siblings).find(targetClass).each(function () {
|
Chris@14
|
690 this.value = weight;
|
Chris@14
|
691 weight++;
|
Chris@14
|
692 });
|
Chris@14
|
693 }
|
Chris@14
|
694 break;
|
Chris@0
|
695 }
|
Chris@0
|
696 }
|
Chris@0
|
697 }
|
Chris@0
|
698 };
|
Chris@0
|
699
|
Chris@0
|
700 Drupal.tableDrag.prototype.copyDragClasses = function (sourceRow, targetRow, group) {
|
Chris@0
|
701 var sourceElement = $(sourceRow).find('.' + group);
|
Chris@0
|
702 var targetElement = $(targetRow).find('.' + group);
|
Chris@0
|
703 if (sourceElement.length && targetElement.length) {
|
Chris@0
|
704 targetElement[0].className = sourceElement[0].className;
|
Chris@0
|
705 }
|
Chris@0
|
706 };
|
Chris@0
|
707
|
Chris@0
|
708 Drupal.tableDrag.prototype.checkScroll = function (cursorY) {
|
Chris@0
|
709 var de = document.documentElement;
|
Chris@0
|
710 var b = document.body;
|
Chris@0
|
711
|
Chris@14
|
712 var windowHeight = window.innerHeight || (de.clientHeight && de.clientWidth !== 0 ? de.clientHeight : b.offsetHeight);
|
Chris@14
|
713 this.windowHeight = windowHeight;
|
Chris@0
|
714 var scrollY = void 0;
|
Chris@0
|
715 if (document.all) {
|
Chris@14
|
716 scrollY = !de.scrollTop ? b.scrollTop : de.scrollTop;
|
Chris@0
|
717 } else {
|
Chris@14
|
718 scrollY = window.pageYOffset ? window.pageYOffset : window.scrollY;
|
Chris@0
|
719 }
|
Chris@14
|
720 this.scrollY = scrollY;
|
Chris@0
|
721 var trigger = this.scrollSettings.trigger;
|
Chris@0
|
722 var delta = 0;
|
Chris@0
|
723
|
Chris@0
|
724 if (cursorY - scrollY > windowHeight - trigger) {
|
Chris@0
|
725 delta = trigger / (windowHeight + scrollY - cursorY);
|
Chris@0
|
726 delta = delta > 0 && delta < trigger ? delta : trigger;
|
Chris@0
|
727 return delta * this.scrollSettings.amount;
|
Chris@17
|
728 }
|
Chris@17
|
729 if (cursorY - scrollY < trigger) {
|
Chris@0
|
730 delta = trigger / (cursorY - scrollY);
|
Chris@0
|
731 delta = delta > 0 && delta < trigger ? delta : trigger;
|
Chris@0
|
732 return -delta * this.scrollSettings.amount;
|
Chris@0
|
733 }
|
Chris@0
|
734 };
|
Chris@0
|
735
|
Chris@0
|
736 Drupal.tableDrag.prototype.setScroll = function (scrollAmount) {
|
Chris@0
|
737 var self = this;
|
Chris@0
|
738
|
Chris@0
|
739 this.scrollInterval = setInterval(function () {
|
Chris@0
|
740 self.checkScroll(self.currentPointerCoords.y);
|
Chris@0
|
741 var aboveTable = self.scrollY > self.table.topY;
|
Chris@0
|
742 var belowTable = self.scrollY + self.windowHeight < self.table.bottomY;
|
Chris@0
|
743 if (scrollAmount > 0 && belowTable || scrollAmount < 0 && aboveTable) {
|
Chris@0
|
744 window.scrollBy(0, scrollAmount);
|
Chris@0
|
745 }
|
Chris@0
|
746 }, this.scrollSettings.interval);
|
Chris@0
|
747 };
|
Chris@0
|
748
|
Chris@0
|
749 Drupal.tableDrag.prototype.restripeTable = function () {
|
Chris@0
|
750 $(this.table).find('> tbody > tr.draggable, > tr.draggable').filter(':visible').filter(':odd').removeClass('odd').addClass('even').end().filter(':even').removeClass('even').addClass('odd');
|
Chris@0
|
751 };
|
Chris@0
|
752
|
Chris@0
|
753 Drupal.tableDrag.prototype.onDrag = function () {
|
Chris@0
|
754 return null;
|
Chris@0
|
755 };
|
Chris@0
|
756
|
Chris@0
|
757 Drupal.tableDrag.prototype.onDrop = function () {
|
Chris@0
|
758 return null;
|
Chris@0
|
759 };
|
Chris@0
|
760
|
Chris@0
|
761 Drupal.tableDrag.prototype.row = function (tableRow, method, indentEnabled, maxDepth, addClasses) {
|
Chris@0
|
762 var $tableRow = $(tableRow);
|
Chris@0
|
763
|
Chris@0
|
764 this.element = tableRow;
|
Chris@0
|
765 this.method = method;
|
Chris@0
|
766 this.group = [tableRow];
|
Chris@0
|
767 this.groupDepth = $tableRow.find('.js-indentation').length;
|
Chris@0
|
768 this.changed = false;
|
Chris@0
|
769 this.table = $tableRow.closest('table')[0];
|
Chris@0
|
770 this.indentEnabled = indentEnabled;
|
Chris@0
|
771 this.maxDepth = maxDepth;
|
Chris@0
|
772
|
Chris@0
|
773 this.direction = '';
|
Chris@0
|
774 if (this.indentEnabled) {
|
Chris@0
|
775 this.indents = $tableRow.find('.js-indentation').length;
|
Chris@0
|
776 this.children = this.findChildren(addClasses);
|
Chris@0
|
777 this.group = $.merge(this.group, this.children);
|
Chris@0
|
778
|
Chris@0
|
779 for (var n = 0; n < this.group.length; n++) {
|
Chris@0
|
780 this.groupDepth = Math.max($(this.group[n]).find('.js-indentation').length, this.groupDepth);
|
Chris@0
|
781 }
|
Chris@0
|
782 }
|
Chris@0
|
783 };
|
Chris@0
|
784
|
Chris@0
|
785 Drupal.tableDrag.prototype.row.prototype.findChildren = function (addClasses) {
|
Chris@0
|
786 var parentIndentation = this.indents;
|
Chris@0
|
787 var currentRow = $(this.element, this.table).next('tr.draggable');
|
Chris@0
|
788 var rows = [];
|
Chris@0
|
789 var child = 0;
|
Chris@0
|
790
|
Chris@0
|
791 function rowIndentation(indentNum, el) {
|
Chris@0
|
792 var self = $(el);
|
Chris@0
|
793 if (child === 1 && indentNum === parentIndentation) {
|
Chris@0
|
794 self.addClass('tree-child-first');
|
Chris@0
|
795 }
|
Chris@0
|
796 if (indentNum === parentIndentation) {
|
Chris@0
|
797 self.addClass('tree-child');
|
Chris@0
|
798 } else if (indentNum > parentIndentation) {
|
Chris@0
|
799 self.addClass('tree-child-horizontal');
|
Chris@0
|
800 }
|
Chris@0
|
801 }
|
Chris@0
|
802
|
Chris@0
|
803 while (currentRow.length) {
|
Chris@0
|
804 if (currentRow.find('.js-indentation').length > parentIndentation) {
|
Chris@0
|
805 child++;
|
Chris@0
|
806 rows.push(currentRow[0]);
|
Chris@0
|
807 if (addClasses) {
|
Chris@0
|
808 currentRow.find('.js-indentation').each(rowIndentation);
|
Chris@0
|
809 }
|
Chris@0
|
810 } else {
|
Chris@0
|
811 break;
|
Chris@0
|
812 }
|
Chris@0
|
813 currentRow = currentRow.next('tr.draggable');
|
Chris@0
|
814 }
|
Chris@0
|
815 if (addClasses && rows.length) {
|
Chris@0
|
816 $(rows[rows.length - 1]).find('.js-indentation:nth-child(' + (parentIndentation + 1) + ')').addClass('tree-child-last');
|
Chris@0
|
817 }
|
Chris@0
|
818 return rows;
|
Chris@0
|
819 };
|
Chris@0
|
820
|
Chris@0
|
821 Drupal.tableDrag.prototype.row.prototype.isValidSwap = function (row) {
|
Chris@0
|
822 var $row = $(row);
|
Chris@0
|
823 if (this.indentEnabled) {
|
Chris@0
|
824 var prevRow = void 0;
|
Chris@0
|
825 var nextRow = void 0;
|
Chris@0
|
826 if (this.direction === 'down') {
|
Chris@0
|
827 prevRow = row;
|
Chris@0
|
828 nextRow = $row.next('tr').get(0);
|
Chris@0
|
829 } else {
|
Chris@0
|
830 prevRow = $row.prev('tr').get(0);
|
Chris@0
|
831 nextRow = row;
|
Chris@0
|
832 }
|
Chris@0
|
833 this.interval = this.validIndentInterval(prevRow, nextRow);
|
Chris@0
|
834
|
Chris@0
|
835 if (this.interval.min > this.interval.max) {
|
Chris@0
|
836 return false;
|
Chris@0
|
837 }
|
Chris@0
|
838 }
|
Chris@0
|
839
|
Chris@0
|
840 if (this.table.tBodies[0].rows[0] === row && $row.is(':not(.draggable)')) {
|
Chris@0
|
841 return false;
|
Chris@0
|
842 }
|
Chris@0
|
843
|
Chris@0
|
844 return true;
|
Chris@0
|
845 };
|
Chris@0
|
846
|
Chris@0
|
847 Drupal.tableDrag.prototype.row.prototype.swap = function (position, row) {
|
Chris@0
|
848 this.group.forEach(function (row) {
|
Chris@0
|
849 Drupal.detachBehaviors(row, drupalSettings, 'move');
|
Chris@0
|
850 });
|
Chris@0
|
851 $(row)[position](this.group);
|
Chris@0
|
852
|
Chris@0
|
853 this.group.forEach(function (row) {
|
Chris@0
|
854 Drupal.attachBehaviors(row, drupalSettings);
|
Chris@0
|
855 });
|
Chris@0
|
856 this.changed = true;
|
Chris@0
|
857 this.onSwap(row);
|
Chris@0
|
858 };
|
Chris@0
|
859
|
Chris@0
|
860 Drupal.tableDrag.prototype.row.prototype.validIndentInterval = function (prevRow, nextRow) {
|
Chris@0
|
861 var $prevRow = $(prevRow);
|
Chris@0
|
862 var maxIndent = void 0;
|
Chris@0
|
863
|
Chris@14
|
864 var minIndent = nextRow ? $(nextRow).find('.js-indentation').length : 0;
|
Chris@0
|
865
|
Chris@0
|
866 if (!prevRow || $prevRow.is(':not(.draggable)') || $(this.element).is('.tabledrag-root')) {
|
Chris@0
|
867 maxIndent = 0;
|
Chris@0
|
868 } else {
|
Chris@0
|
869 maxIndent = $prevRow.find('.js-indentation').length + ($prevRow.is('.tabledrag-leaf') ? 0 : 1);
|
Chris@0
|
870
|
Chris@0
|
871 if (this.maxDepth) {
|
Chris@0
|
872 maxIndent = Math.min(maxIndent, this.maxDepth - (this.groupDepth - this.indents));
|
Chris@0
|
873 }
|
Chris@0
|
874 }
|
Chris@0
|
875
|
Chris@0
|
876 return { min: minIndent, max: maxIndent };
|
Chris@0
|
877 };
|
Chris@0
|
878
|
Chris@0
|
879 Drupal.tableDrag.prototype.row.prototype.indent = function (indentDiff) {
|
Chris@0
|
880 var $group = $(this.group);
|
Chris@0
|
881
|
Chris@0
|
882 if (!this.interval) {
|
Chris@0
|
883 var prevRow = $(this.element).prev('tr').get(0);
|
Chris@0
|
884 var nextRow = $group.eq(-1).next('tr').get(0);
|
Chris@0
|
885 this.interval = this.validIndentInterval(prevRow, nextRow);
|
Chris@0
|
886 }
|
Chris@0
|
887
|
Chris@0
|
888 var indent = this.indents + indentDiff;
|
Chris@0
|
889 indent = Math.max(indent, this.interval.min);
|
Chris@0
|
890 indent = Math.min(indent, this.interval.max);
|
Chris@0
|
891 indentDiff = indent - this.indents;
|
Chris@0
|
892
|
Chris@0
|
893 for (var n = 1; n <= Math.abs(indentDiff); n++) {
|
Chris@0
|
894 if (indentDiff < 0) {
|
Chris@0
|
895 $group.find('.js-indentation:first-of-type').remove();
|
Chris@0
|
896 this.indents--;
|
Chris@0
|
897 } else {
|
Chris@0
|
898 $group.find('td:first-of-type').prepend(Drupal.theme('tableDragIndentation'));
|
Chris@0
|
899 this.indents++;
|
Chris@0
|
900 }
|
Chris@0
|
901 }
|
Chris@0
|
902 if (indentDiff) {
|
Chris@0
|
903 this.changed = true;
|
Chris@0
|
904 this.groupDepth += indentDiff;
|
Chris@0
|
905 this.onIndent();
|
Chris@0
|
906 }
|
Chris@0
|
907
|
Chris@0
|
908 return indentDiff;
|
Chris@0
|
909 };
|
Chris@0
|
910
|
Chris@0
|
911 Drupal.tableDrag.prototype.row.prototype.findSiblings = function (rowSettings) {
|
Chris@0
|
912 var siblings = [];
|
Chris@0
|
913 var directions = ['prev', 'next'];
|
Chris@0
|
914 var rowIndentation = this.indents;
|
Chris@0
|
915 var checkRowIndentation = void 0;
|
Chris@0
|
916 for (var d = 0; d < directions.length; d++) {
|
Chris@0
|
917 var checkRow = $(this.element)[directions[d]]();
|
Chris@0
|
918 while (checkRow.length) {
|
Chris@0
|
919 if (checkRow.find('.' + rowSettings.target)) {
|
Chris@0
|
920 if (this.indentEnabled) {
|
Chris@0
|
921 checkRowIndentation = checkRow.find('.js-indentation').length;
|
Chris@0
|
922 }
|
Chris@0
|
923
|
Chris@0
|
924 if (!this.indentEnabled || checkRowIndentation === rowIndentation) {
|
Chris@0
|
925 siblings.push(checkRow[0]);
|
Chris@0
|
926 } else if (checkRowIndentation < rowIndentation) {
|
Chris@0
|
927 break;
|
Chris@0
|
928 }
|
Chris@0
|
929 } else {
|
Chris@0
|
930 break;
|
Chris@0
|
931 }
|
Chris@0
|
932 checkRow = checkRow[directions[d]]();
|
Chris@0
|
933 }
|
Chris@0
|
934
|
Chris@0
|
935 if (directions[d] === 'prev') {
|
Chris@0
|
936 siblings.reverse();
|
Chris@0
|
937 siblings.push(this.element);
|
Chris@0
|
938 }
|
Chris@0
|
939 }
|
Chris@0
|
940 return siblings;
|
Chris@0
|
941 };
|
Chris@0
|
942
|
Chris@0
|
943 Drupal.tableDrag.prototype.row.prototype.removeIndentClasses = function () {
|
Chris@17
|
944 var _this5 = this;
|
Chris@14
|
945
|
Chris@14
|
946 Object.keys(this.children || {}).forEach(function (n) {
|
Chris@17
|
947 $(_this5.children[n]).find('.js-indentation').removeClass('tree-child').removeClass('tree-child-first').removeClass('tree-child-last').removeClass('tree-child-horizontal');
|
Chris@14
|
948 });
|
Chris@0
|
949 };
|
Chris@0
|
950
|
Chris@0
|
951 Drupal.tableDrag.prototype.row.prototype.markChanged = function () {
|
Chris@0
|
952 var marker = Drupal.theme('tableDragChangedMarker');
|
Chris@0
|
953 var cell = $(this.element).find('td:first-of-type');
|
Chris@0
|
954 if (cell.find('abbr.tabledrag-changed').length === 0) {
|
Chris@0
|
955 cell.append(marker);
|
Chris@0
|
956 }
|
Chris@0
|
957 };
|
Chris@0
|
958
|
Chris@0
|
959 Drupal.tableDrag.prototype.row.prototype.onIndent = function () {
|
Chris@0
|
960 return null;
|
Chris@0
|
961 };
|
Chris@0
|
962
|
Chris@0
|
963 Drupal.tableDrag.prototype.row.prototype.onSwap = function (swappedRow) {
|
Chris@0
|
964 return null;
|
Chris@0
|
965 };
|
Chris@0
|
966
|
Chris@0
|
967 $.extend(Drupal.theme, {
|
Chris@0
|
968 tableDragChangedMarker: function tableDragChangedMarker() {
|
Chris@0
|
969 return '<abbr class="warning tabledrag-changed" title="' + Drupal.t('Changed') + '">*</abbr>';
|
Chris@0
|
970 },
|
Chris@0
|
971 tableDragIndentation: function tableDragIndentation() {
|
Chris@0
|
972 return '<div class="js-indentation indentation"> </div>';
|
Chris@0
|
973 },
|
Chris@0
|
974 tableDragChangedWarning: function tableDragChangedWarning() {
|
Chris@0
|
975 return '<div class="tabledrag-changed-warning messages messages--warning" role="alert">' + Drupal.theme('tableDragChangedMarker') + ' ' + Drupal.t('You have unsaved changes.') + '</div>';
|
Chris@0
|
976 }
|
Chris@0
|
977 });
|
Chris@0
|
978 })(jQuery, Drupal, drupalSettings); |