Update regarding image previews.
Some checks failed
CI / lint (push) Failing after 19s
CI / test (3.8) (push) Failing after 18s
CI / test (3.12) (push) Failing after 19s
CI / test (3.9) (push) Failing after 19s
CI / build (push) Failing after 20s
CI / test (3.11) (push) Failing after 38s
CI / test (3.10) (push) Failing after 39s
Some checks failed
CI / lint (push) Failing after 19s
CI / test (3.8) (push) Failing after 18s
CI / test (3.12) (push) Failing after 19s
CI / test (3.9) (push) Failing after 19s
CI / build (push) Failing after 20s
CI / test (3.11) (push) Failing after 38s
CI / test (3.10) (push) Failing after 39s
This commit is contained in:
parent
213c299603
commit
7e8362f85a
@ -10,7 +10,7 @@ import { buildDevrantImageUrl, isGifUrl } from '../utils/url.js';
|
|||||||
|
|
||||||
class ImagePreview extends BaseComponent {
|
class ImagePreview extends BaseComponent {
|
||||||
static get observedAttributes() {
|
static get observedAttributes() {
|
||||||
return ['src', 'width', 'height', 'alt'];
|
return ['src', 'width', 'height', 'alt', 'external'];
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
@ -23,14 +23,15 @@ class ImagePreview extends BaseComponent {
|
|||||||
const width = this.getAttr('width');
|
const width = this.getAttr('width');
|
||||||
const height = this.getAttr('height');
|
const height = this.getAttr('height');
|
||||||
const alt = this.getAttr('alt') || 'Image';
|
const alt = this.getAttr('alt') || 'Image';
|
||||||
|
const external = this.hasAttribute('external');
|
||||||
|
|
||||||
if (!src) {
|
if (!src) {
|
||||||
this.setHtml('');
|
this.setHtml('');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const imageUrl = buildDevrantImageUrl(src);
|
const imageUrl = external ? src : buildDevrantImageUrl(src);
|
||||||
const isGif = isGifUrl(imageUrl);
|
const isGif = isGifUrl(src);
|
||||||
const aspectRatio = width && height ? width / height : null;
|
const aspectRatio = width && height ? width / height : null;
|
||||||
|
|
||||||
this.addClass('image-preview');
|
this.addClass('image-preview');
|
||||||
@ -71,7 +72,8 @@ class ImagePreview extends BaseComponent {
|
|||||||
const src = this.getAttr('src');
|
const src = this.getAttr('src');
|
||||||
if (!src) return;
|
if (!src) return;
|
||||||
|
|
||||||
const imageUrl = buildDevrantImageUrl(src);
|
const external = this.hasAttribute('external');
|
||||||
|
const imageUrl = external ? src : buildDevrantImageUrl(src);
|
||||||
|
|
||||||
const lightbox = document.createElement('image-lightbox');
|
const lightbox = document.createElement('image-lightbox');
|
||||||
lightbox.setAttribute('src', imageUrl);
|
lightbox.setAttribute('src', imageUrl);
|
||||||
|
|||||||
@ -53,11 +53,12 @@ class RantContent extends BaseComponent {
|
|||||||
let html = `<div class="content-text">${renderedText}</div>`;
|
let html = `<div class="content-text">${renderedText}</div>`;
|
||||||
|
|
||||||
if (images.length > 0) {
|
if (images.length > 0) {
|
||||||
|
const isExternal = links && links.length > 0;
|
||||||
html += `
|
html += `
|
||||||
<div class="content-images">
|
<div class="content-images">
|
||||||
${images.map(url => {
|
${images.map(url => {
|
||||||
const safeUrl = sanitizeUrl(url);
|
const safeUrl = sanitizeUrl(url);
|
||||||
return safeUrl ? `<image-preview src="${safeUrl}"></image-preview>` : '';
|
return safeUrl ? `<image-preview src="${safeUrl}"${isExternal ? ' external' : ''}></image-preview>` : '';
|
||||||
}).join('')}
|
}).join('')}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user