]> git.scottworley.com Git - picsort/blame_incremental - picsorter.js
Resumability: Skip processing if output exists
[picsort] / picsorter.js
... / ...
CommitLineData
1var picinfo = {};
2if ("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});
10function save_picinfo() {
11 localStorage.picsorter_picinfo = JSON.stringify(picinfo);
12}
13save_picinfo();
14
15var exposure = 20;
16var zoom = "sm/";
17var input_index = -1;
18
19
20function setpic() {
21 if ("exposure" in picinfo[files[input_index]]) {
22 exposure = picinfo[files[input_index]].exposure;
23 } else {
24 picinfo[files[input_index]].exposure = exposure;
25 save_picinfo();
26 }
27 $("#pic").attr("src", zoom + exposure + "/" + files[input_index]);
28}
29
30function say(message) {
31 $("#message").text(message).removeClass("fade");
32 setTimeout(function() { $("#message").addClass("fade"); }, 1);
33}
34
35function toggle_zoom() {
36 if (zoom) {
37 zoom = "";
38 } else {
39 zoom = "sm/";
40 }
41 setpic();
42}
43
44function move_to_nondeleted(direction) {
45 do {
46 input_index += direction;
47 } while (picinfo[files[input_index]].deleted);
48 say(input_index + " " + (picinfo[files[input_index]].name || ""));
49 setpic();
50}
51
52function mark_deleted() {
53 picinfo[files[input_index]].deleted = 1;
54 save_picinfo();
55 say("Deleted");
56}
57
58function mark_not_deleted() {
59 delete picinfo[files[input_index]].deleted;
60 save_picinfo();
61 say("Undeleted");
62}
63
64function change_exposure(amount) {
65 exposure += amount;
66 picinfo[files[input_index]].exposure = exposure;
67 save_picinfo();
68 setpic();
69 var display_exposure = (exposure / 4) - 3.5;
70 say((display_exposure >= 0 ? "+" : "") + display_exposure);
71}
72
73function set_name() {
74 var name_input = $("#name").hide().get(0);
75 var name = name_input.value;
76 name_input.value = "";
77 picinfo[files[input_index]].name = name;
78 save_picinfo();
79 say("Named " + name);
80}
81
82$(function() {
83 $("#name").hide().on("keyup", function(e) { e.which == 13 && set_name(); });
84 move_to_nondeleted(1);
85});
86
87Mousetrap.bind('z', toggle_zoom);
88Mousetrap.bind('Z', function() { $("#pic").toggleClass("fit_view"); });
89Mousetrap.bind('n', function() { move_to_nondeleted(1); });
90Mousetrap.bind('p', function() { move_to_nondeleted(-1); });
91Mousetrap.bind('N', function() { input_index ++; say(input_index); setpic(); });
92Mousetrap.bind('P', function() { input_index --; say(input_index); setpic(); });
93Mousetrap.bind('b', function() { change_exposure(1); });
94Mousetrap.bind('d', function() { change_exposure(-1); });
95Mousetrap.bind('x', mark_deleted);
96Mousetrap.bind('X', mark_not_deleted);
97Mousetrap.bind('c', function() { $("#name").show().focus(); return false; });