Pull merge.
[yaffs-website] / web / core / modules / taxonomy / taxonomy.es6.js
1 /**
2  * @file
3  * Taxonomy behaviors.
4  */
5
6 (function($, Drupal) {
7   /**
8    * Move a block in the blocks table from one region to another.
9    *
10    * This behavior is dependent on the tableDrag behavior, since it uses the
11    * objects initialized in that behavior to update the row.
12    *
13    * @type {Drupal~behavior}
14    *
15    * @prop {Drupal~behaviorAttach} attach
16    *   Attaches the drag behavior to a applicable table element.
17    */
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;
26
27       // When a row is swapped, keep previous and next page classes set.
28       tableDrag.row.prototype.onSwap = function(swappedRow) {
29         $table
30           .find('tr.taxonomy-term-preview')
31           .removeClass('taxonomy-term-preview');
32         $table
33           .find('tr.taxonomy-term-divider-top')
34           .removeClass('taxonomy-term-divider-top');
35         $table
36           .find('tr.taxonomy-term-divider-bottom')
37           .removeClass('taxonomy-term-divider-bottom');
38
39         const tableBody = $table[0].tBodies[0];
40         if (backStep) {
41           for (let n = 0; n < backStep; n++) {
42             $(tableBody.rows[n]).addClass('taxonomy-term-preview');
43           }
44           $(tableBody.rows[backStep - 1]).addClass('taxonomy-term-divider-top');
45           $(tableBody.rows[backStep]).addClass('taxonomy-term-divider-bottom');
46         }
47
48         if (forwardStep) {
49           for (let k = rows - forwardStep - 1; k < rows - 1; k++) {
50             $(tableBody.rows[k]).addClass('taxonomy-term-preview');
51           }
52           $(tableBody.rows[rows - forwardStep - 2]).addClass(
53             'taxonomy-term-divider-top',
54           );
55           $(tableBody.rows[rows - forwardStep - 1]).addClass(
56             'taxonomy-term-divider-bottom',
57           );
58         }
59       };
60     },
61   };
62 })(jQuery, Drupal);