]> git.scottworley.com Git - picsort/blame - picsorter.js
move_to_unnamed()
[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() {
cd368e97
SW
31 var display_filename;
32 if (endsWith(files[input_index], ".NEF")) {
33 if ("exposure" in picinfo[files[input_index]]) {
34 exposure = picinfo[files[input_index]].exposure;
35 } else {
36 picinfo[files[input_index]].exposure = exposure;
37 save_picinfo();
38 }
39 display_filename = zoom + exposure + "/" + stripFromEnd(files[input_index], ".NEF") + ".jpeg";
07f84670 40 } else {
cd368e97 41 display_filename = zoom + files[input_index];
07f84670 42 }
cd368e97 43 $("#pic").attr("src", display_filename);
9952a1a7
SW
44}
45
9c7566e1
SW
46function say(message) {
47 $("#message").text(message).removeClass("fade");
48 setTimeout(function() { $("#message").addClass("fade"); }, 1);
49}
50
9952a1a7
SW
51function toggle_zoom() {
52 if (zoom) {
53 zoom = "";
54 } else {
55 zoom = "sm/";
56 }
ac4559ea 57 setpic();
97c26a9c
SW
58}
59
1433682c
SW
60function move_by_filter(direction, filter) {
61 // Keep moving in direction until filter is satisfied
2d325f41
SW
62 do {
63 input_index += direction;
1433682c 64 } while (!filter());
d92eb78e 65 say(input_index + " " + (picinfo[files[input_index]].name || ""));
c0230e38 66 setpic();
2d325f41 67}
1433682c
SW
68function move(direction) {
69 move_by_filter(direction, function() { return true; });
70}
71function move_to_nondeleted(direction) {
72 move_by_filter(direction, function() {
73 return !("deleted" in picinfo[files[input_index]]); });
74}
75function move_to_unnamed(direction) {
76 move_by_filter(direction, function() {
77 return !("deleted" in picinfo[files[input_index]]) &&
78 !("name" in picinfo[files[input_index]]); });
79}
2d325f41
SW
80
81function mark_deleted() {
31092212 82 picinfo[files[input_index]].deleted = 1;
01dd0481 83 save_picinfo();
9c7566e1 84 say("Deleted");
2d325f41
SW
85}
86
87function mark_not_deleted() {
31092212 88 delete picinfo[files[input_index]].deleted;
01dd0481 89 save_picinfo();
9c7566e1 90 say("Undeleted");
2d325f41
SW
91}
92
138122d7
SW
93function change_exposure(amount) {
94 exposure += amount;
07f84670 95 picinfo[files[input_index]].exposure = exposure;
01dd0481 96 save_picinfo();
138122d7
SW
97 setpic();
98 var display_exposure = (exposure / 4) - 3.5;
99 say((display_exposure >= 0 ? "+" : "") + display_exposure);
100}
101
d92eb78e
SW
102function set_name() {
103 var name_input = $("#name").hide().get(0);
104 var name = name_input.value;
105 name_input.value = "";
106 picinfo[files[input_index]].name = name;
107 save_picinfo();
108 say("Named " + name);
109}
110
5d9946cb 111$(function() {
d92eb78e 112 $("#name").hide().on("keyup", function(e) { e.which == 13 && set_name(); });
c0230e38 113 move_to_nondeleted(1);
e18c13a6 114});
ecb5b4ef 115
ac4559ea 116Mousetrap.bind('z', toggle_zoom);
9952a1a7 117Mousetrap.bind('Z', function() { $("#pic").toggleClass("fit_view"); });
a5ef2857
SW
118Mousetrap.bind(['n', 'l'], function() { move_to_nondeleted(1); });
119Mousetrap.bind(['p', 'h'], function() { move_to_nondeleted(-1); });
1433682c
SW
120Mousetrap.bind(['N', 'L'], function() { move_to_unnamed(1); });
121Mousetrap.bind(['P', 'H'], function() { move_to_unnamed(-1); });
122Mousetrap.bind(['m n', 'm l'], function() { move(1); });
123Mousetrap.bind(['m n', 'm h'], function() { move(-1); });
a5ef2857
SW
124Mousetrap.bind(['b', 'k'], function() { change_exposure(1); });
125Mousetrap.bind(['d', 'j'], function() { change_exposure(-1); });
ac4559ea
SW
126Mousetrap.bind('x', mark_deleted);
127Mousetrap.bind('X', mark_not_deleted);
d92eb78e 128Mousetrap.bind('c', function() { $("#name").show().focus(); return false; });