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.
65 function max_image_size(screen_size)
68 for (i = 0; i < fixed_sizes.length; ++i) {
69 if (screen_size[0] >= fixed_sizes[i][0] && screen_size[1] >= fixed_sizes[i][1]) {
70 return fixed_sizes[i];
76 function pick_image_size(screen_size, image_size)
79 for (i = 0; i < fixed_sizes.length; ++i) {
80 // this is a duplicate of pr0n's resizing code, hope for no floating-point
82 var thumbxres = fixed_sizes[i][0];
83 var thumbyres = fixed_sizes[i][1];
84 var width = image_size[0];
85 var height = image_size[1];
87 if (!(thumbxres >= width && thumbyres >= height)) {
88 var sfh = width / thumbxres;
89 var sfv = height / thumbyres;
97 width = Math.floor(width);
98 height = Math.floor(height);
101 if (screen_size[0] >= width && screen_size[1] >= height) {
102 // be sure _not_ to return a reference
103 return [ fixed_sizes[i][0], fixed_sizes[i][1], width, height ];
109 function display_image(width, height, evt, filename, element_id)
111 var url = "http://" + global_vhost + "/" + evt + "/" + width + "x" + height + "/" + global_infobox + filename;
112 var img = document.getElementById(element_id);
115 img.parentNode.removeChild(img);
118 img = document.createElement("img");
122 if (img.src != url) {
126 var main = document.getElementById("iehack");
127 main.appendChild(img);
132 function display_image_num(num, element_id)
134 var screen_size = find_width();
137 if (global_image_list[num][2] == -1) {
138 // no size information, use our pessimal guess
139 adjusted_size = max_image_size(screen_size);
141 adjusted_size = pick_image_size(screen_size, [ global_image_list[num][2], global_image_list[num][3] ]);
144 var img = display_image(adjusted_size[0], adjusted_size[1], global_image_list[num][0], global_image_list[num][1], element_id);
146 if (element_id == "image") {
147 // we want to shrink the box as much as possible if we know the true
151 document.getElementById('linkbg1').href = global_bookmark_url_base + (num+1);
152 document.getElementById('linkbg2').href = global_bookmark_url_base + (num+1);
153 document.getElementById('linkbg3').href = global_bookmark_url_base + (num+1);
159 function prepare_preload(img, num)
161 // cancel any pending preload
162 var preload = document.getElementById("preload");
163 if (preload !== null) {
164 preload.src = "data:";
165 preload.parentNode.removeChild(preload);
168 // grmf -- IE doesn't fire onload if the image was loaded from cache, so check for
169 // completeness first; should at least be _somewhat_ better
171 display_image_num(num, "preload");
173 img.onload = function() { display_image_num(num, "preload"); };
177 function can_go_next()
179 return (global_image_num < global_image_list.length - 1);
182 function can_go_previous()
184 return (global_image_num > 0);
187 function set_opacity(id, amount)
189 var elem = document.getElementById(id);
190 if (typeof(elem.style.opacity) != 'undefined') { // W3C
191 elem.style.opacity = amount;
192 } else if (typeof(elem.style.mozOpacity) != 'undefined') { // older Mozilla
193 elem.style.mozOpacity = amount;
194 } else if (typeof(elem.style.filter) != 'undefined') { // IE
195 if (elem.style.filter.indexOf("alpha") == -1) {
196 // add an alpha filter if there isn't one already
197 if (elem.style.filter) {
198 elem.style.filter += " ";
200 elem.style.filter = "";
202 elem.style.filter += "alpha(opacity=" + (amount*100.0) + ")";
204 // ugh? this seems to break in color index mode...
205 if (typeof(elem.filters) == 'unknown') {
206 elem.style.filter = "alpha(opacity=" + (amount*100.0) + ")";
208 elem.filters.alpha.opacity = (amount * 100.0);
211 } else { // no alpha support
213 elem.style.visibility = "visible";
214 elem.style.zorder = 1;
216 elem.style.visibility = "hidden";
221 function center_image(num)
223 var screen_size = find_width();
226 if (global_image_list[num][2] == -1) {
227 // no size information, use our pessimal guess
228 var adjusted_size = max_image_size(screen_size);
229 width = adjusted_size[0];
230 height = adjusted_size[1];
232 // use the exact information
233 var adjusted_size = pick_image_size(screen_size, [ global_image_list[num][2], global_image_list[num][3] ]);
234 width = adjusted_size[2];
235 height = adjusted_size[3];
238 // center the image on-screen
239 var main = document.getElementById("main");
240 main.style.position = "absolute";
241 main.style.left = (screen_size[0] - width) / 2 + "px";
242 main.style.top = (screen_size[1] - height) / 2 + "px";
243 main.style.width = width + "px";
244 main.style.height = height + "px";
245 main.style.lineHeight = height + "px";
250 var img = display_image_num(global_image_num, "image");
252 prepare_preload(img, global_image_num + 1);
255 set_opacity("previous", can_go_previous() ? 0.7 : 0.1);
256 set_opacity("next", can_go_next() ? 0.7 : 0.1);
257 set_opacity("close", 0.7);
260 function go_previous()
262 if (!can_go_previous()) {
266 var img = display_image_num(--global_image_num, "image");
267 if (can_go_previous()) {
268 set_opacity("previous", 0.7);
269 prepare_preload(img, global_image_num - 1);
271 set_opacity("previous", 0.1);
273 set_opacity("next", can_go_next() ? 0.7 : 0.1);
278 if (!can_go_next()) {
282 var img = display_image_num(++global_image_num, "image");
284 set_opacity("next", 0.7);
285 prepare_preload(img, global_image_num + 1);
287 set_opacity("next", 0.1);
289 set_opacity("previous", can_go_previous() ? 0.7 : 0.1);
294 window.location = global_return_url;
297 function draw_text(msg)
299 // remove any text we might have left
300 var text = document.getElementById("text");
302 text.parentNode.removeChild(text);
305 text = document.createElement("p");
307 text.style.position = "absolute";
308 text.style.color = "white";
309 text.style.lineHeight = "24px";
310 text.style.font = "24px verdana, arial, sans-serif";
311 text.innerHTML = msg;
313 var main = document.getElementById("main");
314 main.appendChild(text);
316 text.style.left = (main.clientWidth - text.clientWidth) / 2 + "px";
317 text.style.top = (main.clientHeight - text.clientHeight) / 2 + "px";
320 function fade_text(opacity)
322 set_opacity("text", opacity);
328 setTimeout("fade_text(" + opacity + ")", 30);
330 var text = document.getElementById("text");
332 text.parentNode.removeChild(text);
337 function select_image(evt, filename)
343 draw_text("Selecting " + filename + "...");
345 req.open("POST", "http://" + global_vhost + "/select", false);
346 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
347 req.send("mode=single&event=" + evt + "&filename=" + filename);
349 setTimeout("fade_text(0.99)", 30);
352 function key_down(which)
354 if (which == 39) { // right
356 set_opacity("next", 0.99);
358 } else if (which == 37) { // left
359 if (can_go_previous()) {
360 set_opacity("previous", 0.99);
362 } else if (which == 27) { // escape
363 set_opacity("close", 0.99);
367 function key_up(which) {
368 if (which == 39) { // right
370 set_opacity("next", 0.7);
373 } else if (which == 37) { // left
374 if (can_go_previous()) {
375 set_opacity("previous", 0.7);
378 } else if (which == 27) { // escape
379 set_opacity("close", 0.7);
381 } else if (which == 32 && global_select) { // space
382 select_image(global_image_list[global_image_num][0], global_image_list[global_image_num][1]);
386 // enable the horrible horrible IE PNG hack
387 function ie_png_hack()
389 var vstr = navigator.appVersion.split("MSIE");
390 var v = parseFloat(vstr[1]);
391 if (v >= 5.5 && v < 7.0 && document.body.filters) {
392 var next = document.getElementById("next");
393 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); }\" />";
395 var previous = document.getElementById("previous");
396 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); }\" />";
398 var close = document.getElementById("close");
399 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);\" />";