annotate core/modules/taxonomy/taxonomy.es6.js @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children
rev   line source
Chris@0 1 /**
Chris@0 2 * @file
Chris@0 3 * Taxonomy behaviors.
Chris@0 4 */
Chris@0 5
Chris@4 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@4 28 tableDrag.row.prototype.onSwap = function(swappedRow) {
Chris@4 29 $table
Chris@4 30 .find('tr.taxonomy-term-preview')
Chris@4 31 .removeClass('taxonomy-term-preview');
Chris@4 32 $table
Chris@4 33 .find('tr.taxonomy-term-divider-top')
Chris@4 34 .removeClass('taxonomy-term-divider-top');
Chris@4 35 $table
Chris@4 36 .find('tr.taxonomy-term-divider-bottom')
Chris@4 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@4 52 $(tableBody.rows[rows - forwardStep - 2]).addClass(
Chris@4 53 'taxonomy-term-divider-top',
Chris@4 54 );
Chris@4 55 $(tableBody.rows[rows - forwardStep - 1]).addClass(
Chris@4 56 'taxonomy-term-divider-bottom',
Chris@4 57 );
Chris@0 58 }
Chris@0 59 };
Chris@0 60 },
Chris@0 61 };
Chris@4 62 })(jQuery, Drupal);