comparison core/misc/tabledrag.js @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
2 * DO NOT EDIT THIS FILE. 2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information, 3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083 4 * https://www.drupal.org/node/2815083
5 * @preserve 5 * @preserve
6 **/ 6 **/
7 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
7 8
8 (function ($, Drupal, drupalSettings) { 9 (function ($, Drupal, drupalSettings) {
9 var showWeight = JSON.parse(localStorage.getItem('Drupal.tableDrag.showWeight')); 10 var showWeight = JSON.parse(localStorage.getItem('Drupal.tableDrag.showWeight'));
10 11
11 Drupal.behaviors.tableDrag = { 12 Drupal.behaviors.tableDrag = {
119 var $table = this.$table; 120 var $table = this.$table;
120 var hidden = void 0; 121 var hidden = void 0;
121 var cell = void 0; 122 var cell = void 0;
122 var columnIndex = void 0; 123 var columnIndex = void 0;
123 Object.keys(this.tableSettings || {}).forEach(function (group) { 124 Object.keys(this.tableSettings || {}).forEach(function (group) {
124 for (var d in _this2.tableSettings[group]) { 125 Object.keys(_this2.tableSettings[group]).some(function (tableSetting) {
125 if (_this2.tableSettings[group].hasOwnProperty(d)) { 126 var field = $table.find('.' + _this2.tableSettings[group][tableSetting].target).eq(0);
126 var field = $table.find('.' + _this2.tableSettings[group][d].target).eq(0); 127 if (field.length && _this2.tableSettings[group][tableSetting].hidden) {
127 if (field.length && _this2.tableSettings[group][d].hidden) { 128 hidden = _this2.tableSettings[group][tableSetting].hidden;
128 hidden = _this2.tableSettings[group][d].hidden; 129 cell = field.closest('td');
129 cell = field.closest('td'); 130 return true;
130 break; 131 }
131 } 132 return false;
132 } 133 });
133 }
134 134
135 if (hidden && cell[0]) { 135 if (hidden && cell[0]) {
136 columnIndex = cell.parent().find('> td').index(cell.get(0)) + 1; 136 columnIndex = cell.parent().find('> td').index(cell.get(0)) + 1;
137 $table.find('> thead > tr, > tbody > tr, > tr').each(_this2.addColspanClass(columnIndex)); 137 $table.find('> thead > tr, > tbody > tr, > tr').each(_this2.addColspanClass(columnIndex));
138 } 138 }
211 }; 211 };
212 212
213 Drupal.tableDrag.prototype.rowSettings = function (group, row) { 213 Drupal.tableDrag.prototype.rowSettings = function (group, row) {
214 var field = $(row).find('.' + group); 214 var field = $(row).find('.' + group);
215 var tableSettingsGroup = this.tableSettings[group]; 215 var tableSettingsGroup = this.tableSettings[group];
216 216 return Object.keys(tableSettingsGroup).map(function (delta) {
217 for (var delta in tableSettingsGroup) { 217 var targetClass = tableSettingsGroup[delta].target;
218 if (tableSettingsGroup.hasOwnProperty(delta)) { 218 var rowSettings = void 0;
219 var targetClass = tableSettingsGroup[delta].target; 219 if (field.is('.' + targetClass)) {
220 if (field.is('.' + targetClass)) { 220 rowSettings = {};
221 var rowSettings = {}; 221 Object.keys(tableSettingsGroup[delta]).forEach(function (n) {
222 222 rowSettings[n] = tableSettingsGroup[delta][n];
223 for (var n in tableSettingsGroup[delta]) { 223 });
224 if (tableSettingsGroup[delta].hasOwnProperty(n)) { 224 }
225 rowSettings[n] = tableSettingsGroup[delta][n]; 225 return rowSettings;
226 } 226 }).filter(function (rowSetting) {
227 } 227 return rowSetting;
228 return rowSettings; 228 })[0];
229 }
230 }
231 }
232 }; 229 };
233 230
234 Drupal.tableDrag.prototype.makeDraggable = function (item) { 231 Drupal.tableDrag.prototype.makeDraggable = function (item) {
235 var self = this; 232 var self = this;
236 var $item = $(item); 233 var $item = $(item);
286 break; 283 break;
287 284
288 case 38: 285 case 38:
289 case 63232: 286 case 63232:
290 { 287 {
291 var $previousRow = $(self.rowObject.element).prev('tr:first-of-type'); 288 var $previousRow = $(self.rowObject.element).prev('tr').eq(0);
292 var previousRow = $previousRow.get(0); 289 var previousRow = $previousRow.get(0);
293 while (previousRow && $previousRow.is(':hidden')) { 290 while (previousRow && $previousRow.is(':hidden')) {
294 $previousRow = $(previousRow).prev('tr:first-of-type'); 291 $previousRow = $(previousRow).prev('tr').eq(0);
295 previousRow = $previousRow.get(0); 292 previousRow = $previousRow.get(0);
296 } 293 }
297 if (previousRow) { 294 if (previousRow) {
298 self.safeBlur = false; 295 self.safeBlur = false;
299 self.rowObject.direction = 'up'; 296 self.rowObject.direction = 'up';
300 keyChange = true; 297 keyChange = true;
301 298
302 if ($(item).is('.tabledrag-root')) { 299 if ($(item).is('.tabledrag-root')) {
303 groupHeight = 0; 300 groupHeight = 0;
304 while (previousRow && $previousRow.find('.js-indentation').length) { 301 while (previousRow && $previousRow.find('.js-indentation').length) {
305 $previousRow = $(previousRow).prev('tr:first-of-type'); 302 $previousRow = $(previousRow).prev('tr').eq(0);
306 previousRow = $previousRow.get(0); 303 previousRow = $previousRow.get(0);
307 groupHeight += $previousRow.is(':hidden') ? 0 : previousRow.offsetHeight; 304 groupHeight += $previousRow.is(':hidden') ? 0 : previousRow.offsetHeight;
308 } 305 }
309 if (previousRow) { 306 if (previousRow) {
310 self.rowObject.swap('before', previousRow); 307 self.rowObject.swap('before', previousRow);
330 break; 327 break;
331 328
332 case 40: 329 case 40:
333 case 63233: 330 case 63233:
334 { 331 {
335 var $nextRow = $(self.rowObject.group).eq(-1).next('tr:first-of-type'); 332 var $nextRow = $(self.rowObject.group).eq(-1).next('tr').eq(0);
336 var nextRow = $nextRow.get(0); 333 var nextRow = $nextRow.get(0);
337 while (nextRow && $nextRow.is(':hidden')) { 334 while (nextRow && $nextRow.is(':hidden')) {
338 $nextRow = $(nextRow).next('tr:first-of-type'); 335 $nextRow = $(nextRow).next('tr').eq(0);
339 nextRow = $nextRow.get(0); 336 nextRow = $nextRow.get(0);
340 } 337 }
341 if (nextRow) { 338 if (nextRow) {
342 self.safeBlur = false; 339 self.safeBlur = false;
343 self.rowObject.direction = 'down'; 340 self.rowObject.direction = 'down';
530 var pointerPos = this.pointerCoords(event); 527 var pointerPos = this.pointerCoords(event);
531 return { x: pointerPos.x - docPos.left, y: pointerPos.y - docPos.top }; 528 return { x: pointerPos.x - docPos.left, y: pointerPos.y - docPos.top };
532 }; 529 };
533 530
534 Drupal.tableDrag.prototype.findDropTargetRow = function (x, y) { 531 Drupal.tableDrag.prototype.findDropTargetRow = function (x, y) {
532 var _this3 = this;
533
535 var rows = $(this.table.tBodies[0].rows).not(':hidden'); 534 var rows = $(this.table.tBodies[0].rows).not(':hidden');
536 for (var n = 0; n < rows.length; n++) { 535
536 var _loop = function _loop(n) {
537 var row = rows[n]; 537 var row = rows[n];
538 var $row = $(row); 538 var $row = $(row);
539 var rowY = $row.offset().top; 539 var rowY = $row.offset().top;
540 var rowHeight = void 0; 540 var rowHeight = void 0;
541 541
544 } else { 544 } else {
545 rowHeight = parseInt(row.offsetHeight, 10) / 2; 545 rowHeight = parseInt(row.offsetHeight, 10) / 2;
546 } 546 }
547 547
548 if (y > rowY - rowHeight && y < rowY + rowHeight) { 548 if (y > rowY - rowHeight && y < rowY + rowHeight) {
549 if (this.indentEnabled) { 549 if (_this3.indentEnabled) {
550 for (n in this.rowObject.group) { 550 if (Object.keys(_this3.rowObject.group).some(function (o) {
551 if (this.rowObject.group[n] === row) { 551 return _this3.rowObject.group[o] === row;
552 return null; 552 })) {
553 } 553 return {
554 } 554 v: null
555 } else if (row === this.rowObject.element) { 555 };
556 return null; 556 }
557 } 557 } else if (row === _this3.rowObject.element) {
558 558 return {
559 if (!this.rowObject.isValidSwap(row)) { 559 v: null
560 return null; 560 };
561 }
562
563 if (!_this3.rowObject.isValidSwap(row)) {
564 return {
565 v: null
566 };
561 } 567 }
562 568
563 while ($row.is(':hidden') && $row.prev('tr').is(':hidden')) { 569 while ($row.is(':hidden') && $row.prev('tr').is(':hidden')) {
564 $row = $row.prev('tr:first-of-type'); 570 $row = $row.prev('tr:first-of-type');
565 row = $row.get(0); 571 row = $row.get(0);
566 } 572 }
567 return row; 573 return {
568 } 574 v: row
575 };
576 }
577 };
578
579 for (var n = 0; n < rows.length; n++) {
580 var _ret = _loop(n);
581
582 if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
569 } 583 }
570 return null; 584 return null;
571 }; 585 };
572 586
573 Drupal.tableDrag.prototype.updateFields = function (changedRow) { 587 Drupal.tableDrag.prototype.updateFields = function (changedRow) {
574 var _this3 = this; 588 var _this4 = this;
575 589
576 Object.keys(this.tableSettings || {}).forEach(function (group) { 590 Object.keys(this.tableSettings || {}).forEach(function (group) {
577 _this3.updateField(changedRow, group); 591 _this4.updateField(changedRow, group);
578 }); 592 });
579 }; 593 };
580 594
581 Drupal.tableDrag.prototype.updateField = function (changedRow, group) { 595 Drupal.tableDrag.prototype.updateField = function (changedRow, group) {
582 var rowSettings = this.rowSettings(group, changedRow); 596 var rowSettings = this.rowSettings(group, changedRow);
709 723
710 if (cursorY - scrollY > windowHeight - trigger) { 724 if (cursorY - scrollY > windowHeight - trigger) {
711 delta = trigger / (windowHeight + scrollY - cursorY); 725 delta = trigger / (windowHeight + scrollY - cursorY);
712 delta = delta > 0 && delta < trigger ? delta : trigger; 726 delta = delta > 0 && delta < trigger ? delta : trigger;
713 return delta * this.scrollSettings.amount; 727 return delta * this.scrollSettings.amount;
714 } else if (cursorY - scrollY < trigger) { 728 }
729 if (cursorY - scrollY < trigger) {
715 delta = trigger / (cursorY - scrollY); 730 delta = trigger / (cursorY - scrollY);
716 delta = delta > 0 && delta < trigger ? delta : trigger; 731 delta = delta > 0 && delta < trigger ? delta : trigger;
717 return -delta * this.scrollSettings.amount; 732 return -delta * this.scrollSettings.amount;
718 } 733 }
719 }; 734 };
924 } 939 }
925 return siblings; 940 return siblings;
926 }; 941 };
927 942
928 Drupal.tableDrag.prototype.row.prototype.removeIndentClasses = function () { 943 Drupal.tableDrag.prototype.row.prototype.removeIndentClasses = function () {
929 var _this4 = this; 944 var _this5 = this;
930 945
931 Object.keys(this.children || {}).forEach(function (n) { 946 Object.keys(this.children || {}).forEach(function (n) {
932 $(_this4.children[n]).find('.js-indentation').removeClass('tree-child').removeClass('tree-child-first').removeClass('tree-child-last').removeClass('tree-child-horizontal'); 947 $(_this5.children[n]).find('.js-indentation').removeClass('tree-child').removeClass('tree-child-first').removeClass('tree-child-last').removeClass('tree-child-horizontal');
933 }); 948 });
934 }; 949 };
935 950
936 Drupal.tableDrag.prototype.row.prototype.markChanged = function () { 951 Drupal.tableDrag.prototype.row.prototype.markChanged = function () {
937 var marker = Drupal.theme('tableDragChangedMarker'); 952 var marker = Drupal.theme('tableDragChangedMarker');