]> git.sesse.net Git - pr0n/blobdiff - files/pr0n-fullscreen.js
Fix text fading.
[pr0n] / files / pr0n-fullscreen.js
index 2601aa14c3c8693183ca96331b7d5574a4fc5cf5..a01508a328c4c813512998b27cb7cc0eba4276e7 100644 (file)
@@ -1,9 +1,9 @@
-var req;
+(function() {
 
-function init_ajax()
-{
-       req = new XMLHttpRequest();
-}
+var global_disabled_opacity = 0.1;
+var global_default_opacity = 0.7;
+var global_highlight_opacity = 1.0;
+var global_infobox = true;
 
 function find_width()
 {
@@ -139,9 +139,23 @@ function display_image(width, height, evt, filename, element_id)
        img.style.transformOrigin = "top left";
        img.style.transform = "scale(" + (1.0 / dpr) + ")";
 
-       // Update the "download original" link.
-       var original_url = window.location.origin + "/" + evt + "/original/" + filename;
-       document.getElementById("origdownload").href = original_url;
+       if (element_id == "image") {
+               // Update the "download original" link.
+               var original_url = window.location.origin + "/" + evt + "/original/" + filename;
+               document.getElementById("origdownload").href = original_url;
+
+               // If it's a raw image, show a JPEG link.
+               var fulldownload = document.getElementById("fulldownload");
+               if (filename.match(/\.(nef|cr2)$/i)) {
+                       fulldownload.style.display = "block";
+                       var full_url = window.location.origin + "/" + evt + "/" + filename;
+                       document.getElementById("fulldownloadlink").href = full_url;
+                       origdownload.innerHTML = "Download original image (RAW)";
+               } else {
+                       fulldownload.style.display = "none";
+                       origdownload.innerHTML = "Download original image";
+               }
+       }
 
        if (global_infobox) {
                var url;
@@ -331,6 +345,7 @@ function toggle_optionmenu()
                set_opacity("options", 0.7);
        }
 }
+window['toggle_optionmenu'] = toggle_optionmenu;
 
 function draw_text(msg)
 {
@@ -363,7 +378,7 @@ function fade_text(opacity)
                if (opacity < 0.0) {
                        opacity = 0.0;
                }
-               setTimeout("fade_text(" + opacity + ")", 30);
+               setTimeout(function() { fade_text(opacity); }, 30);
        } else {
                var text = document.getElementById("text");
                if (text !== null) {
@@ -374,21 +389,18 @@ function fade_text(opacity)
 
 function select_image(evt, filename, selected)
 {
-       if (!req) {
-               return;
-       }
-
        if (selected) {
                draw_text("Selecting " + filename + "...");
        } else {
                draw_text("Unselecting " + filename + "...");
        }
        
+       var req = new XMLHttpRequest();
        req.open("POST", window.location.origin + "/select", false);
        req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        req.send("event=" + evt + "&filename=" + filename + "&selected=" + selected);
 
-       setTimeout("fade_text(0.99)", 30);
+       setTimeout(function() { fade_text(0.99); }, 30);
 }
 
 function key_down(which)
@@ -439,6 +451,7 @@ function parse_image_num(default_value) {
                return default_value;
        }
 }
+window['parse_image_num'] = parse_image_num;
 
 function check_for_hash_change() {
        var num = parse_image_num(-1);
@@ -464,3 +477,38 @@ function toggle_immersive() {
        }
        relayout();
 }
+window['toggle_immersive'] = toggle_immersive;
+
+window.onload = function() {
+       relayout();
+       setInterval(check_for_hash_change, 1000);
+
+       var body = document.body;
+       body.onresize = function() { relayout(); };
+       body.onkeydown = function() { key_down(event.keyCode); };
+       body.onkeyup = function() { key_up(event.keyCode); };
+       body.onhashchange = function() { check_for_hash_change(); };
+       body.onclick = function() { check_for_hash_change(); };
+
+       var previous = document.getElementById('previous');
+       previous.onmousedown = function() { if (can_go_previous()) { set_opacity('previous', global_highlight_opacity); } };
+       previous.onmouseup = function() { if (can_go_previous()) { set_opacity('previous', global_default_opacity); go_previous(); } };
+       previous.onmouseout = function() { if (can_go_previous()) { set_opacity('previous', global_default_opacity); } };
+
+       var next = document.getElementById('next');
+       next.onmousedown = function() { if (can_go_next()) { set_opacity('next', global_highlight_opacity); } };
+       next.onmouseup = function() { if (can_go_next()) { set_opacity('next', global_default_opacity); go_next(); } };
+       next.onmouseout = function() { if (can_go_next()) { set_opacity('next', global_default_opacity); } };
+
+       var close = document.getElementById('close');
+       close.onmousedown = function() { set_opacity('close', global_highlight_opacity); };
+       close.onmouseup = function() { set_opacity('close', global_default_opacity); do_close(); };
+       close.onmouseout = function() { set_opacity('close', global_default_opacity); };
+
+       var options = document.getElementById('options');
+       options.onmousedown = function() { set_opacity('options', global_highlight_opacity); };
+       options.onmouseup = function() { set_opacity('options', global_default_opacity); toggle_optionmenu(); };
+       options.onmouseout = function() { set_opacity('options', global_default_opacity); };
+};
+
+})();