taxonomy.es6.js 1.9 KB

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