Improve plugin_admin.js to support multiple ordered rows
This commit is contained in:
parent
402b034648
commit
147f4df843
1 changed files with 15 additions and 7 deletions
|
@ -22,14 +22,22 @@ function changePos(elem, toPos)
|
||||||
function changeOrder(pos, move)
|
function changeOrder(pos, move)
|
||||||
{
|
{
|
||||||
var newpos = parseInt(pos) + move;
|
var newpos = parseInt(pos) + move;
|
||||||
var line = document.querySelector('[data-order="'+ pos +'"]');
|
var lines = document.querySelectorAll('[data-order="'+ pos +'"]');
|
||||||
var changeline = document.querySelector('[data-order="'+ newpos +'"]');
|
var changelines = document.querySelectorAll('[data-order="'+ newpos +'"]');
|
||||||
var parent = changeline.parentNode;
|
|
||||||
|
// 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue