2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function ($, Drupal, drupalSettings) {
9 var showWeight = JSON.parse(localStorage.getItem('Drupal.tableDrag.showWeight'));
11 Drupal.behaviors.tableDrag = {
12 attach: function attach(context, settings) {
13 function initTableDrag(table, base) {
15 Drupal.tableDrag[base] = new Drupal.tableDrag(table[0], settings.tableDrag[base]);
19 for (var base in settings.tableDrag) {
20 if (settings.tableDrag.hasOwnProperty(base)) {
21 initTableDrag($(context).find('#' + base).once('tabledrag'), base);
27 Drupal.tableDrag = function (table, tableSettings) {
29 var $table = $(table);
31 this.$table = $(table);
35 this.tableSettings = tableSettings;
37 this.dragObject = null;
39 this.rowObject = null;
41 this.oldRowElement = null;
49 this.rtl = $(this.table).css('direction') === 'rtl' ? -1 : 1;
51 this.striping = $(this.table).data('striping') === 1;
53 this.scrollSettings = { amount: 4, interval: 50, trigger: 70 };
55 this.scrollInterval = null;
59 this.windowHeight = 0;
61 this.indentEnabled = false;
62 for (var group in tableSettings) {
63 if (tableSettings.hasOwnProperty(group)) {
64 for (var n in tableSettings[group]) {
65 if (tableSettings[group].hasOwnProperty(n)) {
66 if (tableSettings[group][n].relationship === 'parent') {
67 this.indentEnabled = true;
69 if (tableSettings[group][n].limit > 0) {
70 this.maxDepth = tableSettings[group][n].limit;
76 if (this.indentEnabled) {
79 var indent = Drupal.theme('tableDragIndentation');
80 var testRow = $('<tr/>').addClass('draggable').appendTo(table);
81 var testCell = $('<td/>').appendTo(testRow).prepend(indent).prepend(indent);
82 var $indentation = testCell.find('.js-indentation');
84 this.indentAmount = $indentation.get(1).offsetLeft - $indentation.get(0).offsetLeft;
88 $table.find('> tr.draggable, > tbody > tr.draggable').each(function () {
89 self.makeDraggable(this);
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) {
95 }, this)).wrap('<div class="tabledrag-toggle-weight-wrapper"></div>').parent());
99 $(document).on('touchmove', function (event) {
100 return self.dragRow(event.originalEvent.touches[0], self);
102 $(document).on('touchend', function (event) {
103 return self.dropRow(event.originalEvent.touches[0], self);
105 $(document).on('mousemove pointermove', function (event) {
106 return self.dragRow(event, self);
108 $(document).on('mouseup pointerup', function (event) {
109 return self.dropRow(event, self);
112 $(window).on('storage', $.proxy(function (e) {
113 if (e.originalEvent.key === 'Drupal.tableDrag.showWeight') {
114 showWeight = JSON.parse(e.originalEvent.newValue);
115 this.displayColumns(showWeight);
120 Drupal.tableDrag.prototype.initColumns = function () {
121 var $table = this.$table;
124 var columnIndex = void 0;
125 for (var group in this.tableSettings) {
126 if (this.tableSettings.hasOwnProperty(group)) {
127 for (var d in this.tableSettings[group]) {
128 if (this.tableSettings[group].hasOwnProperty(d)) {
129 var field = $table.find('.' + this.tableSettings[group][d].target).eq(0);
130 if (field.length && this.tableSettings[group][d].hidden) {
131 hidden = this.tableSettings[group][d].hidden;
132 cell = field.closest('td');
138 if (hidden && cell[0]) {
139 columnIndex = cell.parent().find('> td').index(cell.get(0)) + 1;
140 $table.find('> thead > tr, > tbody > tr, > tr').each(this.addColspanClass(columnIndex));
144 this.displayColumns(showWeight);
147 Drupal.tableDrag.prototype.addColspanClass = function (columnIndex) {
150 var index = columnIndex;
151 var cells = $row.children();
153 cells.each(function (n) {
154 if (n < index && this.colSpan && this.colSpan > 1) {
155 index -= this.colSpan - 1;
159 cell = cells.filter(':nth-child(' + index + ')');
160 if (cell[0].colSpan && cell[0].colSpan > 1) {
161 cell.addClass('tabledrag-has-colspan');
163 cell.addClass('tabledrag-hide');
169 Drupal.tableDrag.prototype.displayColumns = function (displayWeight) {
176 $('table').findOnce('tabledrag').trigger('columnschange', !!displayWeight);
179 Drupal.tableDrag.prototype.toggleColumns = function () {
180 showWeight = !showWeight;
181 this.displayColumns(showWeight);
183 localStorage.setItem('Drupal.tableDrag.showWeight', showWeight);
185 localStorage.removeItem('Drupal.tableDrag.showWeight');
189 Drupal.tableDrag.prototype.hideColumns = function () {
190 var $tables = $('table').findOnce('tabledrag');
192 $tables.find('.tabledrag-hide').css('display', 'none');
194 $tables.find('.tabledrag-handle').css('display', '');
196 $tables.find('.tabledrag-has-colspan').each(function () {
197 this.colSpan = this.colSpan - 1;
200 $('.tabledrag-toggle-weight').text(Drupal.t('Show row weights'));
203 Drupal.tableDrag.prototype.showColumns = function () {
204 var $tables = $('table').findOnce('tabledrag');
206 $tables.find('.tabledrag-hide').css('display', '');
208 $tables.find('.tabledrag-handle').css('display', 'none');
210 $tables.find('.tabledrag-has-colspan').each(function () {
211 this.colSpan = this.colSpan + 1;
214 $('.tabledrag-toggle-weight').text(Drupal.t('Hide row weights'));
217 Drupal.tableDrag.prototype.rowSettings = function (group, row) {
218 var field = $(row).find('.' + group);
219 var tableSettingsGroup = this.tableSettings[group];
220 for (var delta in tableSettingsGroup) {
221 if (tableSettingsGroup.hasOwnProperty(delta)) {
222 var targetClass = tableSettingsGroup[delta].target;
223 if (field.is('.' + targetClass)) {
224 var rowSettings = {};
225 for (var n in tableSettingsGroup[delta]) {
226 if (tableSettingsGroup[delta].hasOwnProperty(n)) {
227 rowSettings[n] = tableSettingsGroup[delta][n];
236 Drupal.tableDrag.prototype.makeDraggable = function (item) {
240 $item.find('td:first-of-type').find('a').addClass('menu-item__link');
242 var handle = $('<a href="#" class="tabledrag-handle"><div class="handle"> </div></a>').attr('title', Drupal.t('Drag to re-order'));
244 var $indentationLast = $item.find('td:first-of-type').find('.js-indentation').eq(-1);
245 if ($indentationLast.length) {
246 $indentationLast.after(handle);
248 self.indentCount = Math.max($item.find('.js-indentation').length, self.indentCount);
250 $item.find('td').eq(0).prepend(handle);
253 handle.on('mousedown touchstart pointerdown', function (event) {
254 event.preventDefault();
255 if (event.originalEvent.type === 'touchstart') {
256 event = event.originalEvent.touches[0];
258 self.dragStart(event, self, item);
261 handle.on('click', function (e) {
265 handle.on('focus', function () {
266 self.safeBlur = true;
269 handle.on('blur', function (event) {
270 if (self.rowObject && self.safeBlur) {
271 self.dropRow(event, self);
275 handle.on('keydown', function (event) {
276 if (event.keyCode !== 9 && !self.rowObject) {
277 self.rowObject = new self.row(item, 'keyboard', self.indentEnabled, self.maxDepth, true);
280 var keyChange = false;
281 var groupHeight = void 0;
283 switch (event.keyCode) {
287 self.rowObject.indent(-1 * self.rtl);
292 var $previousRow = $(self.rowObject.element).prev('tr:first-of-type');
293 var previousRow = $previousRow.get(0);
294 while (previousRow && $previousRow.is(':hidden')) {
295 $previousRow = $(previousRow).prev('tr:first-of-type');
296 previousRow = $previousRow.get(0);
299 self.safeBlur = false;
300 self.rowObject.direction = 'up';
303 if ($(item).is('.tabledrag-root')) {
305 while (previousRow && $previousRow.find('.js-indentation').length) {
306 $previousRow = $(previousRow).prev('tr:first-of-type');
307 previousRow = $previousRow.get(0);
308 groupHeight += $previousRow.is(':hidden') ? 0 : previousRow.offsetHeight;
311 self.rowObject.swap('before', previousRow);
313 window.scrollBy(0, -groupHeight);
315 } else if (self.table.tBodies[0].rows[0] !== previousRow || $previousRow.is('.draggable')) {
316 self.rowObject.swap('before', previousRow);
317 self.rowObject.interval = null;
318 self.rowObject.indent(0);
319 window.scrollBy(0, -parseInt(item.offsetHeight, 10));
322 handle.trigger('focus');
329 self.rowObject.indent(self.rtl);
334 var $nextRow = $(self.rowObject.group).eq(-1).next('tr:first-of-type');
335 var nextRow = $nextRow.get(0);
336 while (nextRow && $nextRow.is(':hidden')) {
337 $nextRow = $(nextRow).next('tr:first-of-type');
338 nextRow = $nextRow.get(0);
341 self.safeBlur = false;
342 self.rowObject.direction = 'down';
345 if ($(item).is('.tabledrag-root')) {
347 var nextGroup = new self.row(nextRow, 'keyboard', self.indentEnabled, self.maxDepth, false);
349 $(nextGroup.group).each(function () {
350 groupHeight += $(this).is(':hidden') ? 0 : this.offsetHeight;
352 var nextGroupRow = $(nextGroup.group).eq(-1).get(0);
353 self.rowObject.swap('after', nextGroupRow);
355 window.scrollBy(0, parseInt(groupHeight, 10));
358 self.rowObject.swap('after', nextRow);
359 self.rowObject.interval = null;
360 self.rowObject.indent(0);
361 window.scrollBy(0, parseInt(item.offsetHeight, 10));
364 handle.trigger('focus');
369 if (self.rowObject && self.rowObject.changed === true) {
370 $(item).addClass('drag');
371 if (self.oldRowElement) {
372 $(self.oldRowElement).removeClass('drag-previous');
374 self.oldRowElement = item;
375 if (self.striping === true) {
376 self.restripeTable();
386 handle.on('keypress', function (event) {
388 switch (event.keyCode) {
398 Drupal.tableDrag.prototype.dragStart = function (event, self, item) {
399 self.dragObject = {};
400 self.dragObject.initOffset = self.getPointerOffset(item, event);
401 self.dragObject.initPointerCoords = self.pointerCoords(event);
402 if (self.indentEnabled) {
403 self.dragObject.indentPointerPos = self.dragObject.initPointerCoords;
406 if (self.rowObject) {
407 $(self.rowObject.element).find('a.tabledrag-handle').trigger('blur');
410 self.rowObject = new self.row(item, 'pointer', self.indentEnabled, self.maxDepth, true);
412 self.table.topY = $(self.table).offset().top;
413 self.table.bottomY = self.table.topY + self.table.offsetHeight;
415 $(item).addClass('drag');
417 $('body').addClass('drag');
418 if (self.oldRowElement) {
419 $(self.oldRowElement).removeClass('drag-previous');
423 Drupal.tableDrag.prototype.dragRow = function (event, self) {
424 if (self.dragObject) {
425 self.currentPointerCoords = self.pointerCoords(event);
426 var y = self.currentPointerCoords.y - self.dragObject.initOffset.y;
427 var x = self.currentPointerCoords.x - self.dragObject.initOffset.x;
429 if (y !== self.oldY) {
430 self.rowObject.direction = y > self.oldY ? 'down' : 'up';
434 var scrollAmount = self.checkScroll(self.currentPointerCoords.y);
436 clearInterval(self.scrollInterval);
438 if (scrollAmount > 0 && self.rowObject.direction === 'down' || scrollAmount < 0 && self.rowObject.direction === 'up') {
439 self.setScroll(scrollAmount);
442 var currentRow = self.findDropTargetRow(x, y);
444 if (self.rowObject.direction === 'down') {
445 self.rowObject.swap('after', currentRow, self);
447 self.rowObject.swap('before', currentRow, self);
449 if (self.striping === true) {
450 self.restripeTable();
455 if (self.indentEnabled) {
456 var xDiff = self.currentPointerCoords.x - self.dragObject.indentPointerPos.x;
458 var indentDiff = Math.round(xDiff / self.indentAmount);
460 var indentChange = self.rowObject.indent(indentDiff);
462 self.dragObject.indentPointerPos.x += self.indentAmount * indentChange * self.rtl;
463 self.indentCount = Math.max(self.indentCount, self.rowObject.indents);
470 Drupal.tableDrag.prototype.dropRow = function (event, self) {
471 var droppedRow = void 0;
472 var $droppedRow = void 0;
474 if (self.rowObject !== null) {
475 droppedRow = self.rowObject.element;
476 $droppedRow = $(droppedRow);
478 if (self.rowObject.changed === true) {
479 self.updateFields(droppedRow);
481 for (var group in self.tableSettings) {
482 if (self.tableSettings.hasOwnProperty(group)) {
483 var rowSettings = self.rowSettings(group, droppedRow);
484 if (rowSettings.relationship === 'group') {
485 for (var n in self.rowObject.children) {
486 if (self.rowObject.children.hasOwnProperty(n)) {
487 self.updateField(self.rowObject.children[n], group);
494 self.rowObject.markChanged();
495 if (self.changed === false) {
496 $(Drupal.theme('tableDragChangedWarning')).insertBefore(self.table).hide().fadeIn('slow');
501 if (self.indentEnabled) {
502 self.rowObject.removeIndentClasses();
504 if (self.oldRowElement) {
505 $(self.oldRowElement).removeClass('drag-previous');
507 $droppedRow.removeClass('drag').addClass('drag-previous');
508 self.oldRowElement = droppedRow;
510 self.rowObject = null;
513 if (self.dragObject !== null) {
514 self.dragObject = null;
515 $('body').removeClass('drag');
516 clearInterval(self.scrollInterval);
520 Drupal.tableDrag.prototype.pointerCoords = function (event) {
521 if (event.pageX || event.pageY) {
522 return { x: event.pageX, y: event.pageY };
525 x: event.clientX + document.body.scrollLeft - document.body.clientLeft,
526 y: event.clientY + document.body.scrollTop - document.body.clientTop
530 Drupal.tableDrag.prototype.getPointerOffset = function (target, event) {
531 var docPos = $(target).offset();
532 var pointerPos = this.pointerCoords(event);
533 return { x: pointerPos.x - docPos.left, y: pointerPos.y - docPos.top };
536 Drupal.tableDrag.prototype.findDropTargetRow = function (x, y) {
537 var rows = $(this.table.tBodies[0].rows).not(':hidden');
538 for (var n = 0; n < rows.length; n++) {
541 var rowY = $row.offset().top;
544 if (row.offsetHeight === 0) {
545 rowHeight = parseInt(row.firstChild.offsetHeight, 10) / 2;
547 rowHeight = parseInt(row.offsetHeight, 10) / 2;
550 if (y > rowY - rowHeight && y < rowY + rowHeight) {
551 if (this.indentEnabled) {
552 for (n in this.rowObject.group) {
553 if (this.rowObject.group[n] === row) {
558 if (row === this.rowObject.element) {
563 if (!this.rowObject.isValidSwap(row)) {
567 while ($row.is(':hidden') && $row.prev('tr').is(':hidden')) {
568 $row = $row.prev('tr:first-of-type');
577 Drupal.tableDrag.prototype.updateFields = function (changedRow) {
578 for (var group in this.tableSettings) {
579 if (this.tableSettings.hasOwnProperty(group)) {
580 this.updateField(changedRow, group);
585 Drupal.tableDrag.prototype.updateField = function (changedRow, group) {
586 var rowSettings = this.rowSettings(group, changedRow);
587 var $changedRow = $(changedRow);
588 var sourceRow = void 0;
589 var $previousRow = void 0;
590 var previousRow = void 0;
591 var useSibling = void 0;
593 if (rowSettings.relationship === 'self' || rowSettings.relationship === 'group') {
594 sourceRow = changedRow;
595 } else if (rowSettings.relationship === 'sibling') {
596 $previousRow = $changedRow.prev('tr:first-of-type');
597 previousRow = $previousRow.get(0);
598 var $nextRow = $changedRow.next('tr:first-of-type');
599 var nextRow = $nextRow.get(0);
600 sourceRow = changedRow;
601 if ($previousRow.is('.draggable') && $previousRow.find('.' + group).length) {
602 if (this.indentEnabled) {
603 if ($previousRow.find('.js-indentations').length === $changedRow.find('.js-indentations').length) {
604 sourceRow = previousRow;
607 sourceRow = previousRow;
609 } else if ($nextRow.is('.draggable') && $nextRow.find('.' + group).length) {
610 if (this.indentEnabled) {
611 if ($nextRow.find('.js-indentations').length === $changedRow.find('.js-indentations').length) {
618 } else if (rowSettings.relationship === 'parent') {
619 $previousRow = $changedRow.prev('tr');
620 previousRow = $previousRow;
621 while ($previousRow.length && $previousRow.find('.js-indentation').length >= this.rowObject.indents) {
622 $previousRow = $previousRow.prev('tr');
623 previousRow = $previousRow;
626 if ($previousRow.length) {
627 sourceRow = $previousRow.get(0);
629 sourceRow = $(this.table).find('tr.draggable:first-of-type').get(0);
630 if (sourceRow === this.rowObject.element) {
631 sourceRow = $(this.rowObject.group[this.rowObject.group.length - 1]).next('tr.draggable').get(0);
637 this.copyDragClasses(sourceRow, changedRow, group);
638 rowSettings = this.rowSettings(group, changedRow);
641 rowSettings.relationship = 'sibling';
642 rowSettings.source = rowSettings.target;
645 var targetClass = '.' + rowSettings.target;
646 var targetElement = $changedRow.find(targetClass).get(0);
649 var sourceClass = '.' + rowSettings.source;
650 var sourceElement = $(sourceClass, sourceRow).get(0);
651 switch (rowSettings.action) {
653 targetElement.value = $(sourceElement).closest('tr').find('.js-indentation').length;
657 targetElement.value = sourceElement.value;
661 var siblings = this.rowObject.findSiblings(rowSettings);
662 if ($(targetElement).is('select')) {
664 $(targetElement).find('option').each(function () {
665 values.push(this.value);
667 var maxVal = values[values.length - 1];
669 $(siblings).find(targetClass).each(function () {
670 if (values.length > 0) {
671 this.value = values.shift();
677 var weight = parseInt($(siblings[0]).find(targetClass).val(), 10) || 0;
678 $(siblings).find(targetClass).each(function () {
688 Drupal.tableDrag.prototype.copyDragClasses = function (sourceRow, targetRow, group) {
689 var sourceElement = $(sourceRow).find('.' + group);
690 var targetElement = $(targetRow).find('.' + group);
691 if (sourceElement.length && targetElement.length) {
692 targetElement[0].className = sourceElement[0].className;
696 Drupal.tableDrag.prototype.checkScroll = function (cursorY) {
697 var de = document.documentElement;
698 var b = document.body;
700 var windowHeight = this.windowHeight = window.innerHeight || (de.clientHeight && de.clientWidth !== 0 ? de.clientHeight : b.offsetHeight);
701 var scrollY = void 0;
703 scrollY = this.scrollY = !de.scrollTop ? b.scrollTop : de.scrollTop;
705 scrollY = this.scrollY = window.pageYOffset ? window.pageYOffset : window.scrollY;
707 var trigger = this.scrollSettings.trigger;
710 if (cursorY - scrollY > windowHeight - trigger) {
711 delta = trigger / (windowHeight + scrollY - cursorY);
712 delta = delta > 0 && delta < trigger ? delta : trigger;
713 return delta * this.scrollSettings.amount;
714 } else if (cursorY - scrollY < trigger) {
715 delta = trigger / (cursorY - scrollY);
716 delta = delta > 0 && delta < trigger ? delta : trigger;
717 return -delta * this.scrollSettings.amount;
721 Drupal.tableDrag.prototype.setScroll = function (scrollAmount) {
724 this.scrollInterval = setInterval(function () {
725 self.checkScroll(self.currentPointerCoords.y);
726 var aboveTable = self.scrollY > self.table.topY;
727 var belowTable = self.scrollY + self.windowHeight < self.table.bottomY;
728 if (scrollAmount > 0 && belowTable || scrollAmount < 0 && aboveTable) {
729 window.scrollBy(0, scrollAmount);
731 }, this.scrollSettings.interval);
734 Drupal.tableDrag.prototype.restripeTable = function () {
735 $(this.table).find('> tbody > tr.draggable, > tr.draggable').filter(':visible').filter(':odd').removeClass('odd').addClass('even').end().filter(':even').removeClass('even').addClass('odd');
738 Drupal.tableDrag.prototype.onDrag = function () {
742 Drupal.tableDrag.prototype.onDrop = function () {
746 Drupal.tableDrag.prototype.row = function (tableRow, method, indentEnabled, maxDepth, addClasses) {
747 var $tableRow = $(tableRow);
749 this.element = tableRow;
750 this.method = method;
751 this.group = [tableRow];
752 this.groupDepth = $tableRow.find('.js-indentation').length;
753 this.changed = false;
754 this.table = $tableRow.closest('table')[0];
755 this.indentEnabled = indentEnabled;
756 this.maxDepth = maxDepth;
759 if (this.indentEnabled) {
760 this.indents = $tableRow.find('.js-indentation').length;
761 this.children = this.findChildren(addClasses);
762 this.group = $.merge(this.group, this.children);
764 for (var n = 0; n < this.group.length; n++) {
765 this.groupDepth = Math.max($(this.group[n]).find('.js-indentation').length, this.groupDepth);
770 Drupal.tableDrag.prototype.row.prototype.findChildren = function (addClasses) {
771 var parentIndentation = this.indents;
772 var currentRow = $(this.element, this.table).next('tr.draggable');
776 function rowIndentation(indentNum, el) {
778 if (child === 1 && indentNum === parentIndentation) {
779 self.addClass('tree-child-first');
781 if (indentNum === parentIndentation) {
782 self.addClass('tree-child');
783 } else if (indentNum > parentIndentation) {
784 self.addClass('tree-child-horizontal');
788 while (currentRow.length) {
789 if (currentRow.find('.js-indentation').length > parentIndentation) {
791 rows.push(currentRow[0]);
793 currentRow.find('.js-indentation').each(rowIndentation);
798 currentRow = currentRow.next('tr.draggable');
800 if (addClasses && rows.length) {
801 $(rows[rows.length - 1]).find('.js-indentation:nth-child(' + (parentIndentation + 1) + ')').addClass('tree-child-last');
806 Drupal.tableDrag.prototype.row.prototype.isValidSwap = function (row) {
808 if (this.indentEnabled) {
809 var prevRow = void 0;
810 var nextRow = void 0;
811 if (this.direction === 'down') {
813 nextRow = $row.next('tr').get(0);
815 prevRow = $row.prev('tr').get(0);
818 this.interval = this.validIndentInterval(prevRow, nextRow);
820 if (this.interval.min > this.interval.max) {
825 if (this.table.tBodies[0].rows[0] === row && $row.is(':not(.draggable)')) {
832 Drupal.tableDrag.prototype.row.prototype.swap = function (position, row) {
833 this.group.forEach(function (row) {
834 Drupal.detachBehaviors(row, drupalSettings, 'move');
836 $(row)[position](this.group);
838 this.group.forEach(function (row) {
839 Drupal.attachBehaviors(row, drupalSettings);
845 Drupal.tableDrag.prototype.row.prototype.validIndentInterval = function (prevRow, nextRow) {
846 var $prevRow = $(prevRow);
847 var minIndent = void 0;
848 var maxIndent = void 0;
850 minIndent = nextRow ? $(nextRow).find('.js-indentation').length : 0;
852 if (!prevRow || $prevRow.is(':not(.draggable)') || $(this.element).is('.tabledrag-root')) {
855 maxIndent = $prevRow.find('.js-indentation').length + ($prevRow.is('.tabledrag-leaf') ? 0 : 1);
858 maxIndent = Math.min(maxIndent, this.maxDepth - (this.groupDepth - this.indents));
862 return { min: minIndent, max: maxIndent };
865 Drupal.tableDrag.prototype.row.prototype.indent = function (indentDiff) {
866 var $group = $(this.group);
868 if (!this.interval) {
869 var prevRow = $(this.element).prev('tr').get(0);
870 var nextRow = $group.eq(-1).next('tr').get(0);
871 this.interval = this.validIndentInterval(prevRow, nextRow);
874 var indent = this.indents + indentDiff;
875 indent = Math.max(indent, this.interval.min);
876 indent = Math.min(indent, this.interval.max);
877 indentDiff = indent - this.indents;
879 for (var n = 1; n <= Math.abs(indentDiff); n++) {
880 if (indentDiff < 0) {
881 $group.find('.js-indentation:first-of-type').remove();
884 $group.find('td:first-of-type').prepend(Drupal.theme('tableDragIndentation'));
890 this.groupDepth += indentDiff;
897 Drupal.tableDrag.prototype.row.prototype.findSiblings = function (rowSettings) {
899 var directions = ['prev', 'next'];
900 var rowIndentation = this.indents;
901 var checkRowIndentation = void 0;
902 for (var d = 0; d < directions.length; d++) {
903 var checkRow = $(this.element)[directions[d]]();
904 while (checkRow.length) {
905 if (checkRow.find('.' + rowSettings.target)) {
906 if (this.indentEnabled) {
907 checkRowIndentation = checkRow.find('.js-indentation').length;
910 if (!this.indentEnabled || checkRowIndentation === rowIndentation) {
911 siblings.push(checkRow[0]);
912 } else if (checkRowIndentation < rowIndentation) {
918 checkRow = checkRow[directions[d]]();
921 if (directions[d] === 'prev') {
923 siblings.push(this.element);
929 Drupal.tableDrag.prototype.row.prototype.removeIndentClasses = function () {
930 for (var n in this.children) {
931 if (this.children.hasOwnProperty(n)) {
932 $(this.children[n]).find('.js-indentation').removeClass('tree-child').removeClass('tree-child-first').removeClass('tree-child-last').removeClass('tree-child-horizontal');
937 Drupal.tableDrag.prototype.row.prototype.markChanged = function () {
938 var marker = Drupal.theme('tableDragChangedMarker');
939 var cell = $(this.element).find('td:first-of-type');
940 if (cell.find('abbr.tabledrag-changed').length === 0) {
945 Drupal.tableDrag.prototype.row.prototype.onIndent = function () {
949 Drupal.tableDrag.prototype.row.prototype.onSwap = function (swappedRow) {
953 $.extend(Drupal.theme, {
954 tableDragChangedMarker: function tableDragChangedMarker() {
955 return '<abbr class="warning tabledrag-changed" title="' + Drupal.t('Changed') + '">*</abbr>';
957 tableDragIndentation: function tableDragIndentation() {
958 return '<div class="js-indentation indentation"> </div>';
960 tableDragChangedWarning: function tableDragChangedWarning() {
961 return '<div class="tabledrag-changed-warning messages messages--warning" role="alert">' + Drupal.theme('tableDragChangedMarker') + ' ' + Drupal.t('You have unsaved changes.') + '</div>';
964 })(jQuery, Drupal, drupalSettings);