]>
git.scottworley.com Git - picsort/blob - picsorter.js
2 if ("picsorter_picinfo" in localStorage
) {
3 picinfo
= JSON
.parse(localStorage
.picsorter_picinfo
);
5 $.each(files
, function(i
, f
) {
10 function save_picinfo() {
11 localStorage
.picsorter_picinfo
= JSON
.stringify(picinfo
);
19 function endsWith(str
, suffix
) {
20 return str
.indexOf(suffix
, str
.length
- suffix
.length
) !== -1;
23 function stripFromEnd(str
, suffix
) {
24 if (endsWith(str
, suffix
)) {
25 return str
.substr(0, str
.length
- suffix
.length
);
32 if (endsWith(files
[input_index
], ".NEF")) {
33 if ("exposure" in picinfo
[files
[input_index
]]) {
34 exposure
= picinfo
[files
[input_index
]].exposure
;
36 picinfo
[files
[input_index
]].exposure
= exposure
;
39 display_filename
= zoom
+ exposure
+ "/" + stripFromEnd(files
[input_index
], ".NEF") + ".jpeg";
41 display_filename
= zoom
+ files
[input_index
];
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
);
50 $pic
.attr("src", display_filename
);
53 function say(message
) {
54 $("#message").text(message
).removeClass("fade");
55 setTimeout(function() { $("#message").addClass("fade"); }, 100);
58 var msg
= input_index
+ " " + (picinfo
[files
[input_index
]].name
|| "");
59 if ("deleted" in picinfo
[files
[input_index
]]) {
60 msg
+= "(" + picinfo
[files
[input_index
]].deleted
+ ")";
65 function toggle_zoom() {
74 function move_by_filter(direction
, filter
) {
75 // Keep moving in direction until filter is satisfied
76 var new_index
= input_index
;
78 var next
= new_index
+ direction
;
83 if (next
>= files
.length
) {
88 if (filter(new_index
)) {
92 input_index
= new_index
;
96 function move(direction
) {
97 move_by_filter(direction
, function() { return true; });
99 function move_to_begenning() {
100 move_by_filter(-1, function(i
) { return i
== 0; });
102 function move_to_end() {
103 move_by_filter(1, function(i
) { return i
== files
.length
- 1; });
105 function move_to_nondeleted(direction
) {
106 move_by_filter(direction
, function(i
) {
107 return !("deleted" in picinfo
[files
[i
]]); });
109 function move_to_unnamed(direction
) {
110 move_by_filter(direction
, function(i
) {
111 return !("deleted" in picinfo
[files
[i
]]) &&
112 !("name" in picinfo
[files
[i
]]); });
115 function mark_deleted(method
) {
116 picinfo
[files
[input_index
]].deleted
= method
;
121 function mark_not_deleted() {
122 delete picinfo
[files
[input_index
]].deleted
;
127 function say_exposure() {
128 if (!endsWith(files
[input_index
], ".NEF")) {
129 say("Exposure adjustment not available");
132 var display_exposure
= (exposure
/ 4) - 3.5;
133 say((display_exposure
>= 0 ? "+" : "") + display_exposure
);
136 function change_exposure(amount
) {
137 if (!endsWith(files
[input_index
], ".NEF")) {
138 say("Exposure adjustment not available");
142 picinfo
[files
[input_index
]].exposure
= exposure
;
149 var rotation
= picinfo
[files
[input_index
]].rotate
|| 0;
150 rotation
= (rotation
+ 90) % 360;
151 if (rotation
> 1e-5) {
152 picinfo
[files
[input_index
]].rotate
= rotation
;
154 delete picinfo
[files
[input_index
]].rotate
;
161 function set_name(name
) {
163 picinfo
[files
[input_index
]].name
= name
;
165 say("Named " + name
);
170 function set_name_from_form() {
171 var name_input
= $("#name").hide().get(0);
172 set_name(name_input
.value
);
173 name_input
.value
= "";
176 function shell_escape(x
) {
177 return x
.replace(/'/g, "'\\''");
180 function show_commands() {
182 $.each(files, function(i, f) {
183 var escaped_filename = "'" + shell_escape(f) + "'";
184 if (picinfo[f].deleted == "deleted
") {
185 commands.push("shred
-u
" + escaped_filename);
186 } else if (picinfo[f].deleted == "extra
") {
187 commands.push("mv
-vi
" + escaped_filename + " \"$EXTRADIR
\"");
188 } else if (picinfo[f].deleted == "blurry
") {
189 commands.push("mv
-vi
" + escaped_filename + " \"$BLURRYDIR
\"");
190 } else if ("name
" in picinfo[f] && picinfo[f].name.length > 0) {
191 var command = ["pic
-mv
"];
192 if ("exposure
" in picinfo[f]) {
193 command.push("-e
" + picinfo[f].exposure);
195 if ("rotate
" in picinfo[f]) {
196 command.push("-r
" + picinfo[f].rotate);
198 command.push(escaped_filename);
199 command.push("'" + shell_escape(picinfo[f].name) + "'");
200 commands.push(command.join(" "));
204 $("#shell_out
").text(commands.join("\n")).show();
208 $("#name
").hide().on("keyup
", function(e) { e.which == 13 && set_name_from_form(); });
209 move_to_nondeleted(1);
212 Mousetrap.bind('z', toggle_zoom);
213 Mousetrap.bind('Z', function() { $("#pic
").toggleClass("fit_view
"); });
214 Mousetrap.bind(['n', 'l'], function() { move_to_nondeleted(1); });
215 Mousetrap.bind(['p', 'h'], function() { move_to_nondeleted(-1); });
216 Mousetrap.bind(['N', 'L'], function() { move_to_unnamed(1); });
217 Mousetrap.bind(['P', 'H'], function() { move_to_unnamed(-1); });
218 Mousetrap.bind(['m n', 'm l'], function() { move(1); });
219 Mousetrap.bind(['m n', 'm h'], function() { move(-1); });
220 Mousetrap.bind(['b', 'k'], function() { change_exposure(1); });
221 Mousetrap.bind(['d', 'j'], function() { change_exposure(-1); });
222 Mousetrap.bind('0', move_to_begenning);
223 Mousetrap.bind('$', move_to_end);
224 Mousetrap.bind('x', function(){ mark_deleted("deleted
"); });
225 Mousetrap.bind('X', mark_not_deleted);
226 Mousetrap.bind('e', function(){ mark_deleted("extra
"); });
227 Mousetrap.bind('E', mark_not_deleted);
228 Mousetrap.bind('g', function(){ mark_deleted("blurry
"); });
229 Mousetrap.bind('G', mark_not_deleted);
230 Mousetrap.bind('r', rotate);
231 Mousetrap.bind('i', announce);
232 Mousetrap.bind('f', function() { say(files[input_index]); });
233 Mousetrap.bind('B', function() { say_exposure(); });
234 Mousetrap.bind('c', function() { $("#name
").show().focus(); return false; });
235 Mousetrap.bind('C', function() { if (last_name) { set_name(last_name); } });
236 Mousetrap.bind('%', function() { say((100 * input_index / files.length).toFixed(2) + "%"); });
237 Mousetrap.bind('!', show_commands);
238 Mousetrap.bind('esc', function() { $("#name
").hide(); $("#shell_out
").hide(); });
240 function clean_picinfo() {
242 $.each(files, function(i, f) {
243 files_index[f] = true;
246 if (!files_index[f]) {
252 function undelete_all() {
254 delete picinfo[f].deleted;
257 say("Undeleted everything
");