web: Added media previewing

This commit is contained in:
Thomas Mathews 2022-12-15 10:00:20 -08:00
parent ca3668eea7
commit 318cbe98ea
4 changed files with 48 additions and 3 deletions

View file

@ -113,3 +113,19 @@ function click_event(el) {
console.info(`thread to open: ${el.dataset.eid}`);
switch_view("thread");
}
/* open_media_preview presents a modal to display an image via "url".
*/
function open_media_preview(url, type) {
const el = find_node("#media-preview");
el.classList.remove("closed");
find_node("img", el).src = url;
// TODO handle different medias such as audio and video
// TODO add loading state & error checking
}
/* close_media_preview closes any present media modal.
*/
function close_media_preview() {
find_node("#media-preview").classList.add("closed");
}

View file

@ -169,9 +169,7 @@ function linkify(text, show_media) {
let html;
if (show_media && is_img_url(parsed.pathname)) {
html = `
<a target="_blank" href="${url}">
<img class="inline-img" src="${url}"/>
</a>
<img class="inline-img clickable" src="${url}" onclick="open_media_preview('${url}', 'image')"/>
`;
} else if (show_media && is_video_url(parsed.pathname)) {
html = `