diff options
author | ArthurHoaro <arthur@hoa.ro> | 2015-11-18 17:40:42 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2016-01-31 18:54:48 +0100 |
commit | dea0ba28f950867532eae572e7bcda49e81bbcf0 (patch) | |
tree | 8a9c4f9d7525a2ba249bbaaabe456c2d0941293b /inc/plugin_admin.js | |
parent | 423e2a8b13dc0069c83f3e540f576aa1b89fe5d5 (diff) | |
download | Shaarli-dea0ba28f950867532eae572e7bcda49e81bbcf0.tar.gz Shaarli-dea0ba28f950867532eae572e7bcda49e81bbcf0.tar.zst Shaarli-dea0ba28f950867532eae572e7bcda49e81bbcf0.zip |
Fixes #378 - Plugin administration UI.
Diffstat (limited to 'inc/plugin_admin.js')
-rw-r--r-- | inc/plugin_admin.js | 67 |
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 | */ | ||
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 | } | ||