-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
40 lines (31 loc) · 1.23 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import {Type} from "../cardType";
import {select} from '@wordpress/data';
function theImageUrl(props) {
let fallback = props.meta.cardImage || tcData.defaultImage;
const {getPostType} = select('core');
let postTypeCheck = getPostType(select('core/editor').getEditedPostAttribute('type'));// no use if no support for thumbnail
if (!postTypeCheck || !postTypeCheck.supports['thumbnail']) {
return fallback;
}
let featuredImageId = select('core/editor').getEditedPostAttribute('featured_media');
if (featuredImageId === 0) {
return fallback;
}
let media = select('core').getMedia(featuredImageId);
if (typeof(media) !== 'undefined') {
return props.meta.cardImage || media.source_url;
}
return fallback;
}
export const Image = ({props}) => (
<div className="tcu-imageWrapper"
style={{backgroundImage: "url(" + theImageUrl(props) + ")"}}>
{'player' === Type(props) && (
<div className="PlayerCard-playButton"
style={{backgroundImage: "url(" + tcData.pluginUrl + "img/player.svg)"}}></div>
)}
<img className="u-block"
alt={props.meta.cardImageAlt || ''}
src={theImageUrl(props)}/>
</div>
);