]>
git.scottworley.com Git - picsort/blob - picsorter.js
91febfa4ef73ad0fa655bb59c16573d0488b9128
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
];
44 $pic
.on("load", function() {
45 $pic
.removeClass("rot90 rot180 rot270");
46 if ("rotate" in picinfo
[files
[input_index
]]) {
47 $pic
.addClass("rot" + picinfo
[files
[input_index
]].rotate
);
50 $pic
.attr("src", display_filename
);
53 function say(message
) {
54 $("#message").text(message
).removeClass("fade");
55 setTimeout(function() { $("#message").addClass("fade"); }, 1);
58 function toggle_zoom() {
67 function move_by_filter(direction
, filter
) {
68 // Keep moving in direction until filter is satisfied
69 var new_index
= input_index
;
71 var next
= new_index
+ direction
;
76 if (next
>= files
.length
) {
81 if (filter(new_index
)) {
85 input_index
= new_index
;
86 say(input_index
+ " " + (picinfo
[files
[input_index
]].name
|| ""));
89 function move(direction
) {
90 move_by_filter(direction
, function() { return true; });
92 function move_to_nondeleted(direction
) {
93 move_by_filter(direction
, function(i
) {
94 return !("deleted" in picinfo
[files
[i
]]); });
96 function move_to_unnamed(direction
) {
97 move_by_filter(direction
, function(i
) {
98 return !("deleted" in picinfo
[files
[i
]]) &&
99 !("name" in picinfo
[files
[i
]]); });
102 function mark_deleted() {
103 picinfo
[files
[input_index
]].deleted
= 1;
108 function mark_not_deleted() {
109 delete picinfo
[files
[input_index
]].deleted
;
114 function change_exposure(amount
) {
115 if (!endsWith(files
[input_index
], ".NEF")) {
116 say("Exposure adjustment not available");
120 picinfo
[files
[input_index
]].exposure
= exposure
;
123 var display_exposure
= (exposure
/ 4) - 3.5;
124 say((display_exposure
>= 0 ? "+" : "") + display_exposure
);
128 var rotation
= picinfo
[files
[input_index
]].rotate
|| 0;
129 rotation
= (rotation
+ 90) % 360;
130 if (rotation
> 1e-5) {
131 picinfo
[files
[input_index
]].rotate
= rotation
;
133 delete picinfo
[files
[input_index
]].rotate
;
139 function set_name() {
140 var name_input
= $("#name").hide().get(0);
141 var name
= name_input
.value
;
142 name_input
.value
= "";
143 picinfo
[files
[input_index
]].name
= name
;
145 say("Named " + name
);
149 $("#name").hide().on("keyup", function(e
) { e
.which
== 13 && set_name(); });
150 move_to_nondeleted(1);
153 Mousetrap
.bind('z', toggle_zoom
);
154 Mousetrap
.bind('Z', function() { $("#pic").toggleClass("fit_view"); });
155 Mousetrap
.bind(['n', 'l'], function() { move_to_nondeleted(1); });
156 Mousetrap
.bind(['p', 'h'], function() { move_to_nondeleted(-1); });
157 Mousetrap
.bind(['N', 'L'], function() { move_to_unnamed(1); });
158 Mousetrap
.bind(['P', 'H'], function() { move_to_unnamed(-1); });
159 Mousetrap
.bind(['m n', 'm l'], function() { move(1); });
160 Mousetrap
.bind(['m n', 'm h'], function() { move(-1); });
161 Mousetrap
.bind(['b', 'k'], function() { change_exposure(1); });
162 Mousetrap
.bind(['d', 'j'], function() { change_exposure(-1); });
163 Mousetrap
.bind('x', mark_deleted
);
164 Mousetrap
.bind('X', mark_not_deleted
);
165 Mousetrap
.bind('r', rotate
);
166 Mousetrap
.bind('c', function() { $("#name").show().focus(); return false; });
167 Mousetrap
.bind('%', function() { say((100 * input_index
/ files
.length
).toFixed(2) + "%"); });