]>
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 | 18 | |
8bc0aad4 SW |
19 | function endsWith(str, suffix) { |
20 | return str.indexOf(suffix, str.length - suffix.length) !== -1; | |
21 | } | |
22 | ||
23 | function 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 | 30 | function 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 |
46 | function say(message) { |
47 | $("#message").text(message).removeClass("fade"); | |
48 | setTimeout(function() { $("#message").addClass("fade"); }, 1); | |
49 | } | |
50 | ||
9952a1a7 SW |
51 | function toggle_zoom() { |
52 | if (zoom) { | |
53 | zoom = ""; | |
54 | } else { | |
55 | zoom = "sm/"; | |
56 | } | |
ac4559ea | 57 | setpic(); |
97c26a9c SW |
58 | } |
59 | ||
2d325f41 | 60 | function move_to_nondeleted(direction) { |
2d325f41 SW |
61 | do { |
62 | input_index += direction; | |
31092212 | 63 | } while (picinfo[files[input_index]].deleted); |
d92eb78e | 64 | say(input_index + " " + (picinfo[files[input_index]].name || "")); |
c0230e38 | 65 | setpic(); |
2d325f41 SW |
66 | } |
67 | ||
68 | function mark_deleted() { | |
31092212 | 69 | picinfo[files[input_index]].deleted = 1; |
01dd0481 | 70 | save_picinfo(); |
9c7566e1 | 71 | say("Deleted"); |
2d325f41 SW |
72 | } |
73 | ||
74 | function mark_not_deleted() { | |
31092212 | 75 | delete picinfo[files[input_index]].deleted; |
01dd0481 | 76 | save_picinfo(); |
9c7566e1 | 77 | say("Undeleted"); |
2d325f41 SW |
78 | } |
79 | ||
138122d7 SW |
80 | function change_exposure(amount) { |
81 | exposure += amount; | |
07f84670 | 82 | picinfo[files[input_index]].exposure = exposure; |
01dd0481 | 83 | save_picinfo(); |
138122d7 SW |
84 | setpic(); |
85 | var display_exposure = (exposure / 4) - 3.5; | |
86 | say((display_exposure >= 0 ? "+" : "") + display_exposure); | |
87 | } | |
88 | ||
d92eb78e SW |
89 | function set_name() { |
90 | var name_input = $("#name").hide().get(0); | |
91 | var name = name_input.value; | |
92 | name_input.value = ""; | |
93 | picinfo[files[input_index]].name = name; | |
94 | save_picinfo(); | |
95 | say("Named " + name); | |
96 | } | |
97 | ||
5d9946cb | 98 | $(function() { |
d92eb78e | 99 | $("#name").hide().on("keyup", function(e) { e.which == 13 && set_name(); }); |
c0230e38 | 100 | move_to_nondeleted(1); |
e18c13a6 | 101 | }); |
ecb5b4ef | 102 | |
ac4559ea | 103 | Mousetrap.bind('z', toggle_zoom); |
9952a1a7 | 104 | Mousetrap.bind('Z', function() { $("#pic").toggleClass("fit_view"); }); |
a5ef2857 SW |
105 | Mousetrap.bind(['n', 'l'], function() { move_to_nondeleted(1); }); |
106 | Mousetrap.bind(['p', 'h'], function() { move_to_nondeleted(-1); }); | |
107 | Mousetrap.bind(['N', 'L'], function() { input_index ++; say(input_index); setpic(); }); | |
108 | Mousetrap.bind(['P', 'H'], function() { input_index --; say(input_index); setpic(); }); | |
109 | Mousetrap.bind(['b', 'k'], function() { change_exposure(1); }); | |
110 | Mousetrap.bind(['d', 'j'], function() { change_exposure(-1); }); | |
ac4559ea SW |
111 | Mousetrap.bind('x', mark_deleted); |
112 | Mousetrap.bind('X', mark_not_deleted); | |
d92eb78e | 113 | Mousetrap.bind('c', function() { $("#name").show().focus(); return false; }); |