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