7 if (window.XMLHttpRequest) {
10 req = new XMLHttpRequest();
14 } else if (window.ActiveXObject) {
17 req = new ActiveXObject("Msxml2.XMLHTTP");
20 req = new ActiveXObject("Microsoft.XMLHTTP");
30 if (typeof(window.innerWidth) == 'number') {
32 return [window.innerWidth, window.innerHeight];
33 } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
34 // IE 6+ in 'standards compliant mode'
35 return [document.documentElement.clientWidth, document.documentElement.clientHeight];
36 } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
38 return [document.body.clientWidth, document.body.clientHeight];
43 function parse_image_num(default_value) {
44 var num = parseInt(window.location.hash.substr(1));
45 if (num >= 1 && num <= global_image_list.length) { // and then num != NaN
53 * pr0n can resize to any size we'd like, but we're much more likely
54 * to have this set of fixed-resolution screens cached, so to increase
55 * performance, we round down to the closest fit and use that. This
56 * function is a pessimal estimate of what thumbnail size we can _always_
57 * fit on the screen -- it's right if and only if all images are 4:3
58 * (and landscape). If individual size information is available, use
59 * pick_image_size, below.
77 function max_image_size(screen_size)
80 for (i = 0; i < fixed_sizes.length; ++i) {
81 if (screen_size[0] >= fixed_sizes[i][0] && screen_size[1] >= fixed_sizes[i][1]) {
82 return fixed_sizes[i];
88 function pick_image_size(screen_size, image_size)
91 for (i = 0; i < fixed_sizes.length; ++i) {
92 // this is a duplicate of pr0n's resizing code, hope for no floating-point
94 var thumbxres = fixed_sizes[i][0];
95 var thumbyres = fixed_sizes[i][1];
96 var width = image_size[0];
97 var height = image_size[1];
99 if (!(thumbxres >= width && thumbyres >= height)) {
100 var sfh = width / thumbxres;
101 var sfv = height / thumbyres;
109 width = Math.floor(width);
110 height = Math.floor(height);
113 if (screen_size[0] >= width && screen_size[1] >= height) {
114 // be sure _not_ to return a reference
115 return [ fixed_sizes[i][0], fixed_sizes[i][1], width, height ];
121 function replace_image_element(url, element_id, parent_node)
123 var img = document.getElementById(element_id);
126 img.parentNode.removeChild(img);
129 img = document.createElement("img");
133 if (img.src != url) {
137 parent_node.appendChild(img);
141 function display_image(width, height, evt, filename, element_id)
143 var url = "http://" + global_vhost + "/" + evt + "/" + width + "x" + height + "/nobox/" + filename;
144 var main = document.getElementById("iehack");
145 var img = replace_image_element(url, element_id, main);
147 if (global_infobox != 'nobox') {
148 var url = "http://" + global_vhost + "/" + evt + "/" + width + "x" + height + "/box/" + filename;
149 var boximg = replace_image_element(url, element_id + "_box", main);
151 boximg.style.position = "absolute";
152 boximg.style.left = "0px";
153 boximg.style.bottom = "-1px";
159 function display_image_num(num, element_id)
161 var screen_size = find_width();
164 if (global_image_list[num][2] == -1) {
165 // no size information, use our pessimal guess
166 adjusted_size = max_image_size(screen_size);
168 adjusted_size = pick_image_size(screen_size, [ global_image_list[num][2], global_image_list[num][3] ]);
171 var img = display_image(adjusted_size[0], adjusted_size[1], global_image_list[num][0], global_image_list[num][1], element_id);
173 if (element_id == "image") {
174 // we want to shrink the box as much as possible if we know the true
178 // replace the anchor part (if any) with the image number
179 var baseurl = (window.location.toString().split("#"))[0];
180 window.location = baseurl + "#" + (num+1);
186 function prepare_preload(img, num)
188 // cancel any pending preload
189 var preload = document.getElementById("preload");
190 if (preload !== null) {
191 preload.src = "data:";
192 preload.parentNode.removeChild(preload);
195 var preload_box = document.getElementById("preload_box");
196 if (preload_box !== null) {
197 preload_box.src = "data:";
198 preload_box.parentNode.removeChild(preload_box);
201 // grmf -- IE doesn't fire onload if the image was loaded from cache, so check for
202 // completeness first; should at least be _somewhat_ better
204 display_image_num(num, "preload");
206 img.onload = function() { display_image_num(num, "preload"); };
210 function can_go_next()
212 return (global_image_num < global_image_list.length - 1);
215 function can_go_previous()
217 return (global_image_num > 0);
220 function set_opacity(id, amount)
222 var elem = document.getElementById(id);
223 if (typeof(elem.style.opacity) != 'undefined') { // W3C
224 elem.style.opacity = amount;
225 } else if (typeof(elem.style.mozOpacity) != 'undefined') { // older Mozilla
226 elem.style.mozOpacity = amount;
227 } else if (typeof(elem.style.filter) != 'undefined') { // IE
228 if (elem.style.filter.indexOf("alpha") == -1) {
229 // add an alpha filter if there isn't one already
230 if (elem.style.filter) {
231 elem.style.filter += " ";
233 elem.style.filter = "";
235 elem.style.filter += "alpha(opacity=" + (amount*100.0) + ")";
237 // ugh? this seems to break in color index mode...
238 if (typeof(elem.filters) == 'unknown') {
239 elem.style.filter = "alpha(opacity=" + (amount*100.0) + ")";
241 elem.filters.alpha.opacity = (amount * 100.0);
244 } else { // no alpha support
246 elem.style.visibility = "visible";
247 elem.style.zorder = 1;
249 elem.style.visibility = "hidden";
254 function center_image(num)
256 var screen_size = find_width();
259 if (global_image_list[num][2] == -1) {
260 // no size information, use our pessimal guess
261 var adjusted_size = max_image_size(screen_size);
262 width = adjusted_size[0];
263 height = adjusted_size[1];
265 // use the exact information
266 var adjusted_size = pick_image_size(screen_size, [ global_image_list[num][2], global_image_list[num][3] ]);
267 width = adjusted_size[2];
268 height = adjusted_size[3];
271 // center the image on-screen
272 var main = document.getElementById("main");
273 main.style.position = "absolute";
274 main.style.left = (screen_size[0] - width) / 2 + "px";
275 main.style.top = (screen_size[1] - height) / 2 + "px";
276 main.style.width = width + "px";
277 main.style.height = height + "px";
278 main.style.lineHeight = height + "px";
283 var img = display_image_num(global_image_num, "image");
285 prepare_preload(img, global_image_num + 1);
288 set_opacity("previous", can_go_previous() ? 0.7 : 0.1);
289 set_opacity("next", can_go_next() ? 0.7 : 0.1);
290 set_opacity("close", 0.7);
293 function go_previous()
295 if (!can_go_previous()) {
299 var img = display_image_num(--global_image_num, "image");
300 if (can_go_previous()) {
301 set_opacity("previous", 0.7);
302 prepare_preload(img, global_image_num - 1);
304 set_opacity("previous", 0.1);
306 set_opacity("next", can_go_next() ? 0.7 : 0.1);
311 if (!can_go_next()) {
315 var img = display_image_num(++global_image_num, "image");
317 set_opacity("next", 0.7);
318 prepare_preload(img, global_image_num + 1);
320 set_opacity("next", 0.1);
322 set_opacity("previous", can_go_previous() ? 0.7 : 0.1);
327 window.location = global_return_url;
330 function draw_text(msg)
332 // remove any text we might have left
333 var text = document.getElementById("text");
335 text.parentNode.removeChild(text);
338 text = document.createElement("p");
340 text.style.position = "absolute";
341 text.style.color = "white";
342 text.style.lineHeight = "24px";
343 text.style.font = "24px verdana, arial, sans-serif";
344 text.innerHTML = msg;
346 var main = document.getElementById("main");
347 main.appendChild(text);
349 text.style.left = (main.clientWidth - text.clientWidth) / 2 + "px";
350 text.style.top = (main.clientHeight - text.clientHeight) / 2 + "px";
353 function fade_text(opacity)
355 set_opacity("text", opacity);
361 setTimeout("fade_text(" + opacity + ")", 30);
363 var text = document.getElementById("text");
365 text.parentNode.removeChild(text);
370 function select_image(evt, filename)
376 draw_text("Selecting " + filename + "...");
378 req.open("POST", "http://" + global_vhost + "/select", false);
379 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
380 req.send("mode=single&event=" + evt + "&filename=" + filename);
382 setTimeout("fade_text(0.99)", 30);
385 function key_down(which)
387 if (which == 39) { // right
389 set_opacity("next", 0.99);
391 } else if (which == 37) { // left
392 if (can_go_previous()) {
393 set_opacity("previous", 0.99);
395 } else if (which == 27) { // escape
396 set_opacity("close", 0.99);
398 check_for_hash_change();
402 function key_up(which) {
403 if (which == 39) { // right
405 set_opacity("next", 0.7);
408 } else if (which == 37) { // left
409 if (can_go_previous()) {
410 set_opacity("previous", 0.7);
413 } else if (which == 27) { // escape
414 set_opacity("close", 0.7);
416 } else if (which == 32 && global_select) { // space
417 select_image(global_image_list[global_image_num][0], global_image_list[global_image_num][1]);
419 check_for_hash_change();
423 // enable the horrible horrible IE PNG hack
424 function ie_png_hack()
426 var vstr = navigator.appVersion.split("MSIE");
427 var v = parseFloat(vstr[1]);
428 if (v >= 5.5 && v < 7.0 && document.body.filters) {
429 var next = document.getElementById("next");
430 next.outerHTML = "<span id=\"next\" style=\"display: inline-block; position: absolute; bottom: 0px; right: 0px; width: 50px; height: 50px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + next.src + "')\" onmousedown=\"if (can_go_next()) set_opacity('next', 1.0)\" onmouseup=\"if (can_go_next()) { set_opacity('next', 0.7); go_next(); }\" onmouseout=\"if (can_go_next()) { set_opacity('next', 0.7); }\" />";
432 var previous = document.getElementById("previous");
433 previous.outerHTML = "<span id=\"previous\" style=\"display: inline-block; position: absolute; bottom: 0px; right: 0px; width: 50px; height: 50px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + previous.src + "')\" onmousedown=\"if (can_go_previous()) set_opacity('previous', 1.0)\" onmouseup=\"if (can_go_previous()) { set_opacity('previous', 0.7); go_previous(); }\" onmouseout=\"if (can_go_previous()) { set_opacity('previous', 0.7); }\" />";
435 var close = document.getElementById("close");
436 close.outerHTML = "<span id=\"close\" style=\"display: inline-block; position: absolute; top: 0px; right: 0px; width: 50px; height: 50px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + close.src + "')\" onmousedown=\"set_opacity('close', 1.0)\" onmouseup=\"set_opacity('close', 0.7); do_close();\" onmouseout=\"set_opacity('close', 0.7);\" />";
440 function check_for_hash_change() {
441 var num = parseInt(window.location.hash.substr(1));
442 if (num >= 1 && num <= global_image_list.length) { // and then num != NaN
443 if (--num != global_image_num) {
444 global_image_num = num;