Skip to content

Commit

Permalink
MWPW-155065 PartnerCards fallback for invalid thumbnail images
Browse files Browse the repository at this point in the history
- checks news card background image on first updated
- replace with a hardcoded default (needs configuration somewhere)
- changes the background color of the card header to prevent FOUC
  • Loading branch information
richardhand committed Jul 25, 2024
1 parent af52e4d commit 6c7b20e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions eds/components/NewsCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { formatDate, getLibs } from '../scripts/utils.js';
const miloLibs = getLibs();
const { html, LitElement } = await import(`${miloLibs}/deps/lit-all.min.js`);

// @todo - make this configurable somewhere.
const DEFAULT_BACKGROUND_IMAGE_URL = 'https://solutionpartners.stage2.adobe.com/content/dam/solution/en/images/card-collection/sample_default.png';

class NewsCard extends LitElement {
static properties = { data: { type: Object } };

Expand All @@ -23,6 +26,22 @@ class NewsCard extends LitElement {
return newUrl;
}

checkBackgroundImage(element) {
const style = window.getComputedStyle(element);
const url = style.backgroundImage.slice(5, -2);
const img = new Image();

img.onerror = () => {
element.style.backgroundImage = `url(${DEFAULT_BACKGROUND_IMAGE_URL})`;
};

img.src = url;
}

firstUpdated() {
this.checkBackgroundImage(this.shadowRoot.querySelector('.card-header'));
}

render() {
return html`
<div class="news-card">
Expand Down
2 changes: 1 addition & 1 deletion eds/components/PartnerCardsStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ export const newsCardStyles = css`
.news-card .card-header {
min-height: 192px;
max-height: 192px;
background-color: #323232;
background-color: #f5f5F5;
background-repeat: no-repeat;
background-position: 50% 50%;
background-size: cover;
Expand Down

0 comments on commit 6c7b20e

Please sign in to comment.