]>
git.scottworley.com Git - picsort/blob - picsorter.js
ec63cbc8fd3d5a64473e0a368ed6579932685cab
2 if ("picsorter_picinfo" in localStorage
) {
3 picinfo
= JSON
.parse(localStorage
.picsorter_picinfo
);
5 $.each(files
, function(i
, f
) {
10 function save_picinfo() {
11 localStorage
.picsorter_picinfo
= JSON
.stringify(picinfo
);
19 function endsWith(str
, suffix
) {
20 return str
.indexOf(suffix
, str
.length
- suffix
.length
) !== -1;
23 function stripFromEnd(str
, suffix
) {
24 if (endsWith(str
, suffix
)) {
25 return str
.substr(0, str
.length
- suffix
.length
);
32 if (endsWith(files
[input_index
], ".NEF")) {
33 if ("exposure" in picinfo
[files
[input_index
]]) {
34 exposure
= picinfo
[files
[input_index
]].exposure
;
36 picinfo
[files
[input_index
]].exposure
= exposure
;
39 display_filename
= zoom
+ exposure
+ "/" + stripFromEnd(files
[input_index
], ".NEF") + ".jpeg";
41 display_filename
= zoom
+ files
[input_index
];
43 $("#pic").attr("src", display_filename
);
46 function say(message
) {
47 $("#message").text(message
).removeClass("fade");
48 setTimeout(function() { $("#message").addClass("fade"); }, 1);
51 function toggle_zoom() {
60 function move_by_filter(direction
, filter
) {
61 // Keep moving in direction until filter is satisfied
62 var new_index
= input_index
;
64 var next
= new_index
+ direction
;
69 if (next
>= files
.length
) {
74 if (filter(new_index
)) {
78 input_index
= new_index
;
79 say(input_index
+ " " + (picinfo
[files
[input_index
]].name
|| ""));
82 function move(direction
) {
83 move_by_filter(direction
, function() { return true; });
85 function move_to_nondeleted(direction
) {
86 move_by_filter(direction
, function(i
) {
87 return !("deleted" in picinfo
[files
[i
]]); });
89 function move_to_unnamed(direction
) {
90 move_by_filter(direction
, function(i
) {
91 return !("deleted" in picinfo
[files
[i
]]) &&
92 !("name" in picinfo
[files
[i
]]); });
95 function mark_deleted() {
96 picinfo
[files
[input_index
]].deleted
= 1;
101 function mark_not_deleted() {
102 delete picinfo
[files
[input_index
]].deleted
;
107 function change_exposure(amount
) {
108 if (!endsWith(files
[input_index
], ".NEF")) {
109 say("Exposure adjustment not available");
113 picinfo
[files
[input_index
]].exposure
= exposure
;
116 var display_exposure
= (exposure
/ 4) - 3.5;
117 say((display_exposure
>= 0 ? "+" : "") + display_exposure
);
120 function set_name() {
121 var name_input
= $("#name").hide().get(0);
122 var name
= name_input
.value
;
123 name_input
.value
= "";
124 picinfo
[files
[input_index
]].name
= name
;
126 say("Named " + name
);
130 $("#name").hide().on("keyup", function(e
) { e
.which
== 13 && set_name(); });
131 move_to_nondeleted(1);
134 Mousetrap
.bind('z', toggle_zoom
);
135 Mousetrap
.bind('Z', function() { $("#pic").toggleClass("fit_view"); });
136 Mousetrap
.bind(['n', 'l'], function() { move_to_nondeleted(1); });
137 Mousetrap
.bind(['p', 'h'], function() { move_to_nondeleted(-1); });
138 Mousetrap
.bind(['N', 'L'], function() { move_to_unnamed(1); });
139 Mousetrap
.bind(['P', 'H'], function() { move_to_unnamed(-1); });
140 Mousetrap
.bind(['m n', 'm l'], function() { move(1); });
141 Mousetrap
.bind(['m n', 'm h'], function() { move(-1); });
142 Mousetrap
.bind(['b', 'k'], function() { change_exposure(1); });
143 Mousetrap
.bind(['d', 'j'], function() { change_exposure(-1); });
144 Mousetrap
.bind('x', mark_deleted
);
145 Mousetrap
.bind('X', mark_not_deleted
);
146 Mousetrap
.bind('c', function() { $("#name").show().focus(); return false; });