]> git.scottworley.com Git - picsort/blob - picsorter.js
22d6f10f318e097087afe483aa2ed656a7346bce
[picsort] / picsorter.js
1 if (!("picsorter_deleted" in localStorage)) {
2 localStorage.picsorter_deleted = JSON.stringify({});
3 }
4 var picsorter_deleted = JSON.parse(localStorage.picsorter_deleted);
5
6 var exposure = 20;
7 var zoom = "sm/";
8 var input_index = -1;
9 move_to_nondeleted(1);
10
11
12 function setpic() {
13 $("#pic").attr("src", zoom + exposure + "/" + files[input_index]);
14 }
15
16 function say(message) {
17 $("#message").text(message).removeClass("fade");
18 setTimeout(function() { $("#message").addClass("fade"); }, 1);
19 }
20
21 function toggle_zoom() {
22 if (zoom) {
23 zoom = "";
24 } else {
25 zoom = "sm/";
26 }
27 setpic();
28 }
29
30 function move_to_nondeleted(direction) {
31 do {
32 input_index += direction;
33 } while (files[input_index] in picsorter_deleted);
34 say(input_index);
35 }
36
37 function mark_deleted() {
38 picsorter_deleted[files[input_index]] = 1;
39 localStorage.picsorter_deleted = JSON.stringify(picsorter_deleted);
40 say("Deleted");
41 }
42
43 function mark_not_deleted() {
44 delete picsorter_deleted[files[input_index]];
45 localStorage.picsorter_deleted = JSON.stringify(picsorter_deleted);
46 say("Undeleted");
47 }
48
49 $(function() {
50 setpic();
51 });
52
53 Mousetrap.bind('z', toggle_zoom);
54 Mousetrap.bind('Z', function() { $("#pic").toggleClass("fit_view"); });
55 Mousetrap.bind('n', function() { move_to_nondeleted(1); setpic(); });
56 Mousetrap.bind('p', function() { move_to_nondeleted(-1); setpic(); });
57 Mousetrap.bind('N', function() { input_index ++; say(input_index); setpic(); });
58 Mousetrap.bind('P', function() { input_index --; say(input_index); setpic(); });
59 Mousetrap.bind('b', function() { exposure ++; setpic(); });
60 Mousetrap.bind('d', function() { exposure --; setpic(); });
61 Mousetrap.bind('x', mark_deleted);
62 Mousetrap.bind('X', mark_not_deleted);