Mercurial > hg > isophonics-drupal-site
comparison core/misc/tabledrag.js @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
14 if (table.length) { | 14 if (table.length) { |
15 Drupal.tableDrag[base] = new Drupal.tableDrag(table[0], settings.tableDrag[base]); | 15 Drupal.tableDrag[base] = new Drupal.tableDrag(table[0], settings.tableDrag[base]); |
16 } | 16 } |
17 } | 17 } |
18 | 18 |
19 for (var base in settings.tableDrag) { | 19 Object.keys(settings.tableDrag || {}).forEach(function (base) { |
20 if (settings.tableDrag.hasOwnProperty(base)) { | 20 initTableDrag($(context).find('#' + base).once('tabledrag'), base); |
21 initTableDrag($(context).find('#' + base).once('tabledrag'), base); | 21 }); |
22 } | |
23 } | |
24 } | 22 } |
25 }; | 23 }; |
26 | 24 |
27 Drupal.tableDrag = function (table, tableSettings) { | 25 Drupal.tableDrag = function (table, tableSettings) { |
26 var _this = this; | |
27 | |
28 var self = this; | 28 var self = this; |
29 var $table = $(table); | 29 var $table = $(table); |
30 | 30 |
31 this.$table = $(table); | 31 this.$table = $(table); |
32 | 32 |
57 this.scrollY = 0; | 57 this.scrollY = 0; |
58 | 58 |
59 this.windowHeight = 0; | 59 this.windowHeight = 0; |
60 | 60 |
61 this.indentEnabled = false; | 61 this.indentEnabled = false; |
62 for (var group in tableSettings) { | 62 Object.keys(tableSettings || {}).forEach(function (group) { |
63 if (tableSettings.hasOwnProperty(group)) { | 63 Object.keys(tableSettings[group] || {}).forEach(function (n) { |
64 for (var n in tableSettings[group]) { | 64 if (tableSettings[group][n].relationship === 'parent') { |
65 if (tableSettings[group].hasOwnProperty(n)) { | 65 _this.indentEnabled = true; |
66 if (tableSettings[group][n].relationship === 'parent') { | 66 } |
67 this.indentEnabled = true; | 67 if (tableSettings[group][n].limit > 0) { |
68 } | 68 _this.maxDepth = tableSettings[group][n].limit; |
69 if (tableSettings[group][n].limit > 0) { | 69 } |
70 this.maxDepth = tableSettings[group][n].limit; | 70 }); |
71 } | 71 }); |
72 } | |
73 } | |
74 } | |
75 } | |
76 if (this.indentEnabled) { | 72 if (this.indentEnabled) { |
77 this.indentCount = 1; | 73 this.indentCount = 1; |
78 | 74 |
79 var indent = Drupal.theme('tableDragIndentation'); | 75 var indent = Drupal.theme('tableDragIndentation'); |
80 var testRow = $('<tr/>').addClass('draggable').appendTo(table); | 76 var testRow = $('<tr/>').addClass('draggable').appendTo(table); |
116 } | 112 } |
117 }, this)); | 113 }, this)); |
118 }; | 114 }; |
119 | 115 |
120 Drupal.tableDrag.prototype.initColumns = function () { | 116 Drupal.tableDrag.prototype.initColumns = function () { |
117 var _this2 = this; | |
118 | |
121 var $table = this.$table; | 119 var $table = this.$table; |
122 var hidden = void 0; | 120 var hidden = void 0; |
123 var cell = void 0; | 121 var cell = void 0; |
124 var columnIndex = void 0; | 122 var columnIndex = void 0; |
125 for (var group in this.tableSettings) { | 123 Object.keys(this.tableSettings || {}).forEach(function (group) { |
126 if (this.tableSettings.hasOwnProperty(group)) { | 124 for (var d in _this2.tableSettings[group]) { |
127 for (var d in this.tableSettings[group]) { | 125 if (_this2.tableSettings[group].hasOwnProperty(d)) { |
128 if (this.tableSettings[group].hasOwnProperty(d)) { | 126 var field = $table.find('.' + _this2.tableSettings[group][d].target).eq(0); |
129 var field = $table.find('.' + this.tableSettings[group][d].target).eq(0); | 127 if (field.length && _this2.tableSettings[group][d].hidden) { |
130 if (field.length && this.tableSettings[group][d].hidden) { | 128 hidden = _this2.tableSettings[group][d].hidden; |
131 hidden = this.tableSettings[group][d].hidden; | 129 cell = field.closest('td'); |
132 cell = field.closest('td'); | 130 break; |
133 break; | 131 } |
134 } | 132 } |
135 } | 133 } |
136 } | 134 |
137 | 135 if (hidden && cell[0]) { |
138 if (hidden && cell[0]) { | 136 columnIndex = cell.parent().find('> td').index(cell.get(0)) + 1; |
139 columnIndex = cell.parent().find('> td').index(cell.get(0)) + 1; | 137 $table.find('> thead > tr, > tbody > tr, > tr').each(_this2.addColspanClass(columnIndex)); |
140 $table.find('> thead > tr, > tbody > tr, > tr').each(this.addColspanClass(columnIndex)); | 138 } |
141 } | 139 }); |
142 } | |
143 } | |
144 this.displayColumns(showWeight); | 140 this.displayColumns(showWeight); |
145 }; | 141 }; |
146 | 142 |
147 Drupal.tableDrag.prototype.addColspanClass = function (columnIndex) { | 143 Drupal.tableDrag.prototype.addColspanClass = function (columnIndex) { |
148 return function () { | 144 return function () { |
215 }; | 211 }; |
216 | 212 |
217 Drupal.tableDrag.prototype.rowSettings = function (group, row) { | 213 Drupal.tableDrag.prototype.rowSettings = function (group, row) { |
218 var field = $(row).find('.' + group); | 214 var field = $(row).find('.' + group); |
219 var tableSettingsGroup = this.tableSettings[group]; | 215 var tableSettingsGroup = this.tableSettings[group]; |
216 | |
220 for (var delta in tableSettingsGroup) { | 217 for (var delta in tableSettingsGroup) { |
221 if (tableSettingsGroup.hasOwnProperty(delta)) { | 218 if (tableSettingsGroup.hasOwnProperty(delta)) { |
222 var targetClass = tableSettingsGroup[delta].target; | 219 var targetClass = tableSettingsGroup[delta].target; |
223 if (field.is('.' + targetClass)) { | 220 if (field.is('.' + targetClass)) { |
224 var rowSettings = {}; | 221 var rowSettings = {}; |
222 | |
225 for (var n in tableSettingsGroup[delta]) { | 223 for (var n in tableSettingsGroup[delta]) { |
226 if (tableSettingsGroup[delta].hasOwnProperty(n)) { | 224 if (tableSettingsGroup[delta].hasOwnProperty(n)) { |
227 rowSettings[n] = tableSettingsGroup[delta][n]; | 225 rowSettings[n] = tableSettingsGroup[delta][n]; |
228 } | 226 } |
229 } | 227 } |
287 self.rowObject.indent(-1 * self.rtl); | 285 self.rowObject.indent(-1 * self.rtl); |
288 break; | 286 break; |
289 | 287 |
290 case 38: | 288 case 38: |
291 case 63232: | 289 case 63232: |
292 var $previousRow = $(self.rowObject.element).prev('tr:first-of-type'); | 290 { |
293 var previousRow = $previousRow.get(0); | 291 var $previousRow = $(self.rowObject.element).prev('tr:first-of-type'); |
294 while (previousRow && $previousRow.is(':hidden')) { | 292 var previousRow = $previousRow.get(0); |
295 $previousRow = $(previousRow).prev('tr:first-of-type'); | 293 while (previousRow && $previousRow.is(':hidden')) { |
296 previousRow = $previousRow.get(0); | 294 $previousRow = $(previousRow).prev('tr:first-of-type'); |
297 } | 295 previousRow = $previousRow.get(0); |
298 if (previousRow) { | 296 } |
299 self.safeBlur = false; | 297 if (previousRow) { |
300 self.rowObject.direction = 'up'; | 298 self.safeBlur = false; |
301 keyChange = true; | 299 self.rowObject.direction = 'up'; |
302 | 300 keyChange = true; |
303 if ($(item).is('.tabledrag-root')) { | 301 |
304 groupHeight = 0; | 302 if ($(item).is('.tabledrag-root')) { |
305 while (previousRow && $previousRow.find('.js-indentation').length) { | 303 groupHeight = 0; |
306 $previousRow = $(previousRow).prev('tr:first-of-type'); | 304 while (previousRow && $previousRow.find('.js-indentation').length) { |
307 previousRow = $previousRow.get(0); | 305 $previousRow = $(previousRow).prev('tr:first-of-type'); |
308 groupHeight += $previousRow.is(':hidden') ? 0 : previousRow.offsetHeight; | 306 previousRow = $previousRow.get(0); |
307 groupHeight += $previousRow.is(':hidden') ? 0 : previousRow.offsetHeight; | |
308 } | |
309 if (previousRow) { | |
310 self.rowObject.swap('before', previousRow); | |
311 | |
312 window.scrollBy(0, -groupHeight); | |
313 } | |
314 } else if (self.table.tBodies[0].rows[0] !== previousRow || $previousRow.is('.draggable')) { | |
315 self.rowObject.swap('before', previousRow); | |
316 self.rowObject.interval = null; | |
317 self.rowObject.indent(0); | |
318 window.scrollBy(0, -parseInt(item.offsetHeight, 10)); | |
309 } | 319 } |
310 if (previousRow) { | 320 |
311 self.rowObject.swap('before', previousRow); | 321 handle.trigger('focus'); |
312 | |
313 window.scrollBy(0, -groupHeight); | |
314 } | |
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)); | |
320 } | 322 } |
321 | 323 break; |
322 handle.trigger('focus'); | 324 } |
323 } | |
324 break; | |
325 | 325 |
326 case 39: | 326 case 39: |
327 case 63235: | 327 case 63235: |
328 keyChange = true; | 328 keyChange = true; |
329 self.rowObject.indent(self.rtl); | 329 self.rowObject.indent(self.rtl); |
330 break; | 330 break; |
331 | 331 |
332 case 40: | 332 case 40: |
333 case 63233: | 333 case 63233: |
334 var $nextRow = $(self.rowObject.group).eq(-1).next('tr:first-of-type'); | 334 { |
335 var nextRow = $nextRow.get(0); | 335 var $nextRow = $(self.rowObject.group).eq(-1).next('tr:first-of-type'); |
336 while (nextRow && $nextRow.is(':hidden')) { | 336 var nextRow = $nextRow.get(0); |
337 $nextRow = $(nextRow).next('tr:first-of-type'); | 337 while (nextRow && $nextRow.is(':hidden')) { |
338 nextRow = $nextRow.get(0); | 338 $nextRow = $(nextRow).next('tr:first-of-type'); |
339 } | 339 nextRow = $nextRow.get(0); |
340 if (nextRow) { | 340 } |
341 self.safeBlur = false; | 341 if (nextRow) { |
342 self.rowObject.direction = 'down'; | 342 self.safeBlur = false; |
343 keyChange = true; | 343 self.rowObject.direction = 'down'; |
344 | 344 keyChange = true; |
345 if ($(item).is('.tabledrag-root')) { | 345 |
346 groupHeight = 0; | 346 if ($(item).is('.tabledrag-root')) { |
347 var nextGroup = new self.row(nextRow, 'keyboard', self.indentEnabled, self.maxDepth, false); | 347 groupHeight = 0; |
348 if (nextGroup) { | 348 var nextGroup = new self.row(nextRow, 'keyboard', self.indentEnabled, self.maxDepth, false); |
349 $(nextGroup.group).each(function () { | 349 if (nextGroup) { |
350 groupHeight += $(this).is(':hidden') ? 0 : this.offsetHeight; | 350 $(nextGroup.group).each(function () { |
351 }); | 351 groupHeight += $(this).is(':hidden') ? 0 : this.offsetHeight; |
352 var nextGroupRow = $(nextGroup.group).eq(-1).get(0); | 352 }); |
353 self.rowObject.swap('after', nextGroupRow); | 353 var nextGroupRow = $(nextGroup.group).eq(-1).get(0); |
354 | 354 self.rowObject.swap('after', nextGroupRow); |
355 window.scrollBy(0, parseInt(groupHeight, 10)); | 355 |
356 window.scrollBy(0, parseInt(groupHeight, 10)); | |
357 } | |
358 } else { | |
359 self.rowObject.swap('after', nextRow); | |
360 self.rowObject.interval = null; | |
361 self.rowObject.indent(0); | |
362 window.scrollBy(0, parseInt(item.offsetHeight, 10)); | |
356 } | 363 } |
357 } else { | 364 |
358 self.rowObject.swap('after', nextRow); | 365 handle.trigger('focus'); |
359 self.rowObject.interval = null; | |
360 self.rowObject.indent(0); | |
361 window.scrollBy(0, parseInt(item.offsetHeight, 10)); | |
362 } | 366 } |
363 | 367 break; |
364 handle.trigger('focus'); | 368 } |
365 } | |
366 break; | |
367 } | 369 } |
368 | 370 |
369 if (self.rowObject && self.rowObject.changed === true) { | 371 if (self.rowObject && self.rowObject.changed === true) { |
370 $(item).addClass('drag'); | 372 $(item).addClass('drag'); |
371 if (self.oldRowElement) { | 373 if (self.oldRowElement) { |
476 $droppedRow = $(droppedRow); | 478 $droppedRow = $(droppedRow); |
477 | 479 |
478 if (self.rowObject.changed === true) { | 480 if (self.rowObject.changed === true) { |
479 self.updateFields(droppedRow); | 481 self.updateFields(droppedRow); |
480 | 482 |
481 for (var group in self.tableSettings) { | 483 Object.keys(self.tableSettings || {}).forEach(function (group) { |
482 if (self.tableSettings.hasOwnProperty(group)) { | 484 var rowSettings = self.rowSettings(group, droppedRow); |
483 var rowSettings = self.rowSettings(group, droppedRow); | 485 if (rowSettings.relationship === 'group') { |
484 if (rowSettings.relationship === 'group') { | 486 Object.keys(self.rowObject.children || {}).forEach(function (n) { |
485 for (var n in self.rowObject.children) { | 487 self.updateField(self.rowObject.children[n], group); |
486 if (self.rowObject.children.hasOwnProperty(n)) { | 488 }); |
487 self.updateField(self.rowObject.children[n], group); | 489 } |
488 } | 490 }); |
489 } | |
490 } | |
491 } | |
492 } | |
493 | 491 |
494 self.rowObject.markChanged(); | 492 self.rowObject.markChanged(); |
495 if (self.changed === false) { | 493 if (self.changed === false) { |
496 $(Drupal.theme('tableDragChangedWarning')).insertBefore(self.table).hide().fadeIn('slow'); | 494 $(Drupal.theme('tableDragChangedWarning')).insertBefore(self.table).hide().fadeIn('slow'); |
497 self.changed = true; | 495 self.changed = true; |
537 var rows = $(this.table.tBodies[0].rows).not(':hidden'); | 535 var rows = $(this.table.tBodies[0].rows).not(':hidden'); |
538 for (var n = 0; n < rows.length; n++) { | 536 for (var n = 0; n < rows.length; n++) { |
539 var row = rows[n]; | 537 var row = rows[n]; |
540 var $row = $(row); | 538 var $row = $(row); |
541 var rowY = $row.offset().top; | 539 var rowY = $row.offset().top; |
542 var rowHeight; | 540 var rowHeight = void 0; |
543 | 541 |
544 if (row.offsetHeight === 0) { | 542 if (row.offsetHeight === 0) { |
545 rowHeight = parseInt(row.firstChild.offsetHeight, 10) / 2; | 543 rowHeight = parseInt(row.firstChild.offsetHeight, 10) / 2; |
546 } else { | 544 } else { |
547 rowHeight = parseInt(row.offsetHeight, 10) / 2; | 545 rowHeight = parseInt(row.offsetHeight, 10) / 2; |
552 for (n in this.rowObject.group) { | 550 for (n in this.rowObject.group) { |
553 if (this.rowObject.group[n] === row) { | 551 if (this.rowObject.group[n] === row) { |
554 return null; | 552 return null; |
555 } | 553 } |
556 } | 554 } |
557 } else { | 555 } else if (row === this.rowObject.element) { |
558 if (row === this.rowObject.element) { | |
559 return null; | 556 return null; |
560 } | 557 } |
561 } | |
562 | 558 |
563 if (!this.rowObject.isValidSwap(row)) { | 559 if (!this.rowObject.isValidSwap(row)) { |
564 return null; | 560 return null; |
565 } | 561 } |
566 | 562 |
573 } | 569 } |
574 return null; | 570 return null; |
575 }; | 571 }; |
576 | 572 |
577 Drupal.tableDrag.prototype.updateFields = function (changedRow) { | 573 Drupal.tableDrag.prototype.updateFields = function (changedRow) { |
578 for (var group in this.tableSettings) { | 574 var _this3 = this; |
579 if (this.tableSettings.hasOwnProperty(group)) { | 575 |
580 this.updateField(changedRow, group); | 576 Object.keys(this.tableSettings || {}).forEach(function (group) { |
581 } | 577 _this3.updateField(changedRow, group); |
582 } | 578 }); |
583 }; | 579 }; |
584 | 580 |
585 Drupal.tableDrag.prototype.updateField = function (changedRow, group) { | 581 Drupal.tableDrag.prototype.updateField = function (changedRow, group) { |
586 var rowSettings = this.rowSettings(group, changedRow); | 582 var rowSettings = this.rowSettings(group, changedRow); |
587 var $changedRow = $(changedRow); | 583 var $changedRow = $(changedRow); |
656 case 'match': | 652 case 'match': |
657 targetElement.value = sourceElement.value; | 653 targetElement.value = sourceElement.value; |
658 break; | 654 break; |
659 | 655 |
660 case 'order': | 656 case 'order': |
661 var siblings = this.rowObject.findSiblings(rowSettings); | 657 { |
662 if ($(targetElement).is('select')) { | 658 var siblings = this.rowObject.findSiblings(rowSettings); |
663 var values = []; | 659 if ($(targetElement).is('select')) { |
664 $(targetElement).find('option').each(function () { | 660 var values = []; |
665 values.push(this.value); | 661 $(targetElement).find('option').each(function () { |
666 }); | 662 values.push(this.value); |
667 var maxVal = values[values.length - 1]; | 663 }); |
668 | 664 var maxVal = values[values.length - 1]; |
669 $(siblings).find(targetClass).each(function () { | 665 |
670 if (values.length > 0) { | 666 $(siblings).find(targetClass).each(function () { |
671 this.value = values.shift(); | 667 if (values.length > 0) { |
672 } else { | 668 this.value = values.shift(); |
673 this.value = maxVal; | 669 } else { |
674 } | 670 this.value = maxVal; |
675 }); | 671 } |
676 } else { | 672 }); |
677 var weight = parseInt($(siblings[0]).find(targetClass).val(), 10) || 0; | 673 } else { |
678 $(siblings).find(targetClass).each(function () { | 674 var weight = parseInt($(siblings[0]).find(targetClass).val(), 10) || 0; |
679 this.value = weight; | 675 $(siblings).find(targetClass).each(function () { |
680 weight++; | 676 this.value = weight; |
681 }); | 677 weight++; |
682 } | 678 }); |
683 break; | 679 } |
680 break; | |
681 } | |
684 } | 682 } |
685 } | 683 } |
686 }; | 684 }; |
687 | 685 |
688 Drupal.tableDrag.prototype.copyDragClasses = function (sourceRow, targetRow, group) { | 686 Drupal.tableDrag.prototype.copyDragClasses = function (sourceRow, targetRow, group) { |
695 | 693 |
696 Drupal.tableDrag.prototype.checkScroll = function (cursorY) { | 694 Drupal.tableDrag.prototype.checkScroll = function (cursorY) { |
697 var de = document.documentElement; | 695 var de = document.documentElement; |
698 var b = document.body; | 696 var b = document.body; |
699 | 697 |
700 var windowHeight = this.windowHeight = window.innerHeight || (de.clientHeight && de.clientWidth !== 0 ? de.clientHeight : b.offsetHeight); | 698 var windowHeight = window.innerHeight || (de.clientHeight && de.clientWidth !== 0 ? de.clientHeight : b.offsetHeight); |
699 this.windowHeight = windowHeight; | |
701 var scrollY = void 0; | 700 var scrollY = void 0; |
702 if (document.all) { | 701 if (document.all) { |
703 scrollY = this.scrollY = !de.scrollTop ? b.scrollTop : de.scrollTop; | 702 scrollY = !de.scrollTop ? b.scrollTop : de.scrollTop; |
704 } else { | 703 } else { |
705 scrollY = this.scrollY = window.pageYOffset ? window.pageYOffset : window.scrollY; | 704 scrollY = window.pageYOffset ? window.pageYOffset : window.scrollY; |
706 } | 705 } |
706 this.scrollY = scrollY; | |
707 var trigger = this.scrollSettings.trigger; | 707 var trigger = this.scrollSettings.trigger; |
708 var delta = 0; | 708 var delta = 0; |
709 | 709 |
710 if (cursorY - scrollY > windowHeight - trigger) { | 710 if (cursorY - scrollY > windowHeight - trigger) { |
711 delta = trigger / (windowHeight + scrollY - cursorY); | 711 delta = trigger / (windowHeight + scrollY - cursorY); |
842 this.onSwap(row); | 842 this.onSwap(row); |
843 }; | 843 }; |
844 | 844 |
845 Drupal.tableDrag.prototype.row.prototype.validIndentInterval = function (prevRow, nextRow) { | 845 Drupal.tableDrag.prototype.row.prototype.validIndentInterval = function (prevRow, nextRow) { |
846 var $prevRow = $(prevRow); | 846 var $prevRow = $(prevRow); |
847 var minIndent = void 0; | |
848 var maxIndent = void 0; | 847 var maxIndent = void 0; |
849 | 848 |
850 minIndent = nextRow ? $(nextRow).find('.js-indentation').length : 0; | 849 var minIndent = nextRow ? $(nextRow).find('.js-indentation').length : 0; |
851 | 850 |
852 if (!prevRow || $prevRow.is(':not(.draggable)') || $(this.element).is('.tabledrag-root')) { | 851 if (!prevRow || $prevRow.is(':not(.draggable)') || $(this.element).is('.tabledrag-root')) { |
853 maxIndent = 0; | 852 maxIndent = 0; |
854 } else { | 853 } else { |
855 maxIndent = $prevRow.find('.js-indentation').length + ($prevRow.is('.tabledrag-leaf') ? 0 : 1); | 854 maxIndent = $prevRow.find('.js-indentation').length + ($prevRow.is('.tabledrag-leaf') ? 0 : 1); |
925 } | 924 } |
926 return siblings; | 925 return siblings; |
927 }; | 926 }; |
928 | 927 |
929 Drupal.tableDrag.prototype.row.prototype.removeIndentClasses = function () { | 928 Drupal.tableDrag.prototype.row.prototype.removeIndentClasses = function () { |
930 for (var n in this.children) { | 929 var _this4 = this; |
931 if (this.children.hasOwnProperty(n)) { | 930 |
932 $(this.children[n]).find('.js-indentation').removeClass('tree-child').removeClass('tree-child-first').removeClass('tree-child-last').removeClass('tree-child-horizontal'); | 931 Object.keys(this.children || {}).forEach(function (n) { |
933 } | 932 $(_this4.children[n]).find('.js-indentation').removeClass('tree-child').removeClass('tree-child-first').removeClass('tree-child-last').removeClass('tree-child-horizontal'); |
934 } | 933 }); |
935 }; | 934 }; |
936 | 935 |
937 Drupal.tableDrag.prototype.row.prototype.markChanged = function () { | 936 Drupal.tableDrag.prototype.row.prototype.markChanged = function () { |
938 var marker = Drupal.theme('tableDragChangedMarker'); | 937 var marker = Drupal.theme('tableDragChangedMarker'); |
939 var cell = $(this.element).find('td:first-of-type'); | 938 var cell = $(this.element).find('td:first-of-type'); |