]> git.sesse.net Git - pr0n/blobdiff - files/pr0n-fullscreen.js
Update the numbers in the FAQ.
[pr0n] / files / pr0n-fullscreen.js
index 468f249c0c6c780b30c87eed132d5923f8ec8968..181a82cb1e0745bde78677c7c02ca5ab16b6c74f 100644 (file)
@@ -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 = "<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); }\" />";
+               
+               var close = document.getElementById("close");
+               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);\" />";
        }
 }