diff options
author | ArthurHoaro <arthur@hoa.ro> | 2017-01-14 15:53:39 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2017-02-27 20:01:54 +0100 |
commit | 147f4df8436fcd3d157c48c181d7b0c6a1fd474b (patch) | |
tree | 1239644c7081c40017bdcb8b5e637c30234e0e9d /inc | |
parent | 402b03464812aaec76bc841ca7dacb775baf1e03 (diff) | |
download | Shaarli-147f4df8436fcd3d157c48c181d7b0c6a1fd474b.tar.gz Shaarli-147f4df8436fcd3d157c48c181d7b0c6a1fd474b.tar.zst Shaarli-147f4df8436fcd3d157c48c181d7b0c6a1fd474b.zip |
Improve plugin_admin.js to support multiple ordered rows
Diffstat (limited to 'inc')
-rw-r--r-- | inc/plugin_admin.js | 22 |
1 files changed, 15 insertions, 7 deletions
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) | |||
22 | function changeOrder(pos, move) | 22 | function changeOrder(pos, move) |
23 | { | 23 | { |
24 | var newpos = parseInt(pos) + move; | 24 | var newpos = parseInt(pos) + move; |
25 | var line = document.querySelector('[data-order="'+ pos +'"]'); | 25 | var lines = document.querySelectorAll('[data-order="'+ pos +'"]'); |
26 | var changeline = document.querySelector('[data-order="'+ newpos +'"]'); | 26 | var changelines = document.querySelectorAll('[data-order="'+ newpos +'"]'); |
27 | var parent = changeline.parentNode; | 27 | |
28 | // If we go down reverse lines to preserve the rows order | ||
29 | if (move > 0) { | ||
30 | lines = [].slice.call(lines).reverse(); | ||
31 | } | ||
32 | |||
33 | for (var i = 0 ; i < lines.length ; i++) { | ||
34 | var parent = changelines[0].parentNode; | ||
35 | changePos(lines[i], newpos); | ||
36 | changePos(changelines[i], parseInt(pos)); | ||
37 | var changeItem = move < 0 ? changelines[0] : changelines[changelines.length - 1].nextSibling; | ||
38 | parent.insertBefore(lines[i], changeItem); | ||
39 | } | ||
28 | 40 | ||
29 | changePos(line, newpos); | ||
30 | changePos(changeline, parseInt(pos)); | ||
31 | var changeItem = move < 0 ? changeline : changeline.nextSibling; | ||
32 | parent.insertBefore(line, changeItem); | ||
33 | } | 41 | } |
34 | 42 | ||
35 | /** | 43 | /** |