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];
44 * pr0n can resize to any size we'd like, but we're much more likely
45 * to have this set of fixed-resolution screens cached, so to increase
46 * performance, we round down to the closest fit and use that. This
47 * function is a pessimal estimate of what thumbnail size we can _always_
48 * fit on the screen -- it's right if and only if all images are 4:3
49 * (and landscape). If individual size information is available, use
50 * pick_image_size, below.
68 function max_image_size(screen_size)
71 for (i = 0; i < fixed_sizes.length; ++i) {
72 if (screen_size[0] >= fixed_sizes[i][0] && screen_size[1] >= fixed_sizes[i][1]) {
73 return fixed_sizes[i];
79 function pick_image_size(screen_size, image_size)
82 for (i = 0; i < fixed_sizes.length; ++i) {
83 // this is a duplicate of pr0n's resizing code, hope for no floating-point
85 var thumbxres = fixed_sizes[i][0];
86 var thumbyres = fixed_sizes[i][1];
87 var width = image_size[0];
88 var height = image_size[1];
90 if (!(thumbxres >= width && thumbyres >= height)) {
91 var sfh = width / thumbxres;
92 var sfv = height / thumbyres;
100 width = Math.floor(width);
101 height = Math.floor(height);
104 if (screen_size[0] >= width && screen_size[1] >= height) {
105 // be sure _not_ to return a reference
106 return [ fixed_sizes[i][0], fixed_sizes[i][1], width, height ];
112 function replace_image_element(url, element_id, parent_node)
114 var img = document.getElementById(element_id);
117 img.parentNode.removeChild(img);
120 img = document.createElement("img");
124 if (img.src != url) {
128 parent_node.appendChild(img);
132 function display_image(width, height, evt, filename, element_id)
134 var url = "http://" + global_vhost + "/" + evt + "/" + width + "x" + height + "/nobox/" + filename;
135 var main = document.getElementById("iehack");
136 var img = replace_image_element(url, element_id, main);
137 img.style.position = "absolute";
138 img.style.left = "0px";
139 img.style.top = "0px";
141 if (global_infobox != 'nobox/') {
142 var url = "http://" + global_vhost + "/" + evt + "/" + width + "x" + height + "/box/" + filename;
143 var boximg = replace_image_element(url, element_id + "_box", main);
145 boximg.style.position = "absolute";
146 boximg.style.left = "0px";
147 boximg.style.bottom = "-1px";
153 function display_image_num(num, element_id)
155 var screen_size = find_width();
158 if (global_image_list[num][2] == -1) {
159 // no size information, use our pessimal guess
160 adjusted_size = max_image_size(screen_size);
162 adjusted_size = pick_image_size(screen_size, [ global_image_list[num][2], global_image_list[num][3] ]);
165 var img = display_image(adjusted_size[0], adjusted_size[1], global_image_list[num][0], global_image_list[num][1], element_id);
167 if (element_id == "image") {
168 // we want to shrink the box as much as possible if we know the true
172 // replace the anchor part (if any) with the image number
173 window.location.hash = "#" + (num+1);
179 function prepare_preload(img, num)
181 // cancel any pending preload
182 var preload = document.getElementById("preload");
183 if (preload !== null) {
184 preload.src = "data:";
185 preload.parentNode.removeChild(preload);
188 var preload_box = document.getElementById("preload_box");
189 if (preload_box !== null) {
190 preload_box.src = "data:";
191 preload_box.parentNode.removeChild(preload_box);
194 // grmf -- IE doesn't fire onload if the image was loaded from cache, so check for
195 // completeness first; should at least be _somewhat_ better
197 display_image_num(num, "preload");
199 img.onload = function() { display_image_num(num, "preload"); };
203 function can_go_next()
205 return (global_image_num < global_image_list.length - 1);
208 function can_go_previous()
210 return (global_image_num > 0);
213 function set_opacity(id, amount)
215 var elem = document.getElementById(id);
216 if (typeof(elem.style.opacity) != 'undefined') { // W3C
217 elem.style.opacity = amount;
218 } else if (typeof(elem.style.mozOpacity) != 'undefined') { // older Mozilla
219 elem.style.mozOpacity = amount;
220 } else if (typeof(elem.style.filter) != 'undefined') { // IE
221 if (elem.style.filter.indexOf("alpha") == -1) {
222 // add an alpha filter if there isn't one already
223 if (elem.style.filter) {
224 elem.style.filter += " ";
226 elem.style.filter = "";
228 elem.style.filter += "alpha(opacity=" + (amount*100.0) + ")";
230 // ugh? this seems to break in color index mode...
231 if (typeof(elem.filters) == 'unknown') {
232 elem.style.filter = "alpha(opacity=" + (amount*100.0) + ")";
234 elem.filters.alpha.opacity = (amount * 100.0);
237 } else { // no alpha support
239 elem.style.visibility = "visible";
240 elem.style.zorder = 1;
242 elem.style.visibility = "hidden";
247 function center_image(num)
249 var screen_size = find_width();
252 if (global_image_list[num][2] == -1) {
253 // no size information, use our pessimal guess
254 var adjusted_size = max_image_size(screen_size);
255 width = adjusted_size[0];
256 height = adjusted_size[1];
258 // use the exact information
259 var adjusted_size = pick_image_size(screen_size, [ global_image_list[num][2], global_image_list[num][3] ]);
260 width = adjusted_size[2];
261 height = adjusted_size[3];
264 // center the image on-screen
265 var main = document.getElementById("main");
266 main.style.position = "absolute";
267 main.style.left = (screen_size[0] - width) / 2 + "px";
268 main.style.top = (screen_size[1] - height) / 2 + "px";
269 main.style.width = width + "px";
270 main.style.height = height + "px";
271 main.style.lineHeight = height + "px";
276 var img = display_image_num(global_image_num, "image");
278 prepare_preload(img, global_image_num + 1);
281 set_opacity("previous", can_go_previous() ? 0.7 : 0.1);
282 set_opacity("next", can_go_next() ? 0.7 : 0.1);
283 set_opacity("close", 0.7);
286 function go_previous()
288 if (!can_go_previous()) {
292 var img = display_image_num(--global_image_num, "image");
293 if (can_go_previous()) {
294 set_opacity("previous", 0.7);
295 prepare_preload(img, global_image_num - 1);
297 set_opacity("previous", 0.1);
299 set_opacity("next", can_go_next() ? 0.7 : 0.1);
304 if (!can_go_next()) {
308 var img = display_image_num(++global_image_num, "image");
310 set_opacity("next", 0.7);
311 prepare_preload(img, global_image_num + 1);
313 set_opacity("next", 0.1);
315 set_opacity("previous", can_go_previous() ? 0.7 : 0.1);
320 window.location = global_return_url;
323 function draw_text(msg)
325 // remove any text we might have left
326 var text = document.getElementById("text");
328 text.parentNode.removeChild(text);
331 text = document.createElement("p");
333 text.style.position = "absolute";
334 text.style.color = "white";
335 text.style.lineHeight = "24px";
336 text.style.font = "24px verdana, arial, sans-serif";
337 text.innerHTML = msg;
339 var main = document.getElementById("main");
340 main.appendChild(text);
342 text.style.left = (main.clientWidth - text.clientWidth) / 2 + "px";
343 text.style.top = (main.clientHeight - text.clientHeight) / 2 + "px";
346 function fade_text(opacity)
348 set_opacity("text", opacity);
354 setTimeout("fade_text(" + opacity + ")", 30);
356 var text = document.getElementById("text");
358 text.parentNode.removeChild(text);
363 function select_image(evt, filename)
369 draw_text("Selecting " + filename + "...");
371 req.open("POST", "http://" + global_vhost + "/select", false);
372 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
373 req.send("mode=single&event=" + evt + "&filename=" + filename);
375 setTimeout("fade_text(0.99)", 30);
378 function key_down(which)
380 if (which == 39) { // right
382 set_opacity("next", 0.99);
384 } else if (which == 37) { // left
385 if (can_go_previous()) {
386 set_opacity("previous", 0.99);
388 } else if (which == 27) { // escape
389 set_opacity("close", 0.99);
391 check_for_hash_change();
395 function key_up(which) {
396 if (which == 39) { // right
398 set_opacity("next", 0.7);
401 } else if (which == 37) { // left
402 if (can_go_previous()) {
403 set_opacity("previous", 0.7);
406 } else if (which == 27) { // escape
407 set_opacity("close", 0.7);
409 } else if (which == 32 && global_select) { // space
410 select_image(global_image_list[global_image_num][0], global_image_list[global_image_num][1]);
412 check_for_hash_change();
416 // enable the horrible horrible IE PNG hack
417 function ie_png_hack()
419 var vstr = navigator.appVersion.split("MSIE");
420 var v = parseFloat(vstr[1]);
421 if (v >= 5.5 && v < 7.0 && document.body.filters) {
422 var next = document.getElementById("next");
423 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); }\" />";
425 var previous = document.getElementById("previous");
426 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); }\" />";
428 var close = document.getElementById("close");
429 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);\" />";
433 function parse_image_num(default_value) {
434 var num = parseInt(window.location.hash.substr(1));
435 if (num >= 1 && num <= global_image_list.length) { // and then num != NaN
438 return default_value;
442 function check_for_hash_change() {
443 var num = parse_image_num(-1);
444 if (num != -1 && num != global_image_num) {
445 global_image_num = num;