Don't show same dimensions twice if there are no custom dimensions

This commit is contained in:
Henrik Giesel 2021-07-21 19:03:21 +02:00 committed by Damien Elmes
parent 92ed342547
commit 4142fa2aa2

View file

@ -27,6 +27,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
let actualWidth = ""; let actualWidth = "";
let actualHeight = ""; let actualHeight = "";
let customDimensions = false;
let containerTop = 0; let containerTop = 0;
let containerLeft = 0; let containerLeft = 0;
@ -71,12 +72,15 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
height = image!.clientHeight; height = image!.clientHeight;
const widthProperty = image!.style.width; const widthProperty = image!.style.width;
customDimensions = false;
if (widthProperty) { if (widthProperty) {
actualWidth = widthProperty.endsWith("px") actualWidth = widthProperty.endsWith("px")
? widthProperty.substring(0, widthProperty.length - 2) ? widthProperty.substring(0, widthProperty.length - 2)
: widthProperty; : widthProperty;
customDimensions = true;
} else { } else {
actualWidth = String(width); actualWidth = String(naturalWidth);
} }
const heightProperty = image!.style.height; const heightProperty = image!.style.height;
@ -84,8 +88,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
actualHeight = heightProperty.endsWith("px") actualHeight = heightProperty.endsWith("px")
? heightProperty.substring(0, heightProperty.length - 2) ? heightProperty.substring(0, heightProperty.length - 2)
: heightProperty; : heightProperty;
customDimensions = true;
} else { } else {
actualHeight = String(height); actualHeight = String(naturalHeight);
} }
} }
@ -162,7 +167,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
</div> </div>
{#if showDimensions} {#if showDimensions}
<div class="image-handle-dimensions" class:is-rtl={isRtl}> <div class="image-handle-dimensions" class:is-rtl={isRtl}>
{actualWidth}&times;{actualHeight} (Original: {naturalWidth}&times;{naturalHeight}) <span>{actualWidth}&times;{actualHeight}</span>
{#if customDimensions}<span
>(Original: {naturalWidth}&times;{naturalHeight})</span
>{/if}
</div> </div>
{/if} {/if}
<div <div
@ -240,6 +248,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
user-select: none; user-select: none;
font-size: 13px; font-size: 13px;
color: white;
background-color: rgba(0 0 0 / 0.3); background-color: rgba(0 0 0 / 0.3);
border-color: black; border-color: black;
border-radius: 0.25rem; border-radius: 0.25rem;