6 (function ($, Drupal) {
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) {
29 $table.find('tr.taxonomy-term-preview').removeClass('taxonomy-term-preview');
30 $table.find('tr.taxonomy-term-divider-top').removeClass('taxonomy-term-divider-top');
31 $table.find('tr.taxonomy-term-divider-bottom').removeClass('taxonomy-term-divider-bottom');
33 const tableBody = $table[0].tBodies[0];
35 for (let n = 0; n < backStep; n++) {
36 $(tableBody.rows[n]).addClass('taxonomy-term-preview');
38 $(tableBody.rows[backStep - 1]).addClass('taxonomy-term-divider-top');
39 $(tableBody.rows[backStep]).addClass('taxonomy-term-divider-bottom');
43 for (let k = rows - forwardStep - 1; k < rows - 1; k++) {
44 $(tableBody.rows[k]).addClass('taxonomy-term-preview');
46 $(tableBody.rows[rows - forwardStep - 2]).addClass('taxonomy-term-divider-top');
47 $(tableBody.rows[rows - forwardStep - 1]).addClass('taxonomy-term-divider-bottom');