Improve plugin_admin.js to support multiple ordered rows

This commit is contained in:
ArthurHoaro 2017-01-14 15:53:39 +01:00
parent 402b034648
commit 147f4df843

View file

@ -22,14 +22,22 @@ function changePos(elem, toPos)
function changeOrder(pos, move)
{
var newpos = parseInt(pos) + move;
var line = document.querySelector('[data-order="'+ pos +'"]');
var changeline = document.querySelector('[data-order="'+ newpos +'"]');
var parent = changeline.parentNode;
var lines = document.querySelectorAll('[data-order="'+ pos +'"]');
var changelines = document.querySelectorAll('[data-order="'+ newpos +'"]');
// If we go down reverse lines to preserve the rows order
if (move > 0) {
lines = [].slice.call(lines).reverse();
}
for (var i = 0 ; i < lines.length ; i++) {
var parent = changelines[0].parentNode;
changePos(lines[i], newpos);
changePos(changelines[i], parseInt(pos));
var changeItem = move < 0 ? changelines[0] : changelines[changelines.length - 1].nextSibling;
parent.insertBefore(lines[i], changeItem);
}
changePos(line, newpos);
changePos(changeline, parseInt(pos));
var changeItem = move < 0 ? changeline : changeline.nextSibling;
parent.insertBefore(line, changeItem);
}
/**