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

ba73d278ae4668774f44736489813b14e3914e83

Wolfsblvt <wolfsblvt@gmail.com>

2 files changed, +14 -4Showing whitespace changes
public/scripts/chats.js+13 -3
@@ -585,10 +585,12 @@ async function enlargeMessageImage() {
585 const imgHolder = document.createElement('div');585 const imgHolder = document.createElement('div');
586 imgHolder.classList.add('img_enlarged_holder');586 imgHolder.classList.add('img_enlarged_holder');
587 imgHolder.append(img);587 imgHolder.append(img);
588 const imgContainer = $('<div><pre><code></code></pre></div>');588 const imgContainer = $('<div><pre><code class="img_enlarged_title"></code></code></pre></div>');
589 imgContainer.prepend(imgHolder);589 imgContainer.prepend(imgHolder);
590 imgContainer.addClass('img_enlarged_container');590 imgContainer.addClass('img_enlarged_container');
591 imgContainer.find('code').addClass('txt').text(title);591
592 const codeTitle = imgContainer.find('.img_enlarged_title');
593 codeTitle.addClass('txt').text(title);
592 const titleEmpty = !title || title.trim().length === 0;594 const titleEmpty = !title || title.trim().length === 0;
593 imgContainer.find('pre').toggle(!titleEmpty);595 imgContainer.find('pre').toggle(!titleEmpty);
594 addCopyToCodeBlocks(imgContainer);596 addCopyToCodeBlocks(imgContainer);
@@ -598,9 +600,17 @@ async function enlargeMessageImage() {
598 popup.dlg.style.width = 'unset';600 popup.dlg.style.width = 'unset';
599 popup.dlg.style.height = 'unset';601 popup.dlg.style.height = 'unset';
600602
601 img.addEventListener('click', () => {603 img.addEventListener('click', event => {
602 const shouldZoom = !img.classList.contains('zoomed');604 const shouldZoom = !img.classList.contains('zoomed');
603 img.classList.toggle('zoomed', shouldZoom);605 img.classList.toggle('zoomed', shouldZoom);
606 event.stopPropagation();
607 });
608 codeTitle[0]?.addEventListener('click', event => {
609 event.stopPropagation();
610 });
611
612 popup.dlg.addEventListener('click', event => {
613 popup.completeCancelled();
604 });614 });
605615
606 await popup.show();616 await popup.show();
public/style.css+1 -1
@@ -4799,7 +4799,7 @@ body:not(.sd) .mes_img_swipes {
47994799
4800.img_enlarged {4800.img_enlarged {
4801 object-fit: contain;4801 object-fit: contain;
4802 width: 100%;4802 max-width: 100%;
4803 height: 100%;4803 height: 100%;
4804 cursor: zoom-in4804 cursor: zoom-in
4805}4805}