]> git.sesse.net Git - pr0n/commitdiff
Fix a swiping issue.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 19 Mar 2023 12:12:08 +0000 (13:12 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 19 Mar 2023 12:15:13 +0000 (13:15 +0100)
A infobox that was too wide could be dragged in and then magically
disappear; this would be since clientWidth would be 0 when we measured
(because style.display was 'none' before positioning, and then fixed
only immediately afterwards).

files/pr0n-fullscreen.js

index 7f5aed6dbe79ebce3b0507674232e923a4c3e415..a2480b4a3605030e8b81d04cd72f9dd2d995c53b 100644 (file)
@@ -135,8 +135,8 @@ function display_image(url, backend_width, backend_height, elem_id, offset)
                // 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);
        }
 }
@@ -278,10 +278,8 @@ function position_image(img, backend_width, backend_height, offset, box)
                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";