]>
git.scottworley.com Git - picsort/blob - picsorter.js
e0a05ff0022c54e8db57814c418fa9c9403b97ad
6 function save_picinfo() {
7 localStorage
.picsorter_picinfo
= JSON
.stringify(picinfo
);
10 function endsWith(str
, suffix
) {
11 return str
.indexOf(suffix
, str
.length
- suffix
.length
) !== -1;
14 function stripFromEnd(str
, suffix
) {
15 if (endsWith(str
, suffix
)) {
16 return str
.substr(0, str
.length
- suffix
.length
);
23 if (endsWith(files
[input_index
], ".NEF")) {
24 if ("exposure" in picinfo
[files
[input_index
]]) {
25 exposure
= picinfo
[files
[input_index
]].exposure
;
27 picinfo
[files
[input_index
]].exposure
= exposure
;
30 display_filename
= zoom
+ exposure
+ "/" + stripFromEnd(files
[input_index
], ".NEF") + ".jpeg";
32 display_filename
= zoom
+ files
[input_index
];
35 $pic
.on("load", function() {
36 $pic
.removeClass("rot90 rot180 rot270");
37 if ("rotate" in picinfo
[files
[input_index
]]) {
38 $pic
.addClass("rot" + picinfo
[files
[input_index
]].rotate
);
41 $pic
.attr("src", display_filename
);
44 function say(message
) {
45 $("#message").text(message
).removeClass("fade");
46 setTimeout(function() { $("#message").addClass("fade"); }, 100);
49 var msg
= input_index
+ " " + (picinfo
[files
[input_index
]].name
|| "");
50 if ("deleted" in picinfo
[files
[input_index
]]) {
51 msg
+= "(" + picinfo
[files
[input_index
]].deleted
+ ")";
57 function toggle_zoom() {
67 function move_by_filter(direction
, filter
) {
68 // Keep moving in direction until filter is satisfied
69 var new_index
= input_index
;
71 var next
= new_index
+ direction
;
76 if (next
>= files
.length
) {
81 if (filter(new_index
)) {
85 input_index
= new_index
;
89 function move(direction
) {
90 move_by_filter(direction
, function() { return true; });
92 function move_to_begenning() {
93 move_by_filter(-1, function(i
) { return i
== 0; });
96 function move_to_end() {
97 move_by_filter(1, function(i
) { return i
== files
.length
- 1; });
100 function move_to_nondeleted(direction
) {
101 move_by_filter(direction
, function(i
) {
102 return !("deleted" in picinfo
[files
[i
]]); });
104 function move_to_unnamed(direction
) {
105 move_by_filter(direction
, function(i
) {
106 return !("deleted" in picinfo
[files
[i
]]) &&
107 !("name" in picinfo
[files
[i
]]); });
110 function mark_deleted(method
) {
111 picinfo
[files
[input_index
]].deleted
= method
;
116 function mark_not_deleted() {
117 delete picinfo
[files
[input_index
]].deleted
;
123 function say_exposure() {
124 if (!endsWith(files
[input_index
], ".NEF")) {
125 say("Exposure adjustment not available");
128 var display_exposure
= (exposure
/ 4) - 3.5;
129 say((display_exposure
>= 0 ? "+" : "") + display_exposure
);
133 function change_exposure(amount
) {
134 if (!endsWith(files
[input_index
], ".NEF")) {
135 say("Exposure adjustment not available");
139 picinfo
[files
[input_index
]].exposure
= exposure
;
146 var rotation
= picinfo
[files
[input_index
]].rotate
|| 0;
147 rotation
= (rotation
+ 90) % 360;
148 if (rotation
> 1e-5) {
149 picinfo
[files
[input_index
]].rotate
= rotation
;
151 delete picinfo
[files
[input_index
]].rotate
;
159 function set_name(name
) {
161 picinfo
[files
[input_index
]].name
= name
;
163 say("Named " + name
);
168 function set_name_from_form() {
169 var name_input
= $("#name").hide().get(0);
170 set_name(name_input
.value
);
171 name_input
.value
= "";
174 function shell_escape(x
) {
175 return x
.replace(/'/g, "'\\''");
178 function show_commands() {
180 $.each(files, function(i, f) {
181 var escaped_filename = "'" + shell_escape(f) + "'";
182 if (picinfo[f].deleted == "deleted
") {
183 commands.push("shred
-u
" + escaped_filename);
184 } else if (picinfo[f].deleted == "extra
") {
185 commands.push("mv
-vi
" + escaped_filename + " \"$EXTRADIR
\"");
186 } else if (picinfo[f].deleted == "blurry
") {
187 commands.push("mv
-vi
" + escaped_filename + " \"$BLURRYDIR
\"");
188 } else if ("name
" in picinfo[f] && picinfo[f].name.length > 0) {
189 var command = ["pic
-mv
"];
190 if ("exposure
" in picinfo[f]) {
191 command.push("-e
" + picinfo[f].exposure);
193 if ("rotate
" in picinfo[f]) {
194 command.push("-r
" + picinfo[f].rotate);
196 command.push(escaped_filename);
197 command.push("'" + shell_escape(picinfo[f].name) + "'");
198 commands.push(command.join(" "));
202 $("#shell_out
").text(commands.join("\n")).show();
206 function clean_picinfo() {
208 $.each(files, function(i, f) {
209 files_index[f] = true;
212 if (!files_index[f]) {
218 function undelete_all() {
220 delete picinfo[f].deleted;
223 say("Undeleted everything
");
227 if ("picsorter_picinfo
" in localStorage) {
228 picinfo = JSON.parse(localStorage.picsorter_picinfo);
230 $.each(files, function(i, f) {
231 if (!(f in picinfo)) {
238 $("#name
").hide().on("keyup
", function(e) { e.which == 13 && set_name_from_form(); });
239 move_to_nondeleted(1);
242 Mousetrap.bind('z', toggle_zoom);
243 Mousetrap.bind('Z', function() { $("#pic
").toggleClass("fit_view
"); return false; });
244 Mousetrap.bind(['n', 'l'], function() { move_to_nondeleted(1); return false; });
245 Mousetrap.bind(['p', 'h'], function() { move_to_nondeleted(-1); return false; });
246 Mousetrap.bind(['N', 'L'], function() { move_to_unnamed(1); return false; });
247 Mousetrap.bind(['P', 'H'], function() { move_to_unnamed(-1); return false; });
248 Mousetrap.bind(['m n', 'm l'], function() { move(1); return false; });
249 Mousetrap.bind(['m n', 'm h'], function() { move(-1); return false; });
250 Mousetrap.bind(['b', 'k'], function() { change_exposure(1); return false; });
251 Mousetrap.bind(['d', 'j'], function() { change_exposure(-1); return false; });
252 Mousetrap.bind('0', move_to_begenning);
253 Mousetrap.bind('$', move_to_end);
254 Mousetrap.bind('x', function(){ mark_deleted("deleted
"); return false; });
255 Mousetrap.bind('X', mark_not_deleted);
256 Mousetrap.bind('e', function(){ mark_deleted("extra
"); return false; });
257 Mousetrap.bind('E', mark_not_deleted);
258 Mousetrap.bind('g', function(){ mark_deleted("blurry
"); return false; });
259 Mousetrap.bind('G', mark_not_deleted);
260 Mousetrap.bind('r', rotate);
261 Mousetrap.bind('i', announce);
262 Mousetrap.bind('f', function() { say(files[input_index]); return false; });
263 Mousetrap.bind('B', say_exposure);
264 Mousetrap.bind('c', function() { $("#name
").show().focus(); return false; });
265 Mousetrap.bind('C', function() { if (last_name) { set_name(last_name); } return false; });
266 Mousetrap.bind('%', function() { say((100 * input_index / files.length).toFixed(2) + "%"); return false; });
267 Mousetrap.bind('!', show_commands);
268 Mousetrap.bind('esc', function() { $("#name
").hide(); $("#shell_out
").hide(); return false; });