xmpp.chapril.org-conversejs/src/templates/directives/image.js

18 lines
592 B
JavaScript
Raw Normal View History

2020-07-14 14:06:52 +02:00
import { converse } from "@converse/headless/converse-core";
import { directive, html } from "lit-html";
2020-07-14 15:45:16 +02:00
export const renderImage = directive((url, onLoad, onClick) => part => {
function onError () {
part.setValue(converse.env.utils.convertUrlToHyperlink(url));
part.commit();
}
part.setValue(
html`<a href="${url}"
class="chat-image__link"
target="_blank"
rel="noopener"
2020-07-14 15:45:16 +02:00
><img class="chat-image img-thumbnail" src="${url}" @click=${onClick} @error=${onError} @load=${onLoad}/></a>`
);
});