]> git.scottworley.com Git - picsort/blob - picsorter.js
change_exposure(): Pull exposure logic together
[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 toggle_zoom() {
27 if (zoom) {
28 zoom = "";
29 } else {
30 zoom = "sm/";
31 }
32 setpic();
33 }
34
35 function move_to_nondeleted(direction) {
36 do {
37 input_index += direction;
38 } while (picinfo[files[input_index]].deleted);
39 say(input_index);
40 setpic();
41 }
42
43 function mark_deleted() {
44 picinfo[files[input_index]].deleted = 1;
45 localStorage.picsorter_picinfo = JSON.stringify(picinfo);
46 say("Deleted");
47 }
48
49 function mark_not_deleted() {
50 delete picinfo[files[input_index]].deleted;
51 localStorage.picsorter_picinfo = JSON.stringify(picinfo);
52 say("Undeleted");
53 }
54
55 function change_exposure(amount) {
56 exposure += amount;
57 setpic();
58 var display_exposure = (exposure / 4) - 3.5;
59 say((display_exposure >= 0 ? "+" : "") + display_exposure);
60 }
61
62 $(function() {
63 move_to_nondeleted(1);
64 });
65
66 Mousetrap.bind('z', toggle_zoom);
67 Mousetrap.bind('Z', function() { $("#pic").toggleClass("fit_view"); });
68 Mousetrap.bind('n', function() { move_to_nondeleted(1); });
69 Mousetrap.bind('p', function() { move_to_nondeleted(-1); });
70 Mousetrap.bind('N', function() { input_index ++; say(input_index); setpic(); });
71 Mousetrap.bind('P', function() { input_index --; say(input_index); setpic(); });
72 Mousetrap.bind('b', function() { change_exposure(1); });
73 Mousetrap.bind('d', function() { change_exposure(-1); });
74 Mousetrap.bind('x', mark_deleted);
75 Mousetrap.bind('X', mark_not_deleted);