taxonomy.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * @file
  3. * Taxonomy behaviors.
  4. */
  5. (function ($, Drupal) {
  6. 'use strict';
  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: function (context, settings) {
  20. var backStep = settings.taxonomy.backStep;
  21. var forwardStep = settings.taxonomy.forwardStep;
  22. // Get the blocks tableDrag object.
  23. var tableDrag = Drupal.tableDrag.taxonomy;
  24. var $table = $('#taxonomy');
  25. var rows = $table.find('tr').length;
  26. // When a row is swapped, keep previous and next page classes set.
  27. tableDrag.row.prototype.onSwap = function (swappedRow) {
  28. $table.find('tr.taxonomy-term-preview').removeClass('taxonomy-term-preview');
  29. $table.find('tr.taxonomy-term-divider-top').removeClass('taxonomy-term-divider-top');
  30. $table.find('tr.taxonomy-term-divider-bottom').removeClass('taxonomy-term-divider-bottom');
  31. var tableBody = $table[0].tBodies[0];
  32. if (backStep) {
  33. for (var n = 0; n < backStep; n++) {
  34. $(tableBody.rows[n]).addClass('taxonomy-term-preview');
  35. }
  36. $(tableBody.rows[backStep - 1]).addClass('taxonomy-term-divider-top');
  37. $(tableBody.rows[backStep]).addClass('taxonomy-term-divider-bottom');
  38. }
  39. if (forwardStep) {
  40. for (var k = rows - forwardStep - 1; k < rows - 1; k++) {
  41. $(tableBody.rows[k]).addClass('taxonomy-term-preview');
  42. }
  43. $(tableBody.rows[rows - forwardStep - 2]).addClass('taxonomy-term-divider-top');
  44. $(tableBody.rows[rows - forwardStep - 1]).addClass('taxonomy-term-divider-bottom');
  45. }
  46. };
  47. }
  48. };
  49. })(jQuery, Drupal);