From 147f4df8436fcd3d157c48c181d7b0c6a1fd474b Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 14 Jan 2017 15:53:39 +0100 Subject: Improve plugin_admin.js to support multiple ordered rows --- inc/plugin_admin.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'inc') diff --git a/inc/plugin_admin.js b/inc/plugin_admin.js index 134ffb33..055ac285 100644 --- a/inc/plugin_admin.js +++ b/inc/plugin_admin.js @@ -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); } /** -- cgit v1.2.3