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.
48 function reduce_to_fixed_width(size)
62 for (i = 0; i < fixed_sizes.length; ++i) {
63 if (size[0] >= fixed_sizes[i][0] && size[1] >= fixed_sizes[i][1]) {
64 return fixed_sizes[i];
70 function display_image(width, height, evt, filename, element_id)
72 var url = "http://" + global_vhost + "/" + evt + "/" + width + "x" + height + "/" + global_infobox + filename;
73 var img = document.getElementById(element_id);
76 img.parentNode.removeChild(img);
79 img = document.createElement("img");
87 var main = document.getElementById("iehack");
88 main.appendChild(img);
93 function prepare_preload(img, width, height, evt, filename)
95 // cancel any pending preload
96 var preload = document.getElementById("preload");
97 if (preload !== null) {
98 preload.src = "data:";
99 preload.parentNode.removeChild(preload);
102 // grmf -- IE doesn't fire onload if the image was loaded from cache, so check for
103 // completeness first; should at least be _somewhat_ better
105 display_image(width, height, evt, filename, "preload");
107 img.onload = function() { display_image(width, height, evt, filename, "preload"); };
111 function can_go_next()
113 return (global_image_num < global_image_list.length - 1);
116 function can_go_previous()
118 return (global_image_num > 0);
121 function set_opacity(id, amount)
123 var elem = document.getElementById(id);
124 if (typeof(elem.style.opacity) != 'undefined') { // W3C
125 elem.style.opacity = amount;
126 } else if (typeof(elem.style.mozOpacity) != 'undefined') { // older Mozilla
127 elem.style.mozOpacity = amount;
128 } else if (typeof(elem.style.filter) != 'undefined') { // IE
129 if (elem.style.filter.indexOf("alpha") == -1) {
130 // add an alpha filter if there isn't one already
131 if (elem.style.filter) {
132 elem.style.filter += " ";
134 elem.style.filter = "";
136 elem.style.filter += "alpha(opacity=" + (amount*100.0) + ")";
138 // ugh? this seems to break in color index mode...
139 if (typeof(elem.filters) == 'unknown') {
140 elem.style.filter = "alpha(opacity=" + (amount*100.0) + ")";
142 elem.filters.alpha.opacity = (amount * 100.0);
145 } else { // no alpha support
147 elem.style.visibility = "visible";
148 elem.style.zorder = 1;
150 elem.style.visibility = "hidden";
157 var size = find_width();
158 var adjusted_size = reduce_to_fixed_width(size);
160 var img = display_image(adjusted_size[0], adjusted_size[1], global_image_list[global_image_num][0], global_image_list[global_image_num][1], "image");
162 prepare_preload(img, adjusted_size[0], adjusted_size[1], global_image_list[global_image_num + 1][0], global_image_list[global_image_num + 1]);
165 // center the image on-screen
166 var main = document.getElementById("main");
167 main.style.position = "absolute";
168 main.style.left = (size[0] - adjusted_size[0]) / 2 + "px";
169 main.style.top = (size[1] - adjusted_size[1]) / 2 + "px";
170 main.style.width = adjusted_size[0] + "px";
171 main.style.height = adjusted_size[1] + "px";
172 main.style.lineHeight = adjusted_size[1] + "px";
174 set_opacity("previous", can_go_previous() ? 0.7 : 0.1);
175 set_opacity("next", can_go_next() ? 0.7 : 0.1);
176 set_opacity("close", 0.7);
179 function go_previous()
181 if (!can_go_previous()) {
187 var adjusted_size = reduce_to_fixed_width(find_width());
189 var img = display_image(adjusted_size[0], adjusted_size[1], global_image_list[global_image_num][0], global_image_list[global_image_num][1], "image");
190 if (can_go_previous()) {
191 set_opacity("previous", 0.7);
192 prepare_preload(img, adjusted_size[0], adjusted_size[1], global_image_list[global_image_num - 1][0], global_image_list[global_image_num - 1][1]);
194 set_opacity("previous", 0.1);
196 set_opacity("next", can_go_next() ? 0.7 : 0.1);
201 if (!can_go_next()) {
207 var adjusted_size = reduce_to_fixed_width(find_width());
209 var img = display_image(adjusted_size[0], adjusted_size[1], global_image_list[global_image_num][0], global_image_list[global_image_num][1], "image");
211 set_opacity("next", 0.7);
212 prepare_preload(img, adjusted_size[0], adjusted_size[1], global_image_list[global_image_num + 1][0], global_image_list[global_image_num + 1][1]);
214 set_opacity("next", 0.1);
216 set_opacity("previous", can_go_previous() ? 0.7 : 0.1);
221 window.location = global_return_url;
224 function draw_text(msg)
226 // remove any text we might have left
227 var text = document.getElementById("text");
229 text.parentNode.removeChild(text);
232 text = document.createElement("p");
234 text.style.position = "absolute";
235 text.style.color = "white";
236 text.style.lineHeight = "24px";
237 text.style.font = "24px verdana, arial, sans-serif";
238 text.innerHTML = msg;
240 var main = document.getElementById("main");
241 main.appendChild(text);
243 text.style.left = (main.clientWidth - text.clientWidth) / 2 + "px";
244 text.style.top = (main.clientHeight - text.clientHeight) / 2 + "px";
247 function fade_text(opacity)
249 set_opacity("text", opacity);
255 setTimeout("fade_text(" + opacity + ")", 30);
257 var text = document.getElementById("text");
259 text.parentNode.removeChild(text);
264 function select_image(evt, filename)
270 draw_text("Selecting " + filename + "...");
272 req.open("POST", "http://" + global_vhost + "/select", false);
273 req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
274 req.send("mode=single&event=" + evt + "&filename=" + filename);
276 setTimeout("fade_text(0.99)", 30);
279 function key_down(which)
281 if (which == 39) { // right
283 set_opacity("next", 0.99);
285 } else if (which == 37) { // left
286 if (can_go_previous()) {
287 set_opacity("previous", 0.99);
289 } else if (which == 27) { // escape
290 set_opacity("close", 0.99);
294 function key_up(which) {
295 if (which == 39) { // right
297 set_opacity("next", 0.7);
300 } else if (which == 37) { // left
301 if (can_go_previous()) {
302 set_opacity("previous", 0.7);
305 } else if (which == 27) { // escape
306 set_opacity("close", 0.7);
308 } else if (which == 32 && global_select) { // space
309 select_image(global_image_list[global_image_num][0], global_image_list[global_image_num][1]);
313 // enable the horrible horrible IE PNG hack
314 function ie_png_hack()
316 var vstr = navigator.appVersion.split("MSIE");
317 var v = parseFloat(vstr[1]);
318 if (v >= 5.5 && v < 7.0 && document.body.filters) {
319 var next = document.getElementById("next");
320 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); }\" />";
322 var previous = document.getElementById("previous");
323 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); }\" />";
325 var close = document.getElementById("close");
326 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);\" />";