diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-03-01 22:23:20 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-03-01 22:23:20 -0400 |
commit | 0f7e9e5dfb429b14b816370dc1472ee4c2ae82eb (patch) | |
tree | 90ad0f28f8ca18877820e5c94141fe5cebd8e6ee /src/static | |
parent | 62cd6e574b89a5bfa75dc52ef2383fddf5cbc87a (diff) |
dynamic thumb size for image overlay
Diffstat (limited to 'src/static')
-rw-r--r-- | src/static/client.js | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/static/client.js b/src/static/client.js index af358210..addc93a4 100644 --- a/src/static/client.js +++ b/src/static/client.js @@ -674,8 +674,10 @@ function handleImageLinkClicked(evt) { const mainImage = document.getElementById('image-overlay-image'); const thumbImage = document.getElementById('image-overlay-image-thumb'); + const mainThumbSize = getPreferredThumbSize(); + const source = evt.target.closest('a').href; - mainImage.src = source.replace(/\.(jpg|png)$/, '.huge.jpg'); + mainImage.src = source.replace(/\.(jpg|png)$/, `.${mainThumbSize}.jpg`); thumbImage.src = source.replace(/\.(jpg|png)$/, '.small.jpg'); for (const viewOriginal of allViewOriginal) { viewOriginal.href = source; @@ -700,6 +702,30 @@ function handleImageLinkClicked(evt) { } } +function getPreferredThumbSize() { + // Assuming a square, the image will be constrained to the lesser window + // dimension. Coefficient here matches CSS dimensions for image overlay. + const constrainedLength = Math.floor(Math.min( + 0.80 * window.innerWidth, + 0.80 * window.innerHeight)); + + // Match device pixel ratio, which is 2x for "retina" displays and certain + // device configurations. + const visualLength = window.devicePixelRatio * constrainedLength; + + const largeLength = 800; + const semihugeLength = 1200; + const goodEnoughThreshold = 0.90; + + if (Math.floor(visualLength * goodEnoughThreshold) <= largeLength) { + return 'large'; + } else if (Math.floor(visualLength * goodEnoughThreshold) <= semihugeLength) { + return 'semihuge'; + } else { + return 'huge'; + } +} + function updateFileSizeInformation(fileSize) { const fileSizeWarningThreshold = 8 * 10 ** 6; @@ -723,7 +749,6 @@ function updateFileSizeInformation(fileSize) { fileSize = parseInt(fileSize); const round = (exp) => Math.round(fileSize / 10 ** (exp - 1)) / 10; - console.log(round(3)); if (fileSize > fileSizeWarningThreshold) { fileSizeWarning.classList.add('visible'); |