image.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import tpl_gif from 'templates/gif.js';
  2. import tpl_image from 'templates/image.js';
  3. import { CustomElement } from './element.js';
  4. import { api } from "@converse/headless/core";
  5. import { filterQueryParamsFromURL, isGIFURL, shouldRenderMediaFromURL } from '@converse/headless/utils/url.js';
  6. export default class Image extends CustomElement {
  7. static get properties () {
  8. return {
  9. 'src': { type: String },
  10. 'onImgLoad': { type: Function },
  11. // If specified, image is wrapped in a hyperlink that points to this URL.
  12. 'href': { type: String },
  13. }
  14. }
  15. render () {
  16. if (isGIFURL(this.src) && shouldRenderMediaFromURL(this.src, 'image')) {
  17. return tpl_gif(filterQueryParamsFromURL(this.src), true);
  18. } else {
  19. return tpl_image({
  20. 'src': filterQueryParamsFromURL(this.src),
  21. 'href': this.href,
  22. 'onClick': this.onImgClick,
  23. 'onLoad': this.onImgLoad
  24. });
  25. }
  26. }
  27. }
  28. api.elements.define('converse-image', Image);