|
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@0
|
19 for (var base in settings.tableDrag) {
|
|
Chris@0
|
20 if (settings.tableDrag.hasOwnProperty(base)) {
|
|
Chris@0
|
21 initTableDrag($(context).find('#' + base).once('tabledrag'), base);
|
|
Chris@0
|
22 }
|
|
Chris@0
|
23 }
|
|
Chris@0
|
24 }
|
|
Chris@0
|
25 };
|
|
Chris@0
|
26
|
|
Chris@0
|
27 Drupal.tableDrag = function (table, tableSettings) {
|
|
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@0
|
62 for (var group in tableSettings) {
|
|
Chris@0
|
63 if (tableSettings.hasOwnProperty(group)) {
|
|
Chris@0
|
64 for (var n in tableSettings[group]) {
|
|
Chris@0
|
65 if (tableSettings[group].hasOwnProperty(n)) {
|
|
Chris@0
|
66 if (tableSettings[group][n].relationship === 'parent') {
|
|
Chris@0
|
67 this.indentEnabled = true;
|
|
Chris@0
|
68 }
|
|
Chris@0
|
69 if (tableSettings[group][n].limit > 0) {
|
|
Chris@0
|
70 this.maxDepth = tableSettings[group][n].limit;
|
|
Chris@0
|
71 }
|
|
Chris@0
|
72 }
|
|
Chris@0
|
73 }
|
|
Chris@0
|
74 }
|
|
Chris@0
|
75 }
|
|
Chris@0
|
76 if (this.indentEnabled) {
|
|
Chris@0
|
77 this.indentCount = 1;
|
|
Chris@0
|
78
|
|
Chris@0
|
79 var indent = Drupal.theme('tableDragIndentation');
|
|
Chris@0
|
80 var testRow = $('<tr/>').addClass('draggable').appendTo(table);
|
|
Chris@0
|
81 var testCell = $('<td/>').appendTo(testRow).prepend(indent).prepend(indent);
|
|
Chris@0
|
82 var $indentation = testCell.find('.js-indentation');
|
|
Chris@0
|
83
|
|
Chris@0
|
84 this.indentAmount = $indentation.get(1).offsetLeft - $indentation.get(0).offsetLeft;
|
|
Chris@0
|
85 testRow.remove();
|
|
Chris@0
|
86 }
|
|
Chris@0
|
87
|
|
Chris@0
|
88 $table.find('> tr.draggable, > tbody > tr.draggable').each(function () {
|
|
Chris@0
|
89 self.makeDraggable(this);
|
|
Chris@0
|
90 });
|
|
Chris@0
|
91
|
|
Chris@0
|
92 $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
|
93 e.preventDefault();
|
|
Chris@0
|
94 this.toggleColumns();
|
|
Chris@0
|
95 }, this)).wrap('<div class="tabledrag-toggle-weight-wrapper"></div>').parent());
|
|
Chris@0
|
96
|
|
Chris@0
|
97 self.initColumns();
|
|
Chris@0
|
98
|
|
Chris@0
|
99 $(document).on('touchmove', function (event) {
|
|
Chris@0
|
100 return self.dragRow(event.originalEvent.touches[0], self);
|
|
Chris@0
|
101 });
|
|
Chris@0
|
102 $(document).on('touchend', function (event) {
|
|
Chris@0
|
103 return self.dropRow(event.originalEvent.touches[0], self);
|
|
Chris@0
|
104 });
|
|
Chris@0
|
105 $(document).on('mousemove pointermove', function (event) {
|
|
Chris@0
|
106 return self.dragRow(event, self);
|
|
Chris@0
|
107 });
|
|
Chris@0
|
108 $(document).on('mouseup pointerup', function (event) {
|
|
Chris@0
|
109 return self.dropRow(event, self);
|
|
Chris@0
|
110 });
|
|
Chris@0
|
111
|
|
Chris@0
|
112 $(window).on('storage', $.proxy(function (e) {
|
|
Chris@0
|
113 if (e.originalEvent.key === 'Drupal.tableDrag.showWeight') {
|
|
Chris@0
|
114 showWeight = JSON.parse(e.originalEvent.newValue);
|
|
Chris@0
|
115 this.displayColumns(showWeight);
|
|
Chris@0
|
116 }
|
|
Chris@0
|
117 }, this));
|
|
Chris@0
|
118 };
|
|
Chris@0
|
119
|
|
Chris@0
|
120 Drupal.tableDrag.prototype.initColumns = function () {
|
|
Chris@0
|
121 var $table = this.$table;
|
|
Chris@0
|
122 var hidden = void 0;
|
|
Chris@0
|
123 var cell = void 0;
|
|
Chris@0
|
124 var columnIndex = void 0;
|
|
Chris@0
|
125 for (var group in this.tableSettings) {
|
|
Chris@0
|
126 if (this.tableSettings.hasOwnProperty(group)) {
|
|
Chris@0
|
127 for (var d in this.tableSettings[group]) {
|
|
Chris@0
|
128 if (this.tableSettings[group].hasOwnProperty(d)) {
|
|
Chris@0
|
129 var field = $table.find('.' + this.tableSettings[group][d].target).eq(0);
|
|
Chris@0
|
130 if (field.length && this.tableSettings[group][d].hidden) {
|
|
Chris@0
|
131 hidden = this.tableSettings[group][d].hidden;
|
|
Chris@0
|
132 cell = field.closest('td');
|
|
Chris@0
|
133 break;
|
|
Chris@0
|
134 }
|
|
Chris@0
|
135 }
|
|
Chris@0
|
136 }
|
|
Chris@0
|
137
|
|
Chris@0
|
138 if (hidden && cell[0]) {
|
|
Chris@0
|
139 columnIndex = cell.parent().find('> td').index(cell.get(0)) + 1;
|
|
Chris@0
|
140 $table.find('> thead > tr, > tbody > tr, > tr').each(this.addColspanClass(columnIndex));
|
|
Chris@0
|
141 }
|
|
Chris@0
|
142 }
|
|
Chris@0
|
143 }
|
|
Chris@0
|
144 this.displayColumns(showWeight);
|
|
Chris@0
|
145 };
|
|
Chris@0
|
146
|
|
Chris@0
|
147 Drupal.tableDrag.prototype.addColspanClass = function (columnIndex) {
|
|
Chris@0
|
148 return function () {
|
|
Chris@0
|
149 var $row = $(this);
|
|
Chris@0
|
150 var index = columnIndex;
|
|
Chris@0
|
151 var cells = $row.children();
|
|
Chris@0
|
152 var cell = void 0;
|
|
Chris@0
|
153 cells.each(function (n) {
|
|
Chris@0
|
154 if (n < index && this.colSpan && this.colSpan > 1) {
|
|
Chris@0
|
155 index -= this.colSpan - 1;
|
|
Chris@0
|
156 }
|
|
Chris@0
|
157 });
|
|
Chris@0
|
158 if (index > 0) {
|
|
Chris@0
|
159 cell = cells.filter(':nth-child(' + index + ')');
|
|
Chris@0
|
160 if (cell[0].colSpan && cell[0].colSpan > 1) {
|
|
Chris@0
|
161 cell.addClass('tabledrag-has-colspan');
|
|
Chris@0
|
162 } else {
|
|
Chris@0
|
163 cell.addClass('tabledrag-hide');
|
|
Chris@0
|
164 }
|
|
Chris@0
|
165 }
|
|
Chris@0
|
166 };
|
|
Chris@0
|
167 };
|
|
Chris@0
|
168
|
|
Chris@0
|
169 Drupal.tableDrag.prototype.displayColumns = function (displayWeight) {
|
|
Chris@0
|
170 if (displayWeight) {
|
|
Chris@0
|
171 this.showColumns();
|
|
Chris@0
|
172 } else {
|
|
Chris@0
|
173 this.hideColumns();
|
|
Chris@0
|
174 }
|
|
Chris@0
|
175
|
|
Chris@0
|
176 $('table').findOnce('tabledrag').trigger('columnschange', !!displayWeight);
|
|
Chris@0
|
177 };
|
|
Chris@0
|
178
|
|
Chris@0
|
179 Drupal.tableDrag.prototype.toggleColumns = function () {
|
|
Chris@0
|
180 showWeight = !showWeight;
|
|
Chris@0
|
181 this.displayColumns(showWeight);
|
|
Chris@0
|
182 if (showWeight) {
|
|
Chris@0
|
183 localStorage.setItem('Drupal.tableDrag.showWeight', showWeight);
|
|
Chris@0
|
184 } else {
|
|
Chris@0
|
185 localStorage.removeItem('Drupal.tableDrag.showWeight');
|
|
Chris@0
|
186 }
|
|
Chris@0
|
187 };
|
|
Chris@0
|
188
|
|
Chris@0
|
189 Drupal.tableDrag.prototype.hideColumns = function () {
|
|
Chris@0
|
190 var $tables = $('table').findOnce('tabledrag');
|
|
Chris@0
|
191
|
|
Chris@0
|
192 $tables.find('.tabledrag-hide').css('display', 'none');
|
|
Chris@0
|
193
|
|
Chris@0
|
194 $tables.find('.tabledrag-handle').css('display', '');
|
|
Chris@0
|
195
|
|
Chris@0
|
196 $tables.find('.tabledrag-has-colspan').each(function () {
|
|
Chris@0
|
197 this.colSpan = this.colSpan - 1;
|
|
Chris@0
|
198 });
|
|
Chris@0
|
199
|
|
Chris@0
|
200 $('.tabledrag-toggle-weight').text(Drupal.t('Show row weights'));
|
|
Chris@0
|
201 };
|
|
Chris@0
|
202
|
|
Chris@0
|
203 Drupal.tableDrag.prototype.showColumns = function () {
|
|
Chris@0
|
204 var $tables = $('table').findOnce('tabledrag');
|
|
Chris@0
|
205
|
|
Chris@0
|
206 $tables.find('.tabledrag-hide').css('display', '');
|
|
Chris@0
|
207
|
|
Chris@0
|
208 $tables.find('.tabledrag-handle').css('display', 'none');
|
|
Chris@0
|
209
|
|
Chris@0
|
210 $tables.find('.tabledrag-has-colspan').each(function () {
|
|
Chris@0
|
211 this.colSpan = this.colSpan + 1;
|
|
Chris@0
|
212 });
|
|
Chris@0
|
213
|
|
Chris@0
|
214 $('.tabledrag-toggle-weight').text(Drupal.t('Hide row weights'));
|
|
Chris@0
|
215 };
|
|
Chris@0
|
216
|
|
Chris@0
|
217 Drupal.tableDrag.prototype.rowSettings = function (group, row) {
|
|
Chris@0
|
218 var field = $(row).find('.' + group);
|
|
Chris@0
|
219 var tableSettingsGroup = this.tableSettings[group];
|
|
Chris@0
|
220 for (var delta in tableSettingsGroup) {
|
|
Chris@0
|
221 if (tableSettingsGroup.hasOwnProperty(delta)) {
|
|
Chris@0
|
222 var targetClass = tableSettingsGroup[delta].target;
|
|
Chris@0
|
223 if (field.is('.' + targetClass)) {
|
|
Chris@0
|
224 var rowSettings = {};
|
|
Chris@0
|
225 for (var n in tableSettingsGroup[delta]) {
|
|
Chris@0
|
226 if (tableSettingsGroup[delta].hasOwnProperty(n)) {
|
|
Chris@0
|
227 rowSettings[n] = tableSettingsGroup[delta][n];
|
|
Chris@0
|
228 }
|
|
Chris@0
|
229 }
|
|
Chris@0
|
230 return rowSettings;
|
|
Chris@0
|
231 }
|
|
Chris@0
|
232 }
|
|
Chris@0
|
233 }
|
|
Chris@0
|
234 };
|
|
Chris@0
|
235
|
|
Chris@0
|
236 Drupal.tableDrag.prototype.makeDraggable = function (item) {
|
|
Chris@0
|
237 var self = this;
|
|
Chris@0
|
238 var $item = $(item);
|
|
Chris@0
|
239
|
|
Chris@0
|
240 $item.find('td:first-of-type').find('a').addClass('menu-item__link');
|
|
Chris@0
|
241
|
|
Chris@0
|
242 var handle = $('<a href="#" class="tabledrag-handle"><div class="handle"> </div></a>').attr('title', Drupal.t('Drag to re-order'));
|
|
Chris@0
|
243
|
|
Chris@0
|
244 var $indentationLast = $item.find('td:first-of-type').find('.js-indentation').eq(-1);
|
|
Chris@0
|
245 if ($indentationLast.length) {
|
|
Chris@0
|
246 $indentationLast.after(handle);
|
|
Chris@0
|
247
|
|
Chris@0
|
248 self.indentCount = Math.max($item.find('.js-indentation').length, self.indentCount);
|
|
Chris@0
|
249 } else {
|
|
Chris@0
|
250 $item.find('td').eq(0).prepend(handle);
|
|
Chris@0
|
251 }
|
|
Chris@0
|
252
|
|
Chris@0
|
253 handle.on('mousedown touchstart pointerdown', function (event) {
|
|
Chris@0
|
254 event.preventDefault();
|
|
Chris@0
|
255 if (event.originalEvent.type === 'touchstart') {
|
|
Chris@0
|
256 event = event.originalEvent.touches[0];
|
|
Chris@0
|
257 }
|
|
Chris@0
|
258 self.dragStart(event, self, item);
|
|
Chris@0
|
259 });
|
|
Chris@0
|
260
|
|
Chris@0
|
261 handle.on('click', function (e) {
|
|
Chris@0
|
262 e.preventDefault();
|
|
Chris@0
|
263 });
|
|
Chris@0
|
264
|
|
Chris@0
|
265 handle.on('focus', function () {
|
|
Chris@0
|
266 self.safeBlur = true;
|
|
Chris@0
|
267 });
|
|
Chris@0
|
268
|
|
Chris@0
|
269 handle.on('blur', function (event) {
|
|
Chris@0
|
270 if (self.rowObject && self.safeBlur) {
|
|
Chris@0
|
271 self.dropRow(event, self);
|
|
Chris@0
|
272 }
|
|
Chris@0
|
273 });
|
|
Chris@0
|
274
|
|
Chris@0
|
275 handle.on('keydown', function (event) {
|
|
Chris@0
|
276 if (event.keyCode !== 9 && !self.rowObject) {
|
|
Chris@0
|
277 self.rowObject = new self.row(item, 'keyboard', self.indentEnabled, self.maxDepth, true);
|
|
Chris@0
|
278 }
|
|
Chris@0
|
279
|
|
Chris@0
|
280 var keyChange = false;
|
|
Chris@0
|
281 var groupHeight = void 0;
|
|
Chris@0
|
282
|
|
Chris@0
|
283 switch (event.keyCode) {
|
|
Chris@0
|
284 case 37:
|
|
Chris@0
|
285 case 63234:
|
|
Chris@0
|
286 keyChange = true;
|
|
Chris@0
|
287 self.rowObject.indent(-1 * self.rtl);
|
|
Chris@0
|
288 break;
|
|
Chris@0
|
289
|
|
Chris@0
|
290 case 38:
|
|
Chris@0
|
291 case 63232:
|
|
Chris@0
|
292 var $previousRow = $(self.rowObject.element).prev('tr:first-of-type');
|
|
Chris@0
|
293 var previousRow = $previousRow.get(0);
|
|
Chris@0
|
294 while (previousRow && $previousRow.is(':hidden')) {
|
|
Chris@0
|
295 $previousRow = $(previousRow).prev('tr:first-of-type');
|
|
Chris@0
|
296 previousRow = $previousRow.get(0);
|
|
Chris@0
|
297 }
|
|
Chris@0
|
298 if (previousRow) {
|
|
Chris@0
|
299 self.safeBlur = false;
|
|
Chris@0
|
300 self.rowObject.direction = 'up';
|
|
Chris@0
|
301 keyChange = true;
|
|
Chris@0
|
302
|
|
Chris@0
|
303 if ($(item).is('.tabledrag-root')) {
|
|
Chris@0
|
304 groupHeight = 0;
|
|
Chris@0
|
305 while (previousRow && $previousRow.find('.js-indentation').length) {
|
|
Chris@0
|
306 $previousRow = $(previousRow).prev('tr:first-of-type');
|
|
Chris@0
|
307 previousRow = $previousRow.get(0);
|
|
Chris@0
|
308 groupHeight += $previousRow.is(':hidden') ? 0 : previousRow.offsetHeight;
|
|
Chris@0
|
309 }
|
|
Chris@0
|
310 if (previousRow) {
|
|
Chris@0
|
311 self.rowObject.swap('before', previousRow);
|
|
Chris@0
|
312
|
|
Chris@0
|
313 window.scrollBy(0, -groupHeight);
|
|
Chris@0
|
314 }
|
|
Chris@0
|
315 } else if (self.table.tBodies[0].rows[0] !== previousRow || $previousRow.is('.draggable')) {
|
|
Chris@0
|
316 self.rowObject.swap('before', previousRow);
|
|
Chris@0
|
317 self.rowObject.interval = null;
|
|
Chris@0
|
318 self.rowObject.indent(0);
|
|
Chris@0
|
319 window.scrollBy(0, -parseInt(item.offsetHeight, 10));
|
|
Chris@0
|
320 }
|
|
Chris@0
|
321
|
|
Chris@0
|
322 handle.trigger('focus');
|
|
Chris@0
|
323 }
|
|
Chris@0
|
324 break;
|
|
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@0
|
334 var $nextRow = $(self.rowObject.group).eq(-1).next('tr:first-of-type');
|
|
Chris@0
|
335 var nextRow = $nextRow.get(0);
|
|
Chris@0
|
336 while (nextRow && $nextRow.is(':hidden')) {
|
|
Chris@0
|
337 $nextRow = $(nextRow).next('tr:first-of-type');
|
|
Chris@0
|
338 nextRow = $nextRow.get(0);
|
|
Chris@0
|
339 }
|
|
Chris@0
|
340 if (nextRow) {
|
|
Chris@0
|
341 self.safeBlur = false;
|
|
Chris@0
|
342 self.rowObject.direction = 'down';
|
|
Chris@0
|
343 keyChange = true;
|
|
Chris@0
|
344
|
|
Chris@0
|
345 if ($(item).is('.tabledrag-root')) {
|
|
Chris@0
|
346 groupHeight = 0;
|
|
Chris@0
|
347 var nextGroup = new self.row(nextRow, 'keyboard', self.indentEnabled, self.maxDepth, false);
|
|
Chris@0
|
348 if (nextGroup) {
|
|
Chris@0
|
349 $(nextGroup.group).each(function () {
|
|
Chris@0
|
350 groupHeight += $(this).is(':hidden') ? 0 : this.offsetHeight;
|
|
Chris@0
|
351 });
|
|
Chris@0
|
352 var nextGroupRow = $(nextGroup.group).eq(-1).get(0);
|
|
Chris@0
|
353 self.rowObject.swap('after', nextGroupRow);
|
|
Chris@0
|
354
|
|
Chris@0
|
355 window.scrollBy(0, parseInt(groupHeight, 10));
|
|
Chris@0
|
356 }
|
|
Chris@0
|
357 } else {
|
|
Chris@0
|
358 self.rowObject.swap('after', nextRow);
|
|
Chris@0
|
359 self.rowObject.interval = null;
|
|
Chris@0
|
360 self.rowObject.indent(0);
|
|
Chris@0
|
361 window.scrollBy(0, parseInt(item.offsetHeight, 10));
|
|
Chris@0
|
362 }
|
|
Chris@0
|
363
|
|
Chris@0
|
364 handle.trigger('focus');
|
|
Chris@0
|
365 }
|
|
Chris@0
|
366 break;
|
|
Chris@0
|
367 }
|
|
Chris@0
|
368
|
|
Chris@0
|
369 if (self.rowObject && self.rowObject.changed === true) {
|
|
Chris@0
|
370 $(item).addClass('drag');
|
|
Chris@0
|
371 if (self.oldRowElement) {
|
|
Chris@0
|
372 $(self.oldRowElement).removeClass('drag-previous');
|
|
Chris@0
|
373 }
|
|
Chris@0
|
374 self.oldRowElement = item;
|
|
Chris@0
|
375 if (self.striping === true) {
|
|
Chris@0
|
376 self.restripeTable();
|
|
Chris@0
|
377 }
|
|
Chris@0
|
378 self.onDrag();
|
|
Chris@0
|
379 }
|
|
Chris@0
|
380
|
|
Chris@0
|
381 if (keyChange) {
|
|
Chris@0
|
382 return false;
|
|
Chris@0
|
383 }
|
|
Chris@0
|
384 });
|
|
Chris@0
|
385
|
|
Chris@0
|
386 handle.on('keypress', function (event) {
|
|
Chris@0
|
387
|
|
Chris@0
|
388 switch (event.keyCode) {
|
|
Chris@0
|
389 case 37:
|
|
Chris@0
|
390 case 38:
|
|
Chris@0
|
391 case 39:
|
|
Chris@0
|
392 case 40:
|
|
Chris@0
|
393 return false;
|
|
Chris@0
|
394 }
|
|
Chris@0
|
395 });
|
|
Chris@0
|
396 };
|
|
Chris@0
|
397
|
|
Chris@0
|
398 Drupal.tableDrag.prototype.dragStart = function (event, self, item) {
|
|
Chris@0
|
399 self.dragObject = {};
|
|
Chris@0
|
400 self.dragObject.initOffset = self.getPointerOffset(item, event);
|
|
Chris@0
|
401 self.dragObject.initPointerCoords = self.pointerCoords(event);
|
|
Chris@0
|
402 if (self.indentEnabled) {
|
|
Chris@0
|
403 self.dragObject.indentPointerPos = self.dragObject.initPointerCoords;
|
|
Chris@0
|
404 }
|
|
Chris@0
|
405
|
|
Chris@0
|
406 if (self.rowObject) {
|
|
Chris@0
|
407 $(self.rowObject.element).find('a.tabledrag-handle').trigger('blur');
|
|
Chris@0
|
408 }
|
|
Chris@0
|
409
|
|
Chris@0
|
410 self.rowObject = new self.row(item, 'pointer', self.indentEnabled, self.maxDepth, true);
|
|
Chris@0
|
411
|
|
Chris@0
|
412 self.table.topY = $(self.table).offset().top;
|
|
Chris@0
|
413 self.table.bottomY = self.table.topY + self.table.offsetHeight;
|
|
Chris@0
|
414
|
|
Chris@0
|
415 $(item).addClass('drag');
|
|
Chris@0
|
416
|
|
Chris@0
|
417 $('body').addClass('drag');
|
|
Chris@0
|
418 if (self.oldRowElement) {
|
|
Chris@0
|
419 $(self.oldRowElement).removeClass('drag-previous');
|
|
Chris@0
|
420 }
|
|
Chris@0
|
421 };
|
|
Chris@0
|
422
|
|
Chris@0
|
423 Drupal.tableDrag.prototype.dragRow = function (event, self) {
|
|
Chris@0
|
424 if (self.dragObject) {
|
|
Chris@0
|
425 self.currentPointerCoords = self.pointerCoords(event);
|
|
Chris@0
|
426 var y = self.currentPointerCoords.y - self.dragObject.initOffset.y;
|
|
Chris@0
|
427 var x = self.currentPointerCoords.x - self.dragObject.initOffset.x;
|
|
Chris@0
|
428
|
|
Chris@0
|
429 if (y !== self.oldY) {
|
|
Chris@0
|
430 self.rowObject.direction = y > self.oldY ? 'down' : 'up';
|
|
Chris@0
|
431
|
|
Chris@0
|
432 self.oldY = y;
|
|
Chris@0
|
433
|
|
Chris@0
|
434 var scrollAmount = self.checkScroll(self.currentPointerCoords.y);
|
|
Chris@0
|
435
|
|
Chris@0
|
436 clearInterval(self.scrollInterval);
|
|
Chris@0
|
437
|
|
Chris@0
|
438 if (scrollAmount > 0 && self.rowObject.direction === 'down' || scrollAmount < 0 && self.rowObject.direction === 'up') {
|
|
Chris@0
|
439 self.setScroll(scrollAmount);
|
|
Chris@0
|
440 }
|
|
Chris@0
|
441
|
|
Chris@0
|
442 var currentRow = self.findDropTargetRow(x, y);
|
|
Chris@0
|
443 if (currentRow) {
|
|
Chris@0
|
444 if (self.rowObject.direction === 'down') {
|
|
Chris@0
|
445 self.rowObject.swap('after', currentRow, self);
|
|
Chris@0
|
446 } else {
|
|
Chris@0
|
447 self.rowObject.swap('before', currentRow, self);
|
|
Chris@0
|
448 }
|
|
Chris@0
|
449 if (self.striping === true) {
|
|
Chris@0
|
450 self.restripeTable();
|
|
Chris@0
|
451 }
|
|
Chris@0
|
452 }
|
|
Chris@0
|
453 }
|
|
Chris@0
|
454
|
|
Chris@0
|
455 if (self.indentEnabled) {
|
|
Chris@0
|
456 var xDiff = self.currentPointerCoords.x - self.dragObject.indentPointerPos.x;
|
|
Chris@0
|
457
|
|
Chris@0
|
458 var indentDiff = Math.round(xDiff / self.indentAmount);
|
|
Chris@0
|
459
|
|
Chris@0
|
460 var indentChange = self.rowObject.indent(indentDiff);
|
|
Chris@0
|
461
|
|
Chris@0
|
462 self.dragObject.indentPointerPos.x += self.indentAmount * indentChange * self.rtl;
|
|
Chris@0
|
463 self.indentCount = Math.max(self.indentCount, self.rowObject.indents);
|
|
Chris@0
|
464 }
|
|
Chris@0
|
465
|
|
Chris@0
|
466 return false;
|
|
Chris@0
|
467 }
|
|
Chris@0
|
468 };
|
|
Chris@0
|
469
|
|
Chris@0
|
470 Drupal.tableDrag.prototype.dropRow = function (event, self) {
|
|
Chris@0
|
471 var droppedRow = void 0;
|
|
Chris@0
|
472 var $droppedRow = void 0;
|
|
Chris@0
|
473
|
|
Chris@0
|
474 if (self.rowObject !== null) {
|
|
Chris@0
|
475 droppedRow = self.rowObject.element;
|
|
Chris@0
|
476 $droppedRow = $(droppedRow);
|
|
Chris@0
|
477
|
|
Chris@0
|
478 if (self.rowObject.changed === true) {
|
|
Chris@0
|
479 self.updateFields(droppedRow);
|
|
Chris@0
|
480
|
|
Chris@0
|
481 for (var group in self.tableSettings) {
|
|
Chris@0
|
482 if (self.tableSettings.hasOwnProperty(group)) {
|
|
Chris@0
|
483 var rowSettings = self.rowSettings(group, droppedRow);
|
|
Chris@0
|
484 if (rowSettings.relationship === 'group') {
|
|
Chris@0
|
485 for (var n in self.rowObject.children) {
|
|
Chris@0
|
486 if (self.rowObject.children.hasOwnProperty(n)) {
|
|
Chris@0
|
487 self.updateField(self.rowObject.children[n], group);
|
|
Chris@0
|
488 }
|
|
Chris@0
|
489 }
|
|
Chris@0
|
490 }
|
|
Chris@0
|
491 }
|
|
Chris@0
|
492 }
|
|
Chris@0
|
493
|
|
Chris@0
|
494 self.rowObject.markChanged();
|
|
Chris@0
|
495 if (self.changed === false) {
|
|
Chris@0
|
496 $(Drupal.theme('tableDragChangedWarning')).insertBefore(self.table).hide().fadeIn('slow');
|
|
Chris@0
|
497 self.changed = true;
|
|
Chris@0
|
498 }
|
|
Chris@0
|
499 }
|
|
Chris@0
|
500
|
|
Chris@0
|
501 if (self.indentEnabled) {
|
|
Chris@0
|
502 self.rowObject.removeIndentClasses();
|
|
Chris@0
|
503 }
|
|
Chris@0
|
504 if (self.oldRowElement) {
|
|
Chris@0
|
505 $(self.oldRowElement).removeClass('drag-previous');
|
|
Chris@0
|
506 }
|
|
Chris@0
|
507 $droppedRow.removeClass('drag').addClass('drag-previous');
|
|
Chris@0
|
508 self.oldRowElement = droppedRow;
|
|
Chris@0
|
509 self.onDrop();
|
|
Chris@0
|
510 self.rowObject = null;
|
|
Chris@0
|
511 }
|
|
Chris@0
|
512
|
|
Chris@0
|
513 if (self.dragObject !== null) {
|
|
Chris@0
|
514 self.dragObject = null;
|
|
Chris@0
|
515 $('body').removeClass('drag');
|
|
Chris@0
|
516 clearInterval(self.scrollInterval);
|
|
Chris@0
|
517 }
|
|
Chris@0
|
518 };
|
|
Chris@0
|
519
|
|
Chris@0
|
520 Drupal.tableDrag.prototype.pointerCoords = function (event) {
|
|
Chris@0
|
521 if (event.pageX || event.pageY) {
|
|
Chris@0
|
522 return { x: event.pageX, y: event.pageY };
|
|
Chris@0
|
523 }
|
|
Chris@0
|
524 return {
|
|
Chris@0
|
525 x: event.clientX + document.body.scrollLeft - document.body.clientLeft,
|
|
Chris@0
|
526 y: event.clientY + document.body.scrollTop - document.body.clientTop
|
|
Chris@0
|
527 };
|
|
Chris@0
|
528 };
|
|
Chris@0
|
529
|
|
Chris@0
|
530 Drupal.tableDrag.prototype.getPointerOffset = function (target, event) {
|
|
Chris@0
|
531 var docPos = $(target).offset();
|
|
Chris@0
|
532 var pointerPos = this.pointerCoords(event);
|
|
Chris@0
|
533 return { x: pointerPos.x - docPos.left, y: pointerPos.y - docPos.top };
|
|
Chris@0
|
534 };
|
|
Chris@0
|
535
|
|
Chris@0
|
536 Drupal.tableDrag.prototype.findDropTargetRow = function (x, y) {
|
|
Chris@0
|
537 var rows = $(this.table.tBodies[0].rows).not(':hidden');
|
|
Chris@0
|
538 for (var n = 0; n < rows.length; n++) {
|
|
Chris@0
|
539 var row = rows[n];
|
|
Chris@0
|
540 var $row = $(row);
|
|
Chris@0
|
541 var rowY = $row.offset().top;
|
|
Chris@0
|
542 var rowHeight;
|
|
Chris@0
|
543
|
|
Chris@0
|
544 if (row.offsetHeight === 0) {
|
|
Chris@0
|
545 rowHeight = parseInt(row.firstChild.offsetHeight, 10) / 2;
|
|
Chris@0
|
546 } else {
|
|
Chris@0
|
547 rowHeight = parseInt(row.offsetHeight, 10) / 2;
|
|
Chris@0
|
548 }
|
|
Chris@0
|
549
|
|
Chris@0
|
550 if (y > rowY - rowHeight && y < rowY + rowHeight) {
|
|
Chris@0
|
551 if (this.indentEnabled) {
|
|
Chris@0
|
552 for (n in this.rowObject.group) {
|
|
Chris@0
|
553 if (this.rowObject.group[n] === row) {
|
|
Chris@0
|
554 return null;
|
|
Chris@0
|
555 }
|
|
Chris@0
|
556 }
|
|
Chris@0
|
557 } else {
|
|
Chris@0
|
558 if (row === this.rowObject.element) {
|
|
Chris@0
|
559 return null;
|
|
Chris@0
|
560 }
|
|
Chris@0
|
561 }
|
|
Chris@0
|
562
|
|
Chris@0
|
563 if (!this.rowObject.isValidSwap(row)) {
|
|
Chris@0
|
564 return null;
|
|
Chris@0
|
565 }
|
|
Chris@0
|
566
|
|
Chris@0
|
567 while ($row.is(':hidden') && $row.prev('tr').is(':hidden')) {
|
|
Chris@0
|
568 $row = $row.prev('tr:first-of-type');
|
|
Chris@0
|
569 row = $row.get(0);
|
|
Chris@0
|
570 }
|
|
Chris@0
|
571 return row;
|
|
Chris@0
|
572 }
|
|
Chris@0
|
573 }
|
|
Chris@0
|
574 return null;
|
|
Chris@0
|
575 };
|
|
Chris@0
|
576
|
|
Chris@0
|
577 Drupal.tableDrag.prototype.updateFields = function (changedRow) {
|
|
Chris@0
|
578 for (var group in this.tableSettings) {
|
|
Chris@0
|
579 if (this.tableSettings.hasOwnProperty(group)) {
|
|
Chris@0
|
580 this.updateField(changedRow, group);
|
|
Chris@0
|
581 }
|
|
Chris@0
|
582 }
|
|
Chris@0
|
583 };
|
|
Chris@0
|
584
|
|
Chris@0
|
585 Drupal.tableDrag.prototype.updateField = function (changedRow, group) {
|
|
Chris@0
|
586 var rowSettings = this.rowSettings(group, changedRow);
|
|
Chris@0
|
587 var $changedRow = $(changedRow);
|
|
Chris@0
|
588 var sourceRow = void 0;
|
|
Chris@0
|
589 var $previousRow = void 0;
|
|
Chris@0
|
590 var previousRow = void 0;
|
|
Chris@0
|
591 var useSibling = void 0;
|
|
Chris@0
|
592
|
|
Chris@0
|
593 if (rowSettings.relationship === 'self' || rowSettings.relationship === 'group') {
|
|
Chris@0
|
594 sourceRow = changedRow;
|
|
Chris@0
|
595 } else if (rowSettings.relationship === 'sibling') {
|
|
Chris@0
|
596 $previousRow = $changedRow.prev('tr:first-of-type');
|
|
Chris@0
|
597 previousRow = $previousRow.get(0);
|
|
Chris@0
|
598 var $nextRow = $changedRow.next('tr:first-of-type');
|
|
Chris@0
|
599 var nextRow = $nextRow.get(0);
|
|
Chris@0
|
600 sourceRow = changedRow;
|
|
Chris@0
|
601 if ($previousRow.is('.draggable') && $previousRow.find('.' + group).length) {
|
|
Chris@0
|
602 if (this.indentEnabled) {
|
|
Chris@0
|
603 if ($previousRow.find('.js-indentations').length === $changedRow.find('.js-indentations').length) {
|
|
Chris@0
|
604 sourceRow = previousRow;
|
|
Chris@0
|
605 }
|
|
Chris@0
|
606 } else {
|
|
Chris@0
|
607 sourceRow = previousRow;
|
|
Chris@0
|
608 }
|
|
Chris@0
|
609 } else if ($nextRow.is('.draggable') && $nextRow.find('.' + group).length) {
|
|
Chris@0
|
610 if (this.indentEnabled) {
|
|
Chris@0
|
611 if ($nextRow.find('.js-indentations').length === $changedRow.find('.js-indentations').length) {
|
|
Chris@0
|
612 sourceRow = nextRow;
|
|
Chris@0
|
613 }
|
|
Chris@0
|
614 } else {
|
|
Chris@0
|
615 sourceRow = nextRow;
|
|
Chris@0
|
616 }
|
|
Chris@0
|
617 }
|
|
Chris@0
|
618 } else if (rowSettings.relationship === 'parent') {
|
|
Chris@0
|
619 $previousRow = $changedRow.prev('tr');
|
|
Chris@0
|
620 previousRow = $previousRow;
|
|
Chris@0
|
621 while ($previousRow.length && $previousRow.find('.js-indentation').length >= this.rowObject.indents) {
|
|
Chris@0
|
622 $previousRow = $previousRow.prev('tr');
|
|
Chris@0
|
623 previousRow = $previousRow;
|
|
Chris@0
|
624 }
|
|
Chris@0
|
625
|
|
Chris@0
|
626 if ($previousRow.length) {
|
|
Chris@0
|
627 sourceRow = $previousRow.get(0);
|
|
Chris@0
|
628 } else {
|
|
Chris@0
|
629 sourceRow = $(this.table).find('tr.draggable:first-of-type').get(0);
|
|
Chris@0
|
630 if (sourceRow === this.rowObject.element) {
|
|
Chris@0
|
631 sourceRow = $(this.rowObject.group[this.rowObject.group.length - 1]).next('tr.draggable').get(0);
|
|
Chris@0
|
632 }
|
|
Chris@0
|
633 useSibling = true;
|
|
Chris@0
|
634 }
|
|
Chris@0
|
635 }
|
|
Chris@0
|
636
|
|
Chris@0
|
637 this.copyDragClasses(sourceRow, changedRow, group);
|
|
Chris@0
|
638 rowSettings = this.rowSettings(group, changedRow);
|
|
Chris@0
|
639
|
|
Chris@0
|
640 if (useSibling) {
|
|
Chris@0
|
641 rowSettings.relationship = 'sibling';
|
|
Chris@0
|
642 rowSettings.source = rowSettings.target;
|
|
Chris@0
|
643 }
|
|
Chris@0
|
644
|
|
Chris@0
|
645 var targetClass = '.' + rowSettings.target;
|
|
Chris@0
|
646 var targetElement = $changedRow.find(targetClass).get(0);
|
|
Chris@0
|
647
|
|
Chris@0
|
648 if (targetElement) {
|
|
Chris@0
|
649 var sourceClass = '.' + rowSettings.source;
|
|
Chris@0
|
650 var sourceElement = $(sourceClass, sourceRow).get(0);
|
|
Chris@0
|
651 switch (rowSettings.action) {
|
|
Chris@0
|
652 case 'depth':
|
|
Chris@0
|
653 targetElement.value = $(sourceElement).closest('tr').find('.js-indentation').length;
|
|
Chris@0
|
654 break;
|
|
Chris@0
|
655
|
|
Chris@0
|
656 case 'match':
|
|
Chris@0
|
657 targetElement.value = sourceElement.value;
|
|
Chris@0
|
658 break;
|
|
Chris@0
|
659
|
|
Chris@0
|
660 case 'order':
|
|
Chris@0
|
661 var siblings = this.rowObject.findSiblings(rowSettings);
|
|
Chris@0
|
662 if ($(targetElement).is('select')) {
|
|
Chris@0
|
663 var values = [];
|
|
Chris@0
|
664 $(targetElement).find('option').each(function () {
|
|
Chris@0
|
665 values.push(this.value);
|
|
Chris@0
|
666 });
|
|
Chris@0
|
667 var maxVal = values[values.length - 1];
|
|
Chris@0
|
668
|
|
Chris@0
|
669 $(siblings).find(targetClass).each(function () {
|
|
Chris@0
|
670 if (values.length > 0) {
|
|
Chris@0
|
671 this.value = values.shift();
|
|
Chris@0
|
672 } else {
|
|
Chris@0
|
673 this.value = maxVal;
|
|
Chris@0
|
674 }
|
|
Chris@0
|
675 });
|
|
Chris@0
|
676 } else {
|
|
Chris@0
|
677 var weight = parseInt($(siblings[0]).find(targetClass).val(), 10) || 0;
|
|
Chris@0
|
678 $(siblings).find(targetClass).each(function () {
|
|
Chris@0
|
679 this.value = weight;
|
|
Chris@0
|
680 weight++;
|
|
Chris@0
|
681 });
|
|
Chris@0
|
682 }
|
|
Chris@0
|
683 break;
|
|
Chris@0
|
684 }
|
|
Chris@0
|
685 }
|
|
Chris@0
|
686 };
|
|
Chris@0
|
687
|
|
Chris@0
|
688 Drupal.tableDrag.prototype.copyDragClasses = function (sourceRow, targetRow, group) {
|
|
Chris@0
|
689 var sourceElement = $(sourceRow).find('.' + group);
|
|
Chris@0
|
690 var targetElement = $(targetRow).find('.' + group);
|
|
Chris@0
|
691 if (sourceElement.length && targetElement.length) {
|
|
Chris@0
|
692 targetElement[0].className = sourceElement[0].className;
|
|
Chris@0
|
693 }
|
|
Chris@0
|
694 };
|
|
Chris@0
|
695
|
|
Chris@0
|
696 Drupal.tableDrag.prototype.checkScroll = function (cursorY) {
|
|
Chris@0
|
697 var de = document.documentElement;
|
|
Chris@0
|
698 var b = document.body;
|
|
Chris@0
|
699
|
|
Chris@0
|
700 var windowHeight = this.windowHeight = window.innerHeight || (de.clientHeight && de.clientWidth !== 0 ? de.clientHeight : b.offsetHeight);
|
|
Chris@0
|
701 var scrollY = void 0;
|
|
Chris@0
|
702 if (document.all) {
|
|
Chris@0
|
703 scrollY = this.scrollY = !de.scrollTop ? b.scrollTop : de.scrollTop;
|
|
Chris@0
|
704 } else {
|
|
Chris@0
|
705 scrollY = this.scrollY = window.pageYOffset ? window.pageYOffset : window.scrollY;
|
|
Chris@0
|
706 }
|
|
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 minIndent = void 0;
|
|
Chris@0
|
848 var maxIndent = void 0;
|
|
Chris@0
|
849
|
|
Chris@0
|
850 minIndent = nextRow ? $(nextRow).find('.js-indentation').length : 0;
|
|
Chris@0
|
851
|
|
Chris@0
|
852 if (!prevRow || $prevRow.is(':not(.draggable)') || $(this.element).is('.tabledrag-root')) {
|
|
Chris@0
|
853 maxIndent = 0;
|
|
Chris@0
|
854 } else {
|
|
Chris@0
|
855 maxIndent = $prevRow.find('.js-indentation').length + ($prevRow.is('.tabledrag-leaf') ? 0 : 1);
|
|
Chris@0
|
856
|
|
Chris@0
|
857 if (this.maxDepth) {
|
|
Chris@0
|
858 maxIndent = Math.min(maxIndent, this.maxDepth - (this.groupDepth - this.indents));
|
|
Chris@0
|
859 }
|
|
Chris@0
|
860 }
|
|
Chris@0
|
861
|
|
Chris@0
|
862 return { min: minIndent, max: maxIndent };
|
|
Chris@0
|
863 };
|
|
Chris@0
|
864
|
|
Chris@0
|
865 Drupal.tableDrag.prototype.row.prototype.indent = function (indentDiff) {
|
|
Chris@0
|
866 var $group = $(this.group);
|
|
Chris@0
|
867
|
|
Chris@0
|
868 if (!this.interval) {
|
|
Chris@0
|
869 var prevRow = $(this.element).prev('tr').get(0);
|
|
Chris@0
|
870 var nextRow = $group.eq(-1).next('tr').get(0);
|
|
Chris@0
|
871 this.interval = this.validIndentInterval(prevRow, nextRow);
|
|
Chris@0
|
872 }
|
|
Chris@0
|
873
|
|
Chris@0
|
874 var indent = this.indents + indentDiff;
|
|
Chris@0
|
875 indent = Math.max(indent, this.interval.min);
|
|
Chris@0
|
876 indent = Math.min(indent, this.interval.max);
|
|
Chris@0
|
877 indentDiff = indent - this.indents;
|
|
Chris@0
|
878
|
|
Chris@0
|
879 for (var n = 1; n <= Math.abs(indentDiff); n++) {
|
|
Chris@0
|
880 if (indentDiff < 0) {
|
|
Chris@0
|
881 $group.find('.js-indentation:first-of-type').remove();
|
|
Chris@0
|
882 this.indents--;
|
|
Chris@0
|
883 } else {
|
|
Chris@0
|
884 $group.find('td:first-of-type').prepend(Drupal.theme('tableDragIndentation'));
|
|
Chris@0
|
885 this.indents++;
|
|
Chris@0
|
886 }
|
|
Chris@0
|
887 }
|
|
Chris@0
|
888 if (indentDiff) {
|
|
Chris@0
|
889 this.changed = true;
|
|
Chris@0
|
890 this.groupDepth += indentDiff;
|
|
Chris@0
|
891 this.onIndent();
|
|
Chris@0
|
892 }
|
|
Chris@0
|
893
|
|
Chris@0
|
894 return indentDiff;
|
|
Chris@0
|
895 };
|
|
Chris@0
|
896
|
|
Chris@0
|
897 Drupal.tableDrag.prototype.row.prototype.findSiblings = function (rowSettings) {
|
|
Chris@0
|
898 var siblings = [];
|
|
Chris@0
|
899 var directions = ['prev', 'next'];
|
|
Chris@0
|
900 var rowIndentation = this.indents;
|
|
Chris@0
|
901 var checkRowIndentation = void 0;
|
|
Chris@0
|
902 for (var d = 0; d < directions.length; d++) {
|
|
Chris@0
|
903 var checkRow = $(this.element)[directions[d]]();
|
|
Chris@0
|
904 while (checkRow.length) {
|
|
Chris@0
|
905 if (checkRow.find('.' + rowSettings.target)) {
|
|
Chris@0
|
906 if (this.indentEnabled) {
|
|
Chris@0
|
907 checkRowIndentation = checkRow.find('.js-indentation').length;
|
|
Chris@0
|
908 }
|
|
Chris@0
|
909
|
|
Chris@0
|
910 if (!this.indentEnabled || checkRowIndentation === rowIndentation) {
|
|
Chris@0
|
911 siblings.push(checkRow[0]);
|
|
Chris@0
|
912 } else if (checkRowIndentation < rowIndentation) {
|
|
Chris@0
|
913 break;
|
|
Chris@0
|
914 }
|
|
Chris@0
|
915 } else {
|
|
Chris@0
|
916 break;
|
|
Chris@0
|
917 }
|
|
Chris@0
|
918 checkRow = checkRow[directions[d]]();
|
|
Chris@0
|
919 }
|
|
Chris@0
|
920
|
|
Chris@0
|
921 if (directions[d] === 'prev') {
|
|
Chris@0
|
922 siblings.reverse();
|
|
Chris@0
|
923 siblings.push(this.element);
|
|
Chris@0
|
924 }
|
|
Chris@0
|
925 }
|
|
Chris@0
|
926 return siblings;
|
|
Chris@0
|
927 };
|
|
Chris@0
|
928
|
|
Chris@0
|
929 Drupal.tableDrag.prototype.row.prototype.removeIndentClasses = function () {
|
|
Chris@0
|
930 for (var n in this.children) {
|
|
Chris@0
|
931 if (this.children.hasOwnProperty(n)) {
|
|
Chris@0
|
932 $(this.children[n]).find('.js-indentation').removeClass('tree-child').removeClass('tree-child-first').removeClass('tree-child-last').removeClass('tree-child-horizontal');
|
|
Chris@0
|
933 }
|
|
Chris@0
|
934 }
|
|
Chris@0
|
935 };
|
|
Chris@0
|
936
|
|
Chris@0
|
937 Drupal.tableDrag.prototype.row.prototype.markChanged = function () {
|
|
Chris@0
|
938 var marker = Drupal.theme('tableDragChangedMarker');
|
|
Chris@0
|
939 var cell = $(this.element).find('td:first-of-type');
|
|
Chris@0
|
940 if (cell.find('abbr.tabledrag-changed').length === 0) {
|
|
Chris@0
|
941 cell.append(marker);
|
|
Chris@0
|
942 }
|
|
Chris@0
|
943 };
|
|
Chris@0
|
944
|
|
Chris@0
|
945 Drupal.tableDrag.prototype.row.prototype.onIndent = function () {
|
|
Chris@0
|
946 return null;
|
|
Chris@0
|
947 };
|
|
Chris@0
|
948
|
|
Chris@0
|
949 Drupal.tableDrag.prototype.row.prototype.onSwap = function (swappedRow) {
|
|
Chris@0
|
950 return null;
|
|
Chris@0
|
951 };
|
|
Chris@0
|
952
|
|
Chris@0
|
953 $.extend(Drupal.theme, {
|
|
Chris@0
|
954 tableDragChangedMarker: function tableDragChangedMarker() {
|
|
Chris@0
|
955 return '<abbr class="warning tabledrag-changed" title="' + Drupal.t('Changed') + '">*</abbr>';
|
|
Chris@0
|
956 },
|
|
Chris@0
|
957 tableDragIndentation: function tableDragIndentation() {
|
|
Chris@0
|
958 return '<div class="js-indentation indentation"> </div>';
|
|
Chris@0
|
959 },
|
|
Chris@0
|
960 tableDragChangedWarning: function tableDragChangedWarning() {
|
|
Chris@0
|
961 return '<div class="tabledrag-changed-warning messages messages--warning" role="alert">' + Drupal.theme('tableDragChangedMarker') + ' ' + Drupal.t('You have unsaved changes.') + '</div>';
|
|
Chris@0
|
962 }
|
|
Chris@0
|
963 });
|
|
Chris@0
|
964 })(jQuery, Drupal, drupalSettings); |