]>
git.scottworley.com Git - picsort/blob - picsorter.js
6608edff15549b05a438f67626a78941d372b332
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 say(input_index
+ " " + (picinfo
[files
[input_index
]].name
|| ""));
61 function toggle_zoom() {
70 function move_by_filter(direction
, filter
) {
71 // Keep moving in direction until filter is satisfied
72 var new_index
= input_index
;
74 var next
= new_index
+ direction
;
79 if (next
>= files
.length
) {
84 if (filter(new_index
)) {
88 input_index
= new_index
;
92 function move(direction
) {
93 move_by_filter(direction
, function() { return true; });
95 function move_to_begenning() {
96 move_by_filter(-1, function(i
) { return i
== 0; });
98 function move_to_end() {
99 move_by_filter(1, function(i
) { return i
== files
.length
- 1; });
101 function move_to_nondeleted(direction
) {
102 move_by_filter(direction
, function(i
) {
103 return !("deleted" in picinfo
[files
[i
]]); });
105 function move_to_unnamed(direction
) {
106 move_by_filter(direction
, function(i
) {
107 return !("deleted" in picinfo
[files
[i
]]) &&
108 !("name" in picinfo
[files
[i
]]); });
111 function mark_deleted(method
) {
112 picinfo
[files
[input_index
]].deleted
= method
;
117 function mark_not_deleted() {
118 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
);
132 function change_exposure(amount
) {
133 if (!endsWith(files
[input_index
], ".NEF")) {
134 say("Exposure adjustment not available");
138 picinfo
[files
[input_index
]].exposure
= exposure
;
145 var rotation
= picinfo
[files
[input_index
]].rotate
|| 0;
146 rotation
= (rotation
+ 90) % 360;
147 if (rotation
> 1e-5) {
148 picinfo
[files
[input_index
]].rotate
= rotation
;
150 delete picinfo
[files
[input_index
]].rotate
;
157 function set_name(name
) {
158 picinfo
[files
[input_index
]].name
= name
;
160 say("Named " + name
);
164 function set_name_from_form() {
165 var name_input
= $("#name").hide().get(0);
166 set_name(name_input
.value
);
167 name_input
.value
= "";
170 function shell_escape(x
) {
171 return x
.replace(/'/g, "'\\''");
174 function show_commands() {
176 $.each(files, function(i, f) {
177 if ("name
" in picinfo[f] && picinfo[f].name.length > 0) {
178 var escaped_filename = "'" + shell_escape(picinfo[f].name) + "'";
179 if (picinfo[f].deleted == "deleted
") {
180 commands.push("rm
" + escaped_filename);
183 if (picinfo[f].deleted == "extra
") {
184 commands.push("mv
" + escaped_filename + " \"$EXTRADIR
\"");
187 var command = ["pic
-mv
"];
188 if ("exposure
" in picinfo[f]) {
189 command.push("-e
" + picinfo[f].exposure);
191 if ("rotate
" in picinfo[f]) {
192 command.push("-r
" + picinfo[f].rotate);
194 command.push("'" + shell_escape(f) + "'");
195 command.push(escaped_filename);
196 commands.push(command.join(" "));
200 $("#shell_out
").text(commands.join("\n")).show();
204 $("#name
").hide().on("keyup
", function(e) { e.which == 13 && set_name_from_form(); });
205 move_to_nondeleted(1);
208 Mousetrap.bind('z', toggle_zoom);
209 Mousetrap.bind('Z', function() { $("#pic
").toggleClass("fit_view
"); });
210 Mousetrap.bind(['n', 'l'], function() { move_to_nondeleted(1); });
211 Mousetrap.bind(['p', 'h'], function() { move_to_nondeleted(-1); });
212 Mousetrap.bind(['N', 'L'], function() { move_to_unnamed(1); });
213 Mousetrap.bind(['P', 'H'], function() { move_to_unnamed(-1); });
214 Mousetrap.bind(['m n', 'm l'], function() { move(1); });
215 Mousetrap.bind(['m n', 'm h'], function() { move(-1); });
216 Mousetrap.bind(['b', 'k'], function() { change_exposure(1); });
217 Mousetrap.bind(['d', 'j'], function() { change_exposure(-1); });
218 Mousetrap.bind('0', move_to_begenning);
219 Mousetrap.bind('$', move_to_end);
220 Mousetrap.bind('x', function(){ mark_deleted("deleted
"); });
221 Mousetrap.bind('X', mark_not_deleted);
222 Mousetrap.bind('e', function(){ mark_deleted("extra
"); });
223 Mousetrap.bind('E', mark_not_deleted);
224 Mousetrap.bind('r', rotate);
225 Mousetrap.bind('i', announce);
226 Mousetrap.bind('f', function() { say(files[input_index]); });
227 Mousetrap.bind('B', function() { say_exposure(); });
228 Mousetrap.bind('c', function() { $("#name
").show().focus(); return false; });
229 Mousetrap.bind('C', function() { if (last_name) { set_name(last_name); } });
230 Mousetrap.bind('%', function() { say((100 * input_index / files.length).toFixed(2) + "%"); });
231 Mousetrap.bind('!', show_commands);
232 Mousetrap.bind('esc', function() { $("#name
").hide(); $("#shell_out
").hide(); });
234 function clean_picinfo() {
236 $.each(files, function(i, f) {
237 files_index[f] = true;
240 if (!files_index[f]) {
246 function undelete_all() {
248 delete picinfo[f].deleted;
251 say("Undeleted everything
");