]> git.sesse.net Git - pr0n/blobdiff - files/pr0n-fullscreen.js
Fix an (irrelevant) confusion about addEventListener.
[pr0n] / files / pr0n-fullscreen.js
index 7f5aed6dbe79ebce3b0507674232e923a4c3e415..f08605cb1640f47490c13ec3b7ce3aa19559d6a4 100644 (file)
@@ -128,15 +128,15 @@ function display_image(url, backend_width, backend_height, elem_id, offset)
                if (main_img === null || main_img.complete) {
                        img.src = url;
                } else {
-                       main_img.addEventListener('load', function() { img.src = url; }, false);
+                       main_img.addEventListener('load', function() { img.src = url; }, { 'once': true });
                }
 
                // Seemingly one needs to delay position_image(), or Firefox will set the initial
                // scroll offset completely off.
                img.style.display = 'none';
                setTimeout(function() {
+                       img.style.display = null;  // Must be done before position_image(), for measurement.
                        position_image(img, backend_width, backend_height, offset, false);
-                       img.style.display = null;
                }, 1);
        }
 }
@@ -164,8 +164,8 @@ function display_infobox(html, backend_width, backend_height, elem_id, offset)
                // scroll offset completely off.
                box.style.display = 'none';
                setTimeout(function() {
+                       box.style.display = null;  // Must be done before position_image(), for measurement.
                        position_image(box, backend_width, backend_height, offset, true);
-                       box.style.display = null;
                }, 1);
        }
 }
@@ -274,14 +274,12 @@ function position_image(img, backend_width, backend_height, offset, box)
        img.style.transform = "translate(" + extra_x_offset + "px,0px)";
 
        if (box) {
-               img.style.top = Math.min(top + height, screen_size[1] - 24) / dpr + "px";
+               img.style.top = Math.min(top + height, screen_size[1] - 24 * dpr) / dpr + "px";
                img.style.height = "24px";
                img.style.width = null;
                img.style.whiteSpace = 'nowrap';
-               if (offset == 0) {
-                       // Hide the box if there's no room for all the text.
-                       img.style.opacity = (img.clientWidth < width / dpr + 10) ? null : 0.0;
-               }
+               // Hide the box if there's no room for all the text.
+               img.style.opacity = (img.clientWidth < width / dpr + 10) ? null : 0.0;
                img.style.width = (width / dpr) + "px";
        } else {
                img.style.top = (top / dpr) + "px";