]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - inc/plugin_admin.js
134ffb337607d84c3bc7bfa0e77db7512fd27a27
[github/shaarli/Shaarli.git] / inc / plugin_admin.js
1 /**
2 * Change the position counter of a row.
3 *
4 * @param elem Element Node to change.
5 * @param toPos int New position.
6 */
7 function 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 */
22 function 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 */
42 function 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 */
58 function 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 }