]> git.scottworley.com Git - picsort/blame - picsorter.js
'r' to Rotate.
[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 }
59a0fba1
SW
43 var $pic = $("#pic");
44 $pic.attr("src", display_filename);
45 $pic.removeClass("rot90 rot180 rot270");
46 if ("rotate" in picinfo[files[input_index]]) {
47 $pic.addClass("rot" + picinfo[files[input_index]].rotate);
48 }
9952a1a7
SW
49}
50
9c7566e1
SW
51function say(message) {
52 $("#message").text(message).removeClass("fade");
53 setTimeout(function() { $("#message").addClass("fade"); }, 1);
54}
55
9952a1a7
SW
56function toggle_zoom() {
57 if (zoom) {
58 zoom = "";
59 } else {
60 zoom = "sm/";
61 }
ac4559ea 62 setpic();
97c26a9c
SW
63}
64
1433682c
SW
65function move_by_filter(direction, filter) {
66 // Keep moving in direction until filter is satisfied
755cf903
SW
67 var new_index = input_index;
68 while (true) {
69 var next = new_index + direction;
70 if (next < 0) {
71 say("At beginning");
72 return;
73 }
74 if (next >= files.length) {
75 say("At end");
76 return;
77 }
78 new_index = next;
79 if (filter(new_index)) {
80 break;
81 }
82 }
83 input_index = new_index;
d92eb78e 84 say(input_index + " " + (picinfo[files[input_index]].name || ""));
c0230e38 85 setpic();
2d325f41 86}
1433682c
SW
87function move(direction) {
88 move_by_filter(direction, function() { return true; });
89}
90function move_to_nondeleted(direction) {
755cf903
SW
91 move_by_filter(direction, function(i) {
92 return !("deleted" in picinfo[files[i]]); });
1433682c
SW
93}
94function move_to_unnamed(direction) {
755cf903
SW
95 move_by_filter(direction, function(i) {
96 return !("deleted" in picinfo[files[i]]) &&
97 !("name" in picinfo[files[i]]); });
1433682c 98}
2d325f41
SW
99
100function mark_deleted() {
31092212 101 picinfo[files[input_index]].deleted = 1;
01dd0481 102 save_picinfo();
9c7566e1 103 say("Deleted");
2d325f41
SW
104}
105
106function mark_not_deleted() {
31092212 107 delete picinfo[files[input_index]].deleted;
01dd0481 108 save_picinfo();
9c7566e1 109 say("Undeleted");
2d325f41
SW
110}
111
138122d7 112function change_exposure(amount) {
b11d9c69
SW
113 if (!endsWith(files[input_index], ".NEF")) {
114 say("Exposure adjustment not available");
115 return;
116 }
138122d7 117 exposure += amount;
07f84670 118 picinfo[files[input_index]].exposure = exposure;
01dd0481 119 save_picinfo();
138122d7
SW
120 setpic();
121 var display_exposure = (exposure / 4) - 3.5;
122 say((display_exposure >= 0 ? "+" : "") + display_exposure);
123}
124
59a0fba1
SW
125function rotate() {
126 var rotation = picinfo[files[input_index]].rotate || 0;
127 rotation = (rotation + 90) % 360;
128 if (rotation > 1e-5) {
129 picinfo[files[input_index]].rotate = rotation;
130 } else {
131 delete picinfo[files[input_index]].rotate;
132 }
133 save_picinfo();
134 setpic();
135}
136
d92eb78e
SW
137function set_name() {
138 var name_input = $("#name").hide().get(0);
139 var name = name_input.value;
140 name_input.value = "";
141 picinfo[files[input_index]].name = name;
142 save_picinfo();
143 say("Named " + name);
144}
145
5d9946cb 146$(function() {
d92eb78e 147 $("#name").hide().on("keyup", function(e) { e.which == 13 && set_name(); });
c0230e38 148 move_to_nondeleted(1);
e18c13a6 149});
ecb5b4ef 150
ac4559ea 151Mousetrap.bind('z', toggle_zoom);
9952a1a7 152Mousetrap.bind('Z', function() { $("#pic").toggleClass("fit_view"); });
a5ef2857
SW
153Mousetrap.bind(['n', 'l'], function() { move_to_nondeleted(1); });
154Mousetrap.bind(['p', 'h'], function() { move_to_nondeleted(-1); });
1433682c
SW
155Mousetrap.bind(['N', 'L'], function() { move_to_unnamed(1); });
156Mousetrap.bind(['P', 'H'], function() { move_to_unnamed(-1); });
157Mousetrap.bind(['m n', 'm l'], function() { move(1); });
158Mousetrap.bind(['m n', 'm h'], function() { move(-1); });
a5ef2857
SW
159Mousetrap.bind(['b', 'k'], function() { change_exposure(1); });
160Mousetrap.bind(['d', 'j'], function() { change_exposure(-1); });
ac4559ea
SW
161Mousetrap.bind('x', mark_deleted);
162Mousetrap.bind('X', mark_not_deleted);
59a0fba1 163Mousetrap.bind('r', rotate);
d92eb78e 164Mousetrap.bind('c', function() { $("#name").show().focus(); return false; });