]> git.scottworley.com Git - picsort/blame - picsorter.js
I miss ${foo%bar}
[picsort] / picsorter.js
CommitLineData
31092212
SW
1var picinfo = {};
2if ("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
10function save_picinfo() {
11 localStorage.picsorter_picinfo = JSON.stringify(picinfo);
12}
13save_picinfo();
2d325f41 14
ca898dc7
SW
15var exposure = 20;
16var zoom = "sm/";
17var input_index = -1;
ca898dc7 18
8bc0aad4
SW
19function endsWith(str, suffix) {
20 return str.indexOf(suffix, str.length - suffix.length) !== -1;
21}
22
23function 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 30function setpic() {
07f84670
SW
31 if ("exposure" in picinfo[files[input_index]]) {
32 exposure = picinfo[files[input_index]].exposure;
33 } else {
34 picinfo[files[input_index]].exposure = exposure;
01dd0481 35 save_picinfo();
07f84670 36 }
9952a1a7
SW
37 $("#pic").attr("src", zoom + exposure + "/" + files[input_index]);
38}
39
9c7566e1
SW
40function say(message) {
41 $("#message").text(message).removeClass("fade");
42 setTimeout(function() { $("#message").addClass("fade"); }, 1);
43}
44
9952a1a7
SW
45function toggle_zoom() {
46 if (zoom) {
47 zoom = "";
48 } else {
49 zoom = "sm/";
50 }
ac4559ea 51 setpic();
97c26a9c
SW
52}
53
2d325f41 54function move_to_nondeleted(direction) {
2d325f41
SW
55 do {
56 input_index += direction;
31092212 57 } while (picinfo[files[input_index]].deleted);
d92eb78e 58 say(input_index + " " + (picinfo[files[input_index]].name || ""));
c0230e38 59 setpic();
2d325f41
SW
60}
61
62function mark_deleted() {
31092212 63 picinfo[files[input_index]].deleted = 1;
01dd0481 64 save_picinfo();
9c7566e1 65 say("Deleted");
2d325f41
SW
66}
67
68function mark_not_deleted() {
31092212 69 delete picinfo[files[input_index]].deleted;
01dd0481 70 save_picinfo();
9c7566e1 71 say("Undeleted");
2d325f41
SW
72}
73
138122d7
SW
74function change_exposure(amount) {
75 exposure += amount;
07f84670 76 picinfo[files[input_index]].exposure = exposure;
01dd0481 77 save_picinfo();
138122d7
SW
78 setpic();
79 var display_exposure = (exposure / 4) - 3.5;
80 say((display_exposure >= 0 ? "+" : "") + display_exposure);
81}
82
d92eb78e
SW
83function set_name() {
84 var name_input = $("#name").hide().get(0);
85 var name = name_input.value;
86 name_input.value = "";
87 picinfo[files[input_index]].name = name;
88 save_picinfo();
89 say("Named " + name);
90}
91
5d9946cb 92$(function() {
d92eb78e 93 $("#name").hide().on("keyup", function(e) { e.which == 13 && set_name(); });
c0230e38 94 move_to_nondeleted(1);
e18c13a6 95});
ecb5b4ef 96
ac4559ea 97Mousetrap.bind('z', toggle_zoom);
9952a1a7 98Mousetrap.bind('Z', function() { $("#pic").toggleClass("fit_view"); });
c0230e38
SW
99Mousetrap.bind('n', function() { move_to_nondeleted(1); });
100Mousetrap.bind('p', function() { move_to_nondeleted(-1); });
9c7566e1
SW
101Mousetrap.bind('N', function() { input_index ++; say(input_index); setpic(); });
102Mousetrap.bind('P', function() { input_index --; say(input_index); setpic(); });
138122d7
SW
103Mousetrap.bind('b', function() { change_exposure(1); });
104Mousetrap.bind('d', function() { change_exposure(-1); });
ac4559ea
SW
105Mousetrap.bind('x', mark_deleted);
106Mousetrap.bind('X', mark_not_deleted);
d92eb78e 107Mousetrap.bind('c', function() { $("#name").show().focus(); return false; });