X-Git-Url: https://git.sesse.net/?p=pr0n;a=blobdiff_plain;f=files%2Fpr0n-fullscreen.js;h=181a82cb1e0745bde78677c7c02ca5ab16b6c74f;hp=468f249c0c6c780b30c87eed132d5923f8ec8968;hb=8acd90a2a1a6a0065c2fb753f7eb326ac9781107;hpb=3f3629cdf0838f8ee48af115918101de21c4d99c diff --git a/files/pr0n-fullscreen.js b/files/pr0n-fullscreen.js index 468f249..181a82c 100644 --- a/files/pr0n-fullscreen.js +++ b/files/pr0n-fullscreen.js @@ -1,3 +1,30 @@ +var req; + +function init_ajax() +{ + req = false; + + if (window.XMLHttpRequest) { + // Mozilla/Safari + try { + req = new XMLHttpRequest(); + } catch(e) { + req = false; + } + } else if (window.ActiveXObject) { + // IE/Windows + try { + req = new ActiveXObject("Msxml2.XMLHTTP"); + } catch(e) { + try { + req = new ActiveXObject("Microsoft.XMLHTTP"); + } catch(e) { + req = false; + } + } + } +} + function find_width() { if (typeof(window.innerWidth) == 'number') { @@ -43,7 +70,7 @@ function display_image(width, height, evt, filename, element_id) var url = "http://" + global_vhost + "/" + evt + "/" + width + "x" + height + "/" + filename; var img = document.getElementById(element_id); if (img != null) { - img.src = ""; + img.src = "data:"; img.parentNode.removeChild(img); } @@ -55,7 +82,7 @@ function display_image(width, height, evt, filename, element_id) img.src = url; } - var main = document.getElementById("main"); + var main = document.getElementById("iehack"); main.appendChild(img); return img; @@ -66,15 +93,17 @@ function prepare_preload(img, width, height, evt, filename) // cancel any pending preload var preload = document.getElementById("preload"); if (preload != null) { - preload.src = ""; + preload.src = "data:"; preload.parentNode.removeChild(preload); } - - if (document.all) { // IE-specific - img.onload = "display_image(" + width + "," + height + ",\"" + evt + "\",\"" + filename + "\",\"preload\");"; + + // grmf -- IE doesn't fire onload if the image was loaded from cache, so check for + // completeness first; should at least be _somewhat_ better + if (img.complete) { + display_image(width, height, evt, filename, "preload"); } else { - img.onload = function() { display_image(width, height, evt, filename, "preload"); } - } + img.onload = function() { display_image(width, height, evt, filename, "preload"); }; + } } function relayout() @@ -117,8 +146,13 @@ function set_opacity(id, amount) elem.style.filter = ""; } elem.style.filter += "alpha(opacity=" + (amount*100.0) + ")"; - } else { - elem.filters.alpha.opacity = (amount * 100.0); + } else { + // ugh? this seems to break in color index mode... + if (typeof(elem.filters) == 'unknown') { + elem.style.filter = "alpha(opacity=" + (amount*100.0) + ")"; + } else { + elem.filters.alpha.opacity = (amount * 100.0); + } } } else { // no alpha support if (amount > 0.5) { @@ -207,6 +241,38 @@ function key_up(which) { } else if (which == 27) { // escape set_opacity("close", 0.7); do_close(); + } else if (which == 32 && global_select) { // space + select_image(global_image_list[global_image_num]); + } +} + +function select_image(filename) +{ + if (!req) + return; + + draw_text("Selecting " + filename + "..."); + + req.open("POST", "http://" + global_vhost + "/select", false); + req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + req.send("mode=single&event=" + global_evt + "&filename=" + filename); + + setTimeout("fade_text(0.99)", 30); +} + +function fade_text(opacity) +{ + set_opacity("text", opacity); + if (opacity > 0.0) { + opacity -= 0.03; + if (opacity < 0.0) + opacity = 0.0; + setTimeout("fade_text(" + opacity + ")", 30); + } else { + var text = document.getElementById("text"); + if (text != null) { + text.parentNode.removeChild(text); + } } } @@ -215,6 +281,29 @@ function do_close() window.location = global_return_url; } +function draw_text(msg) +{ + // remove any text we might have left + var text = document.getElementById("text"); + if (text != null) { + text.parentNode.removeChild(text); + } + + text = document.createElement("p"); + text.id = "text"; + text.style.position = "absolute"; + text.style.color = "white"; + text.style.lineHeight = "24px"; + text.style.font = "24px verdana, arial, sans-serif"; + text.innerHTML = msg; + + var main = document.getElementById("main"); + main.appendChild(text); + + text.style.left = (main.clientWidth - text.clientWidth) / 2 + "px"; + text.style.top = (main.clientHeight - text.clientHeight) / 2 + "px"; +} + // enable the horrible horrible IE PNG hack function ie_png_hack() { @@ -226,5 +315,8 @@ function ie_png_hack() var previous = document.getElementById("previous"); previous.outerHTML = ""; + + var close = document.getElementById("close"); + close.outerHTML = ""; } }