2017-05-19 22:12:53 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Taxonomy behaviors.
|
|
|
|
*/
|
|
|
|
|
2020-10-21 10:41:33 +00:00
|
|
|
(function ($, Drupal) {
|
2017-05-19 22:12:53 +00:00
|
|
|
/**
|
2020-05-11 00:03:15 +00:00
|
|
|
* Reorder taxonomy terms.
|
2017-05-19 22:12:53 +00:00
|
|
|
*
|
|
|
|
* This behavior is dependent on the tableDrag behavior, since it uses the
|
|
|
|
* objects initialized in that behavior to update the row.
|
|
|
|
*
|
|
|
|
* @type {Drupal~behavior}
|
|
|
|
*
|
|
|
|
* @prop {Drupal~behaviorAttach} attach
|
Issue #2851394 by GoZ, hgunicamp, oknate, jungle, wolffereast, tameeshb, mmatsoo, ridhimaabrol24, jofitz, swarad07, tanc, shaktik, dimaro, shashikant_chauhan, MerryHamster, quietone, nitesh624, martin_q, boaloysius, gaurav.kapoor, nitvirus, ankithashetty, Munavijayalakshmi, kostyashupenko, leolando.tan, amit.drupal, ravi.shankar, akashkrishnan01, Swapnil_Kotwal, Saviktor, mrinalini9, anmolgoyal74, Venkatesh Rajan.J, shimpy, lomasr, Dinesh18, shubham.prakash, mahtab_alam, markdorison, cilefen, longwave, bleen, xjm, alexpott, gmaltoni: Fix grammar 'a' to 'an' when necessary
2020-11-13 14:25:11 +00:00
|
|
|
* Attaches the drag behavior to an applicable table element.
|
2017-05-19 22:12:53 +00:00
|
|
|
*/
|
|
|
|
Drupal.behaviors.termDrag = {
|
2017-07-06 06:21:40 +00:00
|
|
|
attach(context, settings) {
|
|
|
|
const backStep = settings.taxonomy.backStep;
|
|
|
|
const forwardStep = settings.taxonomy.forwardStep;
|
2020-05-11 00:03:15 +00:00
|
|
|
// Get the taxonomy tableDrag object.
|
2017-07-06 06:21:40 +00:00
|
|
|
const tableDrag = Drupal.tableDrag.taxonomy;
|
|
|
|
const $table = $('#taxonomy');
|
|
|
|
const rows = $table.find('tr').length;
|
2017-05-19 22:12:53 +00:00
|
|
|
|
|
|
|
// When a row is swapped, keep previous and next page classes set.
|
2020-10-21 10:41:33 +00:00
|
|
|
tableDrag.row.prototype.onSwap = function (swappedRow) {
|
2018-08-09 15:49:18 +00:00
|
|
|
$table
|
|
|
|
.find('tr.taxonomy-term-preview')
|
|
|
|
.removeClass('taxonomy-term-preview');
|
|
|
|
$table
|
|
|
|
.find('tr.taxonomy-term-divider-top')
|
|
|
|
.removeClass('taxonomy-term-divider-top');
|
|
|
|
$table
|
|
|
|
.find('tr.taxonomy-term-divider-bottom')
|
|
|
|
.removeClass('taxonomy-term-divider-bottom');
|
2017-05-19 22:12:53 +00:00
|
|
|
|
2017-07-06 06:21:40 +00:00
|
|
|
const tableBody = $table[0].tBodies[0];
|
2017-05-19 22:12:53 +00:00
|
|
|
if (backStep) {
|
2017-07-06 06:21:40 +00:00
|
|
|
for (let n = 0; n < backStep; n++) {
|
2017-05-19 22:12:53 +00:00
|
|
|
$(tableBody.rows[n]).addClass('taxonomy-term-preview');
|
|
|
|
}
|
|
|
|
$(tableBody.rows[backStep - 1]).addClass('taxonomy-term-divider-top');
|
|
|
|
$(tableBody.rows[backStep]).addClass('taxonomy-term-divider-bottom');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (forwardStep) {
|
2017-07-06 06:21:40 +00:00
|
|
|
for (let k = rows - forwardStep - 1; k < rows - 1; k++) {
|
2017-05-19 22:12:53 +00:00
|
|
|
$(tableBody.rows[k]).addClass('taxonomy-term-preview');
|
|
|
|
}
|
2018-08-09 15:49:18 +00:00
|
|
|
$(tableBody.rows[rows - forwardStep - 2]).addClass(
|
|
|
|
'taxonomy-term-divider-top',
|
|
|
|
);
|
|
|
|
$(tableBody.rows[rows - forwardStep - 1]).addClass(
|
|
|
|
'taxonomy-term-divider-bottom',
|
|
|
|
);
|
2017-05-19 22:12:53 +00:00
|
|
|
}
|
|
|
|
};
|
2017-07-06 06:21:40 +00:00
|
|
|
},
|
2017-05-19 22:12:53 +00:00
|
|
|
};
|
2018-08-09 15:49:18 +00:00
|
|
|
})(jQuery, Drupal);
|