8 * Move a block in the blocks table from one region to another.
10 * This behavior is dependent on the tableDrag behavior, since it uses the
11 * objects initialized in that behavior to update the row.
13 * @type {Drupal~behavior}
15 * @prop {Drupal~behaviorAttach} attach
16 * Attaches the drag behavior to a applicable table element.
18 Drupal.behaviors.termDrag = {
19 attach(context, settings) {
20 const backStep = settings.taxonomy.backStep;
21 const forwardStep = settings.taxonomy.forwardStep;
22 // Get the blocks tableDrag object.
23 const tableDrag = Drupal.tableDrag.taxonomy;
24 const $table = $('#taxonomy');
25 const rows = $table.find('tr').length;
27 // When a row is swapped, keep previous and next page classes set.
28 tableDrag.row.prototype.onSwap = function(swappedRow) {
30 .find('tr.taxonomy-term-preview')
31 .removeClass('taxonomy-term-preview');
33 .find('tr.taxonomy-term-divider-top')
34 .removeClass('taxonomy-term-divider-top');
36 .find('tr.taxonomy-term-divider-bottom')
37 .removeClass('taxonomy-term-divider-bottom');
39 const tableBody = $table[0].tBodies[0];
41 for (let n = 0; n < backStep; n++) {
42 $(tableBody.rows[n]).addClass('taxonomy-term-preview');
44 $(tableBody.rows[backStep - 1]).addClass('taxonomy-term-divider-top');
45 $(tableBody.rows[backStep]).addClass('taxonomy-term-divider-bottom');
49 for (let k = rows - forwardStep - 1; k < rows - 1; k++) {
50 $(tableBody.rows[k]).addClass('taxonomy-term-preview');
52 $(tableBody.rows[rows - forwardStep - 2]).addClass(
53 'taxonomy-term-divider-top',
55 $(tableBody.rows[rows - forwardStep - 1]).addClass(
56 'taxonomy-term-divider-bottom',