Chris@0: /** Chris@0: * @file Chris@0: * Taxonomy behaviors. Chris@0: */ Chris@0: Chris@17: (function($, Drupal) { Chris@0: /** Chris@0: * Move a block in the blocks table from one region to another. Chris@0: * Chris@0: * This behavior is dependent on the tableDrag behavior, since it uses the Chris@0: * objects initialized in that behavior to update the row. Chris@0: * Chris@0: * @type {Drupal~behavior} Chris@0: * Chris@0: * @prop {Drupal~behaviorAttach} attach Chris@0: * Attaches the drag behavior to a applicable table element. Chris@0: */ Chris@0: Drupal.behaviors.termDrag = { Chris@0: attach(context, settings) { Chris@0: const backStep = settings.taxonomy.backStep; Chris@0: const forwardStep = settings.taxonomy.forwardStep; Chris@0: // Get the blocks tableDrag object. Chris@0: const tableDrag = Drupal.tableDrag.taxonomy; Chris@0: const $table = $('#taxonomy'); Chris@0: const rows = $table.find('tr').length; Chris@0: Chris@0: // When a row is swapped, keep previous and next page classes set. Chris@17: tableDrag.row.prototype.onSwap = function(swappedRow) { Chris@17: $table Chris@17: .find('tr.taxonomy-term-preview') Chris@17: .removeClass('taxonomy-term-preview'); Chris@17: $table Chris@17: .find('tr.taxonomy-term-divider-top') Chris@17: .removeClass('taxonomy-term-divider-top'); Chris@17: $table Chris@17: .find('tr.taxonomy-term-divider-bottom') Chris@17: .removeClass('taxonomy-term-divider-bottom'); Chris@0: Chris@0: const tableBody = $table[0].tBodies[0]; Chris@0: if (backStep) { Chris@0: for (let n = 0; n < backStep; n++) { Chris@0: $(tableBody.rows[n]).addClass('taxonomy-term-preview'); Chris@0: } Chris@0: $(tableBody.rows[backStep - 1]).addClass('taxonomy-term-divider-top'); Chris@0: $(tableBody.rows[backStep]).addClass('taxonomy-term-divider-bottom'); Chris@0: } Chris@0: Chris@0: if (forwardStep) { Chris@0: for (let k = rows - forwardStep - 1; k < rows - 1; k++) { Chris@0: $(tableBody.rows[k]).addClass('taxonomy-term-preview'); Chris@0: } Chris@17: $(tableBody.rows[rows - forwardStep - 2]).addClass( Chris@17: 'taxonomy-term-divider-top', Chris@17: ); Chris@17: $(tableBody.rows[rows - forwardStep - 1]).addClass( Chris@17: 'taxonomy-term-divider-bottom', Chris@17: ); Chris@0: } Chris@0: }; Chris@0: }, Chris@0: }; Chris@17: })(jQuery, Drupal);