aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/plugin_admin.js
diff options
context:
space:
mode:
authorArthur <arthur@hoa.ro>2016-01-31 19:00:13 +0100
committerArthur <arthur@hoa.ro>2016-01-31 19:00:13 +0100
commit53603f582300fc2709932b62652a5acfed088910 (patch)
tree9dbc383bf66cf9881a9b22d2437545740e26f7c1 /inc/plugin_admin.js
parent893338f0d407a0989454d5e3c0e43c97f7eface5 (diff)
parentdea0ba28f950867532eae572e7bcda49e81bbcf0 (diff)
downloadShaarli-53603f582300fc2709932b62652a5acfed088910.tar.gz
Shaarli-53603f582300fc2709932b62652a5acfed088910.tar.zst
Shaarli-53603f582300fc2709932b62652a5acfed088910.zip
Merge pull request #388 from ArthurHoaro/pluginadmin
Fixes #378 - Plugin administration UI.
Diffstat (limited to 'inc/plugin_admin.js')
-rw-r--r--inc/plugin_admin.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/inc/plugin_admin.js b/inc/plugin_admin.js
new file mode 100644
index 00000000..134ffb33
--- /dev/null
+++ b/inc/plugin_admin.js
@@ -0,0 +1,67 @@
1/**
2 * Change the position counter of a row.
3 *
4 * @param elem Element Node to change.
5 * @param toPos int New position.
6 */
7function changePos(elem, toPos)
8{
9 var elemName = elem.getAttribute('data-line')
10
11 elem.setAttribute('data-order', toPos);
12 var hiddenInput = document.querySelector('[name="order_'+ elemName +'"]');
13 hiddenInput.setAttribute('value', toPos);
14}
15
16/**
17 * Move a row up or down.
18 *
19 * @param pos Element Node to move.
20 * @param move int Move: +1 (down) or -1 (up)
21 */
22function changeOrder(pos, move)
23{
24 var newpos = parseInt(pos) + move;
25 var line = document.querySelector('[data-order="'+ pos +'"]');
26 var changeline = document.querySelector('[data-order="'+ newpos +'"]');
27 var parent = changeline.parentNode;
28
29 changePos(line, newpos);
30 changePos(changeline, parseInt(pos));
31 var changeItem = move < 0 ? changeline : changeline.nextSibling;
32 parent.insertBefore(line, changeItem);
33}
34
35/**
36 * Move a row up in the table.
37 *
38 * @param pos int row counter.
39 *
40 * @returns false
41 */
42function orderUp(pos)
43{
44 if (pos == 0) {
45 return false;
46 }
47 changeOrder(pos, -1);
48 return false;
49}
50
51/**
52 * Move a row down in the table.
53 *
54 * @param pos int row counter.
55 *
56 * @returns false
57 */
58function orderDown(pos)
59{
60 var lastpos = document.querySelector('[data-order]:last-child').getAttribute('data-order');
61 if (pos == lastpos) {
62 return false;
63 }
64
65 changeOrder(pos, +1);
66 return false;
67}