]> git.sesse.net Git - pr0n/blobdiff - files/pr0n-fullscreen.js
Render the infobox on the client side.
[pr0n] / files / pr0n-fullscreen.js
index 076c626a9a81c49dc59a22189ead0eebef165f83..b431a3c33a1a9f42adadb79545b6d29a8fca6150 100644 (file)
@@ -104,7 +104,7 @@ function rename_element(old_name, new_name)
        return elem;
 }
 
-function display_image(url, backend_width, backend_height, elem_id, offset, box)
+function display_image(url, backend_width, backend_height, elem_id, offset)
 {
        // See if this image already exists in the DOM; if not, add it.
        var img = document.getElementById(elem_id);
@@ -112,7 +112,7 @@ function display_image(url, backend_width, backend_height, elem_id, offset, box)
                img = document.createElement("img");
                img.id = elem_id;
                img.alt = "";
-               img.className = box ? "fsbox" : "fsimg";
+               img.className = "fsimg";
        }
        img.style.position = "absolute";
        img.style.transformOrigin = "top left";
@@ -120,7 +120,7 @@ function display_image(url, backend_width, backend_height, elem_id, offset, box)
 
        if (offset === 0) {
                img.src = url;
-               position_image(img, backend_width, backend_height, offset, box);
+               position_image(img, backend_width, backend_height, offset, false);
        } else {
                // This is a preload, so wait for the main image to be ready.
                // The test for .complete is an old IE hack, which I don't know if is relevant anymore.
@@ -135,12 +135,41 @@ function display_image(url, backend_width, backend_height, elem_id, offset, box)
                // scroll offset completely off.
                img.style.display = 'none';
                setTimeout(function() {
-                       position_image(img, backend_width, backend_height, offset, box);
+                       position_image(img, backend_width, backend_height, offset, false);
                        img.style.display = null;
                }, 1);
        }
 }
 
+function display_infobox(html, backend_width, backend_height, elem_id, offset)
+{
+       // See if this image already exists in the DOM; if not, add it.
+       var box = document.getElementById(elem_id);
+       if (box === null) {
+               box = document.createElement("div");
+               box.id = elem_id;
+               box.alt = "";
+               box.className = "fsbox";
+       }
+       box.style.position = "absolute";
+       box.style.transformOrigin = "top left";
+       box.innerHTML = html;
+       document.getElementById("main").appendChild(box);
+
+       if (offset === 0) {
+               position_image(box, backend_width, backend_height, offset, true);
+       } else {
+               // This is a preload.
+               // Seemingly one needs to delay position_image(), or Firefox will set the initial
+               // scroll offset completely off.
+               box.style.display = 'none';
+               setTimeout(function() {
+                       position_image(box, backend_width, backend_height, offset, true);
+                       box.style.display = null;
+               }, 1);
+       }
+}
+
 function display_image_num(num, offset)
 {
        var screen_size = find_width();
@@ -160,19 +189,11 @@ function display_image_num(num, offset)
        var url = window.location.origin + "/" + evt + "/" + backend_width + "x" + backend_height + "/" + filename;
        var elem_id = num;
 
-       display_image(url, adjusted_size[2], adjusted_size[3], elem_id, offset, false);
+       display_image(url, adjusted_size[2], adjusted_size[3], elem_id, offset);
 
        if (global_infobox) {
-               var url;
-               var dpr = find_dpr();
                var elem_id = num + "_box";
-               if (dpr == 1) {
-                       url = window.location.origin + "/" + evt + "/" + backend_width + "x" + backend_height + "/box/" + filename;
-               } else {
-                       url = window.location.origin + "/" + evt + "/" + backend_width + "x" + backend_height + "@" + dpr.toFixed(2) + "/box/" + filename;
-               }
-               display_image(url, adjusted_size[2], adjusted_size[3], elem_id, offset, true);
-               document.getElementById(elem_id).style.transform += " scale(" + (1.0 / dpr) + ")";
+               display_infobox(global_image_list[num][4], adjusted_size[2], adjusted_size[3], elem_id, offset);
        }
 
        if (offset === 0) {
@@ -254,6 +275,8 @@ function position_image(img, backend_width, backend_height, offset, box)
 
        if (box) {
                img.style.top = Math.min(top + height, screen_size[1] - 24) / dpr + "px";
+               img.style.width = (width / dpr) + "px";
+               img.style.height = "24px";
        } else {
                img.style.top = (top / dpr) + "px";
                img.style.lineHeight = (height / dpr) + "px";
@@ -531,7 +554,7 @@ function set_swipe_pos(x, transition)
                        var inum = parseInt(child.id.replace("_box", ""));
                        var offset = inum - global_image_num;
                        child.style.transition = transition;
-                       child.style.transform = "translate(" + (x + find_width()[0] * offset / dpr) + "px,0px) scale(" + (1.0 / dpr) + ")";
+                       child.style.transform = "translate(" + (x + find_width()[0] * offset / dpr) + "px,0px)";
                }
        }
 }