]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - inc/plugin_admin.js
2 * Change the position counter of a row.
4 * @param elem Element Node to change.
5 * @param toPos int New position.
7 function changePos(elem
, toPos
)
9 var elemName
= elem
.getAttribute('data-line')
11 elem
.setAttribute('data-order', toPos
);
12 var hiddenInput
= document
.querySelector('[name="order_'+ elemName
+'"]');
13 hiddenInput
.setAttribute('value', toPos
);
17 * Move a row up or down.
19 * @param pos Element Node to move.
20 * @param move int Move: +1 (down) or -1 (up)
22 function changeOrder(pos
, move)
24 var newpos
= parseInt(pos
) + move;
25 var lines
= document
.querySelectorAll('[data-order="'+ pos
+'"]');
26 var changelines
= document
.querySelectorAll('[data-order="'+ newpos
+'"]');
28 // If we go down reverse lines to preserve the rows order
30 lines
= [].slice
.call(lines
).reverse();
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
);
44 * Move a row up in the table.
46 * @param pos int row counter.
60 * Move a row down in the table.
62 * @param pos int row counter.
66 function orderDown(pos
)
68 var lastpos
= document
.querySelector('[data-order]:last-child').getAttribute('data-order');