]>
Commit | Line | Data |
---|---|---|
31092212 SW |
1 | var picinfo = {}; |
2 | if ("picsorter_picinfo" in localStorage) { | |
3 | picinfo = JSON.parse(localStorage.picsorter_picinfo); | |
2d325f41 | 4 | } |
31092212 SW |
5 | $.each(files, function(i, f) { |
6 | if (!(f in picinfo)) { | |
7 | picinfo[f] = {}; | |
8 | } | |
9 | }); | |
01dd0481 SW |
10 | function save_picinfo() { |
11 | localStorage.picsorter_picinfo = JSON.stringify(picinfo); | |
12 | } | |
13 | save_picinfo(); | |
2d325f41 | 14 | |
ca898dc7 SW |
15 | var exposure = 20; |
16 | var zoom = "sm/"; | |
17 | var input_index = -1; | |
ca898dc7 | 18 | |
8bc0aad4 SW |
19 | function endsWith(str, suffix) { |
20 | return str.indexOf(suffix, str.length - suffix.length) !== -1; | |
21 | } | |
22 | ||
23 | function stripFromEnd(str, suffix) { | |
24 | if (endsWith(str, suffix)) { | |
25 | return str.substr(0, str.length - suffix.length); | |
26 | } | |
27 | return str; | |
28 | } | |
ca898dc7 | 29 | |
ed9d7c54 | 30 | function setpic() { |
cd368e97 SW |
31 | var display_filename; |
32 | if (endsWith(files[input_index], ".NEF")) { | |
33 | if ("exposure" in picinfo[files[input_index]]) { | |
34 | exposure = picinfo[files[input_index]].exposure; | |
35 | } else { | |
36 | picinfo[files[input_index]].exposure = exposure; | |
37 | save_picinfo(); | |
38 | } | |
39 | display_filename = zoom + exposure + "/" + stripFromEnd(files[input_index], ".NEF") + ".jpeg"; | |
07f84670 | 40 | } else { |
cd368e97 | 41 | display_filename = zoom + files[input_index]; |
07f84670 | 42 | } |
59a0fba1 | 43 | var $pic = $("#pic"); |
6219f116 SW |
44 | $pic.on("load", function() { |
45 | $pic.removeClass("rot90 rot180 rot270"); | |
46 | if ("rotate" in picinfo[files[input_index]]) { | |
47 | $pic.addClass("rot" + picinfo[files[input_index]].rotate); | |
48 | } | |
49 | }); | |
59a0fba1 | 50 | $pic.attr("src", display_filename); |
9952a1a7 SW |
51 | } |
52 | ||
9c7566e1 SW |
53 | function say(message) { |
54 | $("#message").text(message).removeClass("fade"); | |
55 | setTimeout(function() { $("#message").addClass("fade"); }, 1); | |
56 | } | |
52c0fe1e SW |
57 | function announce() { |
58 | say(input_index + " " + (picinfo[files[input_index]].name || "")); | |
59 | } | |
9c7566e1 | 60 | |
9952a1a7 SW |
61 | function toggle_zoom() { |
62 | if (zoom) { | |
63 | zoom = ""; | |
64 | } else { | |
65 | zoom = "sm/"; | |
66 | } | |
ac4559ea | 67 | setpic(); |
97c26a9c SW |
68 | } |
69 | ||
1433682c SW |
70 | function move_by_filter(direction, filter) { |
71 | // Keep moving in direction until filter is satisfied | |
755cf903 SW |
72 | var new_index = input_index; |
73 | while (true) { | |
74 | var next = new_index + direction; | |
75 | if (next < 0) { | |
76 | say("At beginning"); | |
77 | return; | |
78 | } | |
79 | if (next >= files.length) { | |
80 | say("At end"); | |
81 | return; | |
82 | } | |
83 | new_index = next; | |
84 | if (filter(new_index)) { | |
85 | break; | |
86 | } | |
87 | } | |
88 | input_index = new_index; | |
52c0fe1e | 89 | announce(); |
c0230e38 | 90 | setpic(); |
2d325f41 | 91 | } |
1433682c SW |
92 | function move(direction) { |
93 | move_by_filter(direction, function() { return true; }); | |
94 | } | |
95 | function move_to_nondeleted(direction) { | |
755cf903 SW |
96 | move_by_filter(direction, function(i) { |
97 | return !("deleted" in picinfo[files[i]]); }); | |
1433682c SW |
98 | } |
99 | function move_to_unnamed(direction) { | |
755cf903 SW |
100 | move_by_filter(direction, function(i) { |
101 | return !("deleted" in picinfo[files[i]]) && | |
102 | !("name" in picinfo[files[i]]); }); | |
1433682c | 103 | } |
2d325f41 SW |
104 | |
105 | function mark_deleted() { | |
31092212 | 106 | picinfo[files[input_index]].deleted = 1; |
01dd0481 | 107 | save_picinfo(); |
9c7566e1 | 108 | say("Deleted"); |
2d325f41 SW |
109 | } |
110 | ||
111 | function mark_not_deleted() { | |
31092212 | 112 | delete picinfo[files[input_index]].deleted; |
01dd0481 | 113 | save_picinfo(); |
9c7566e1 | 114 | say("Undeleted"); |
2d325f41 SW |
115 | } |
116 | ||
138122d7 | 117 | function change_exposure(amount) { |
b11d9c69 SW |
118 | if (!endsWith(files[input_index], ".NEF")) { |
119 | say("Exposure adjustment not available"); | |
120 | return; | |
121 | } | |
138122d7 | 122 | exposure += amount; |
07f84670 | 123 | picinfo[files[input_index]].exposure = exposure; |
01dd0481 | 124 | save_picinfo(); |
138122d7 SW |
125 | setpic(); |
126 | var display_exposure = (exposure / 4) - 3.5; | |
127 | say((display_exposure >= 0 ? "+" : "") + display_exposure); | |
128 | } | |
129 | ||
59a0fba1 SW |
130 | function rotate() { |
131 | var rotation = picinfo[files[input_index]].rotate || 0; | |
132 | rotation = (rotation + 90) % 360; | |
133 | if (rotation > 1e-5) { | |
134 | picinfo[files[input_index]].rotate = rotation; | |
135 | } else { | |
136 | delete picinfo[files[input_index]].rotate; | |
137 | } | |
138 | save_picinfo(); | |
139 | setpic(); | |
140 | } | |
141 | ||
0799b4b3 SW |
142 | |
143 | function set_name(name) { | |
d92eb78e SW |
144 | picinfo[files[input_index]].name = name; |
145 | save_picinfo(); | |
146 | say("Named " + name); | |
0799b4b3 SW |
147 | last_name = name; |
148 | } | |
149 | ||
150 | function set_name_from_form() { | |
151 | var name_input = $("#name").hide().get(0); | |
152 | set_name(name_input.value); | |
153 | name_input.value = ""; | |
d92eb78e SW |
154 | } |
155 | ||
eaa5e016 SW |
156 | function shell_escape(x) { |
157 | return x.replace(/'/g, "'\\''"); | |
158 | } | |
159 | ||
160 | function show_commands() { | |
161 | var commands = []; | |
162 | $.each(files, function(i, f) { | |
f1b39471 SW |
163 | if ("name" in picinfo[f] && picinfo[f].name.length > 0 && |
164 | !("deleted" in picinfo[f])) { | |
eaa5e016 SW |
165 | var command = ["pic-mv"]; |
166 | if ("exposure" in picinfo[f]) { | |
167 | command.push("-e " + picinfo[f].exposure); | |
168 | } | |
169 | if ("rotate" in picinfo[f]) { | |
170 | command.push("-r " + picinfo[f].rotate); | |
171 | } | |
172 | command.push("'" + shell_escape(f) + "'"); | |
173 | command.push("'" + shell_escape(picinfo[f].name) + "'"); | |
174 | commands.push(command.join(" ")); | |
175 | } | |
176 | }); | |
0f889466 | 177 | commands.push(""); |
eaa5e016 SW |
178 | $("#shell_out").text(commands.join("\n")).show(); |
179 | } | |
180 | ||
5d9946cb | 181 | $(function() { |
0799b4b3 | 182 | $("#name").hide().on("keyup", function(e) { e.which == 13 && set_name_from_form(); }); |
c0230e38 | 183 | move_to_nondeleted(1); |
e18c13a6 | 184 | }); |
ecb5b4ef | 185 | |
ac4559ea | 186 | Mousetrap.bind('z', toggle_zoom); |
9952a1a7 | 187 | Mousetrap.bind('Z', function() { $("#pic").toggleClass("fit_view"); }); |
a5ef2857 SW |
188 | Mousetrap.bind(['n', 'l'], function() { move_to_nondeleted(1); }); |
189 | Mousetrap.bind(['p', 'h'], function() { move_to_nondeleted(-1); }); | |
1433682c SW |
190 | Mousetrap.bind(['N', 'L'], function() { move_to_unnamed(1); }); |
191 | Mousetrap.bind(['P', 'H'], function() { move_to_unnamed(-1); }); | |
192 | Mousetrap.bind(['m n', 'm l'], function() { move(1); }); | |
193 | Mousetrap.bind(['m n', 'm h'], function() { move(-1); }); | |
a5ef2857 SW |
194 | Mousetrap.bind(['b', 'k'], function() { change_exposure(1); }); |
195 | Mousetrap.bind(['d', 'j'], function() { change_exposure(-1); }); | |
ac4559ea SW |
196 | Mousetrap.bind('x', mark_deleted); |
197 | Mousetrap.bind('X', mark_not_deleted); | |
59a0fba1 | 198 | Mousetrap.bind('r', rotate); |
52c0fe1e | 199 | Mousetrap.bind('i', announce); |
88880347 | 200 | Mousetrap.bind('f', function() { say(files[input_index]); }); |
d92eb78e | 201 | Mousetrap.bind('c', function() { $("#name").show().focus(); return false; }); |
0799b4b3 | 202 | Mousetrap.bind('C', function() { if (last_name) { set_name(last_name); } }); |
76812d8f | 203 | Mousetrap.bind('%', function() { say((100 * input_index / files.length).toFixed(2) + "%"); }); |
eaa5e016 | 204 | Mousetrap.bind('!', show_commands); |
de26d1f8 | 205 | Mousetrap.bind('esc', function() { $("#name").hide(); $("#shell_out").hide(); }); |