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