]>
git.scottworley.com Git - picsort/blob - picsorter.js
24cc8938e054363048ab1159ca805662c86a70eb
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
.attr("src", display_filename
);
45 $pic
.removeClass("rot90 rot180 rot270");
46 if ("rotate" in picinfo
[files
[input_index
]]) {
47 $pic
.addClass("rot" + picinfo
[files
[input_index
]].rotate
);
51 function say(message
) {
52 $("#message").text(message
).removeClass("fade");
53 setTimeout(function() { $("#message").addClass("fade"); }, 1);
56 function toggle_zoom() {
65 function move_by_filter(direction
, filter
) {
66 // Keep moving in direction until filter is satisfied
67 var new_index
= input_index
;
69 var next
= new_index
+ direction
;
74 if (next
>= files
.length
) {
79 if (filter(new_index
)) {
83 input_index
= new_index
;
84 say(input_index
+ " " + (picinfo
[files
[input_index
]].name
|| ""));
87 function move(direction
) {
88 move_by_filter(direction
, function() { return true; });
90 function move_to_nondeleted(direction
) {
91 move_by_filter(direction
, function(i
) {
92 return !("deleted" in picinfo
[files
[i
]]); });
94 function move_to_unnamed(direction
) {
95 move_by_filter(direction
, function(i
) {
96 return !("deleted" in picinfo
[files
[i
]]) &&
97 !("name" in picinfo
[files
[i
]]); });
100 function mark_deleted() {
101 picinfo
[files
[input_index
]].deleted
= 1;
106 function mark_not_deleted() {
107 delete picinfo
[files
[input_index
]].deleted
;
112 function change_exposure(amount
) {
113 if (!endsWith(files
[input_index
], ".NEF")) {
114 say("Exposure adjustment not available");
118 picinfo
[files
[input_index
]].exposure
= exposure
;
121 var display_exposure
= (exposure
/ 4) - 3.5;
122 say((display_exposure
>= 0 ? "+" : "") + display_exposure
);
126 var rotation
= picinfo
[files
[input_index
]].rotate
|| 0;
127 rotation
= (rotation
+ 90) % 360;
128 if (rotation
> 1e-5) {
129 picinfo
[files
[input_index
]].rotate
= rotation
;
131 delete picinfo
[files
[input_index
]].rotate
;
137 function set_name() {
138 var name_input
= $("#name").hide().get(0);
139 var name
= name_input
.value
;
140 name_input
.value
= "";
141 picinfo
[files
[input_index
]].name
= name
;
143 say("Named " + name
);
147 $("#name").hide().on("keyup", function(e
) { e
.which
== 13 && set_name(); });
148 move_to_nondeleted(1);
151 Mousetrap
.bind('z', toggle_zoom
);
152 Mousetrap
.bind('Z', function() { $("#pic").toggleClass("fit_view"); });
153 Mousetrap
.bind(['n', 'l'], function() { move_to_nondeleted(1); });
154 Mousetrap
.bind(['p', 'h'], function() { move_to_nondeleted(-1); });
155 Mousetrap
.bind(['N', 'L'], function() { move_to_unnamed(1); });
156 Mousetrap
.bind(['P', 'H'], function() { move_to_unnamed(-1); });
157 Mousetrap
.bind(['m n', 'm l'], function() { move(1); });
158 Mousetrap
.bind(['m n', 'm h'], function() { move(-1); });
159 Mousetrap
.bind(['b', 'k'], function() { change_exposure(1); });
160 Mousetrap
.bind(['d', 'j'], function() { change_exposure(-1); });
161 Mousetrap
.bind('x', mark_deleted
);
162 Mousetrap
.bind('X', mark_not_deleted
);
163 Mousetrap
.bind('r', rotate
);
164 Mousetrap
.bind('c', function() { $("#name").show().focus(); return false; });