diff --git a/edsdme/components/NewsCard.js b/edsdme/components/NewsCard.js index ac8afaf..c7a2952 100644 --- a/edsdme/components/NewsCard.js +++ b/edsdme/components/NewsCard.js @@ -1,9 +1,11 @@ import { newsCardStyles } from './PartnerCardsStyles.js'; -import { formatDate, getLibs } from '../scripts/utils.js'; +import { formatDate, getLibs, prodHosts } from '../scripts/utils.js'; const miloLibs = getLibs(); const { html, LitElement } = await import(`${miloLibs}/deps/lit-all.min.js`); +const DEFAULT_BACKGROUND_IMAGE_PATH = '/content/dam/solution/en/images/card-collection/sample_default.png'; + class NewsCard extends LitElement { static properties = { data: { type: Object } }; @@ -24,6 +26,25 @@ class NewsCard extends LitElement { return newUrl; } + checkBackgroundImage(element) { + const url = this.data.styles?.backgroundImage; + const img = new Image(); + + const isProd = prodHosts.includes(window.location.host); + const defaultBackgroundImageOrigin = `https://partners.${isProd ? '' : 'stage.'}adobe.com`; + const defaultBackgroundImageUrl = `${defaultBackgroundImageOrigin}${DEFAULT_BACKGROUND_IMAGE_PATH}`; + + img.onerror = () => { + element.style.backgroundImage = `url(${defaultBackgroundImageUrl})`; + }; + + img.src = url; + } + + firstUpdated() { + this.checkBackgroundImage(this.shadowRoot.querySelector('.card-header')); + } + render() { return html`