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