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