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