]> git.scottworley.com Git - picsort/blame_incremental - picsorter.js
hjkl movement keys
[picsort] / picsorter.js
... / ...
CommitLineData
1var picinfo = {};
2if ("picsorter_picinfo" in localStorage) {
3 picinfo = JSON.parse(localStorage.picsorter_picinfo);
4}
5$.each(files, function(i, f) {
6 if (!(f in picinfo)) {
7 picinfo[f] = {};
8 }
9});
10function save_picinfo() {
11 localStorage.picsorter_picinfo = JSON.stringify(picinfo);
12}
13save_picinfo();
14
15var exposure = 20;
16var zoom = "sm/";
17var input_index = -1;
18
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}
29
30function setpic() {
31 if ("exposure" in picinfo[files[input_index]]) {
32 exposure = picinfo[files[input_index]].exposure;
33 } else {
34 picinfo[files[input_index]].exposure = exposure;
35 save_picinfo();
36 }
37 $("#pic").attr("src", zoom + exposure + "/" + files[input_index]);
38}
39
40function say(message) {
41 $("#message").text(message).removeClass("fade");
42 setTimeout(function() { $("#message").addClass("fade"); }, 1);
43}
44
45function toggle_zoom() {
46 if (zoom) {
47 zoom = "";
48 } else {
49 zoom = "sm/";
50 }
51 setpic();
52}
53
54function move_to_nondeleted(direction) {
55 do {
56 input_index += direction;
57 } while (picinfo[files[input_index]].deleted);
58 say(input_index + " " + (picinfo[files[input_index]].name || ""));
59 setpic();
60}
61
62function mark_deleted() {
63 picinfo[files[input_index]].deleted = 1;
64 save_picinfo();
65 say("Deleted");
66}
67
68function mark_not_deleted() {
69 delete picinfo[files[input_index]].deleted;
70 save_picinfo();
71 say("Undeleted");
72}
73
74function change_exposure(amount) {
75 exposure += amount;
76 picinfo[files[input_index]].exposure = exposure;
77 save_picinfo();
78 setpic();
79 var display_exposure = (exposure / 4) - 3.5;
80 say((display_exposure >= 0 ? "+" : "") + display_exposure);
81}
82
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
92$(function() {
93 $("#name").hide().on("keyup", function(e) { e.which == 13 && set_name(); });
94 move_to_nondeleted(1);
95});
96
97Mousetrap.bind('z', toggle_zoom);
98Mousetrap.bind('Z', function() { $("#pic").toggleClass("fit_view"); });
99Mousetrap.bind(['n', 'l'], function() { move_to_nondeleted(1); });
100Mousetrap.bind(['p', 'h'], function() { move_to_nondeleted(-1); });
101Mousetrap.bind(['N', 'L'], function() { input_index ++; say(input_index); setpic(); });
102Mousetrap.bind(['P', 'H'], function() { input_index --; say(input_index); setpic(); });
103Mousetrap.bind(['b', 'k'], function() { change_exposure(1); });
104Mousetrap.bind(['d', 'j'], function() { change_exposure(-1); });
105Mousetrap.bind('x', mark_deleted);
106Mousetrap.bind('X', mark_not_deleted);
107Mousetrap.bind('c', function() { $("#name").show().focus(); return false; });