Merge pull request #3285 from SillyTavern/zoom-image-closing Allow zoomed in images in chat to be closed by clicking outside
Signed| @@ -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></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'; |
| 600 | 602 | ||
| 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 | }); |
| 605 | 615 | ||
| 606 | await popup.show(); | 616 | await popup.show(); |
| @@ -4799,7 +4799,7 @@ body:not(.sd) .mes_img_swipes { | |||
| 4799 | 4799 | ||
| 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-in | 4804 | cursor: zoom-in |
| 4805 | } | 4805 | } |