Security update for Core, with self-updated composer
[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.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');
32
33         const tableBody = $table[0].tBodies[0];
34         if (backStep) {
35           for (let n = 0; n < backStep; n++) {
36             $(tableBody.rows[n]).addClass('taxonomy-term-preview');
37           }
38           $(tableBody.rows[backStep - 1]).addClass('taxonomy-term-divider-top');
39           $(tableBody.rows[backStep]).addClass('taxonomy-term-divider-bottom');
40         }
41
42         if (forwardStep) {
43           for (let k = rows - forwardStep - 1; k < rows - 1; k++) {
44             $(tableBody.rows[k]).addClass('taxonomy-term-preview');
45           }
46           $(tableBody.rows[rows - forwardStep - 2]).addClass('taxonomy-term-divider-top');
47           $(tableBody.rows[rows - forwardStep - 1]).addClass('taxonomy-term-divider-bottom');
48         }
49       };
50     },
51   };
52 }(jQuery, Drupal));