Signal and Chat photos open in an in-app viewer (X, tap outside, Escape or Back to return to the chat)
build-container / build (push) Successful in 3m5s
build-container / build (push) Successful in 3m5s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c4b830dd43
commit
d0e4e82e0a
4 files changed
+37
-1
No files matched your search
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
// Photos in Signal and Chat open in a full-screen viewer inside the app instead of a new tab.
|
||||
// Close with the X, a tap outside the photo, Escape, or the phone's Back gesture; the chat is right where it was.
|
||||
(function () {
|
||||
let box = null, pushed = false;
|
||||
function close(fromPop) {
|
||||
if (!box) return; box.remove(); box = null; document.removeEventListener('keydown', onKey, true);
|
||||
if (pushed && !fromPop) { pushed = false; history.back(); } else pushed = false;
|
||||
}
|
||||
const onKey = e => { if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); close(); } };
|
||||
function open(src, name) {
|
||||
close();
|
||||
box = document.createElement('div'); box.id = 'imgview'; box.setAttribute('role', 'dialog'); box.setAttribute('aria-modal', 'true'); box.setAttribute('aria-label', name || 'Photo');
|
||||
box.innerHTML = '<button type="button" class="ibtn ivx" aria-label="Close photo"></button><a class="ivsave" download aria-label="Save photo">Save</a><img alt="">';
|
||||
const x = box.querySelector('.ivx'); x.innerHTML = typeof icon === 'function' ? icon('x') : '✕';
|
||||
const im = box.querySelector('img'); im.alt = name || 'Photo'; im.src = src;
|
||||
const sv = box.querySelector('.ivsave'); sv.href = src; if (name) sv.setAttribute('download', name);
|
||||
x.onclick = () => close();
|
||||
box.onclick = e => { if (e.target === box) close(); };
|
||||
document.body.appendChild(box); document.addEventListener('keydown', onKey, true); x.focus({ preventScroll: true });
|
||||
try { history.pushState({ imgview: 1 }, ''); pushed = true; } catch { /* no history: the X still closes it */ }
|
||||
}
|
||||
addEventListener('popstate', () => { if (box) { pushed = false; close(true); } });
|
||||
document.addEventListener('click', e => {
|
||||
const im = e.target.closest && e.target.closest('img.sgimg'); if (!im) return;
|
||||
const a = im.closest('a[href]'); if (!a) return;
|
||||
e.preventDefault(); open(a.getAttribute('href'), im.alt);
|
||||
});
|
||||
})();
|
||||
Reference in new issue
Block a user