]>
git.scottworley.com Git - picsort/blob - picsorter.js
d10631cc008fef86930967e127d264c8bc28cb9c
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
+ ")";
56 function toggle_zoom() {
65 function move_by_filter(direction
, filter
) {
66 // Keep moving in direction until filter is satisfied
67 var new_index
= input_index
;
69 var next
= new_index
+ direction
;
74 if (next
>= files
.length
) {
79 if (filter(new_index
)) {
83 input_index
= new_index
;
87 function move(direction
) {
88 move_by_filter(direction
, function() { return true; });
90 function move_to_begenning() {
91 move_by_filter(-1, function(i
) { return i
== 0; });
93 function move_to_end() {
94 move_by_filter(1, function(i
) { return i
== files
.length
- 1; });
96 function move_to_nondeleted(direction
) {
97 move_by_filter(direction
, function(i
) {
98 return !("deleted" in picinfo
[files
[i
]]); });
100 function move_to_unnamed(direction
) {
101 move_by_filter(direction
, function(i
) {
102 return !("deleted" in picinfo
[files
[i
]]) &&
103 !("name" in picinfo
[files
[i
]]); });
106 function mark_deleted(method
) {
107 picinfo
[files
[input_index
]].deleted
= method
;
112 function mark_not_deleted() {
113 delete picinfo
[files
[input_index
]].deleted
;
118 function say_exposure() {
119 if (!endsWith(files
[input_index
], ".NEF")) {
120 say("Exposure adjustment not available");
123 var display_exposure
= (exposure
/ 4) - 3.5;
124 say((display_exposure
>= 0 ? "+" : "") + display_exposure
);
127 function change_exposure(amount
) {
128 if (!endsWith(files
[input_index
], ".NEF")) {
129 say("Exposure adjustment not available");
133 picinfo
[files
[input_index
]].exposure
= exposure
;
140 var rotation
= picinfo
[files
[input_index
]].rotate
|| 0;
141 rotation
= (rotation
+ 90) % 360;
142 if (rotation
> 1e-5) {
143 picinfo
[files
[input_index
]].rotate
= rotation
;
145 delete picinfo
[files
[input_index
]].rotate
;
152 function set_name(name
) {
154 picinfo
[files
[input_index
]].name
= name
;
156 say("Named " + name
);
161 function set_name_from_form() {
162 var name_input
= $("#name").hide().get(0);
163 set_name(name_input
.value
);
164 name_input
.value
= "";
167 function shell_escape(x
) {
168 return x
.replace(/'/g, "'\\''");
171 function show_commands() {
173 $.each(files, function(i, f) {
174 var escaped_filename = "'" + shell_escape(f) + "'";
175 if (picinfo[f].deleted == "deleted
") {
176 commands.push("shred
-u
" + escaped_filename);
177 } else if (picinfo[f].deleted == "extra
") {
178 commands.push("mv
-vi
" + escaped_filename + " \"$EXTRADIR
\"");
179 } else if (picinfo[f].deleted == "blurry
") {
180 commands.push("mv
-vi
" + escaped_filename + " \"$BLURRYDIR
\"");
181 } else if ("name
" in picinfo[f] && picinfo[f].name.length > 0) {
182 var command = ["pic
-mv
"];
183 if ("exposure
" in picinfo[f]) {
184 command.push("-e
" + picinfo[f].exposure);
186 if ("rotate
" in picinfo[f]) {
187 command.push("-r
" + picinfo[f].rotate);
189 command.push(escaped_filename);
190 command.push("'" + shell_escape(picinfo[f].name) + "'");
191 commands.push(command.join(" "));
195 $("#shell_out
").text(commands.join("\n")).show();
198 function clean_picinfo() {
200 $.each(files, function(i, f) {
201 files_index[f] = true;
204 if (!files_index[f]) {
210 function undelete_all() {
212 delete picinfo[f].deleted;
215 say("Undeleted everything
");
219 if ("picsorter_picinfo
" in localStorage) {
220 picinfo = JSON.parse(localStorage.picsorter_picinfo);
222 $.each(files, function(i, f) {
223 if (!(f in picinfo)) {
230 $("#name
").hide().on("keyup
", function(e) { e.which == 13 && set_name_from_form(); });
231 move_to_nondeleted(1);
234 Mousetrap.bind('z', toggle_zoom);
235 Mousetrap.bind('Z', function() { $("#pic
").toggleClass("fit_view
"); return false; });
236 Mousetrap.bind(['n', 'l'], function() { move_to_nondeleted(1); return false; });
237 Mousetrap.bind(['p', 'h'], function() { move_to_nondeleted(-1); return false; });
238 Mousetrap.bind(['N', 'L'], function() { move_to_unnamed(1); return false; });
239 Mousetrap.bind(['P', 'H'], function() { move_to_unnamed(-1); return false; });
240 Mousetrap.bind(['m n', 'm l'], function() { move(1); return false; });
241 Mousetrap.bind(['m n', 'm h'], function() { move(-1); return false; });
242 Mousetrap.bind(['b', 'k'], function() { change_exposure(1); return false; });
243 Mousetrap.bind(['d', 'j'], function() { change_exposure(-1); return false; });
244 Mousetrap.bind('0', move_to_begenning);
245 Mousetrap.bind('$', move_to_end);
246 Mousetrap.bind('x', function(){ mark_deleted("deleted
"); return false; });
247 Mousetrap.bind('X', mark_not_deleted);
248 Mousetrap.bind('e', function(){ mark_deleted("extra
"); return false; });
249 Mousetrap.bind('E', mark_not_deleted);
250 Mousetrap.bind('g', function(){ mark_deleted("blurry
"); return false; });
251 Mousetrap.bind('G', mark_not_deleted);
252 Mousetrap.bind('r', rotate);
253 Mousetrap.bind('i', announce);
254 Mousetrap.bind('f', function() { say(files[input_index]); return false; });
255 Mousetrap.bind('B', say_exposure);
256 Mousetrap.bind('c', function() { $("#name
").show().focus(); return false; });
257 Mousetrap.bind('C', function() { if (last_name) { set_name(last_name); } return false; });
258 Mousetrap.bind('%', function() { say((100 * input_index / files.length).toFixed(2) + "%"); return false; });
259 Mousetrap.bind('!', show_commands);
260 Mousetrap.bind('esc', function() { $("#name
").hide(); $("#shell_out
").hide(); return false; });