Allow zoomed in images be closed by click outside

- Add event listener to close image enlarge popup when clicked outside of image or description
- Change img div to not be width:100% by default, was useless and just confusing when you could click next to the image and it zoomed in
This commit is contained in:
Wolfsblvt
2025-01-09 19:16:48 +01:00
parent 23779fe565
commit ba73d278ae
2 changed files with 14 additions and 4 deletions

View File

@@ -585,10 +585,12 @@ async function enlargeMessageImage() {
const imgHolder = document.createElement('div');
imgHolder.classList.add('img_enlarged_holder');
imgHolder.append(img);
const imgContainer = $('<div><pre><code></code></pre></div>');
const imgContainer = $('<div><pre><code class="img_enlarged_title"></code></code></pre></div>');
imgContainer.prepend(imgHolder);
imgContainer.addClass('img_enlarged_container');
imgContainer.find('code').addClass('txt').text(title);
const codeTitle = imgContainer.find('.img_enlarged_title');
codeTitle.addClass('txt').text(title);
const titleEmpty = !title || title.trim().length === 0;
imgContainer.find('pre').toggle(!titleEmpty);
addCopyToCodeBlocks(imgContainer);
@@ -598,9 +600,17 @@ async function enlargeMessageImage() {
popup.dlg.style.width = 'unset';
popup.dlg.style.height = 'unset';
img.addEventListener('click', () => {
img.addEventListener('click', event => {
const shouldZoom = !img.classList.contains('zoomed');
img.classList.toggle('zoomed', shouldZoom);
event.stopPropagation();
});
codeTitle[0]?.addEventListener('click', event => {
event.stopPropagation();
});
popup.dlg.addEventListener('click', event => {
popup.completeCancelled();
});
await popup.show();