2019-02-25 18:04:49 +07:00
|
|
|
const createCard = require('../create-card');
|
|
|
|
|
|
|
|
module.exports = createCard({
|
2018-06-07 12:35:38 +01:00
|
|
|
name: 'embed',
|
|
|
|
type: 'dom',
|
|
|
|
render(opts) {
|
|
|
|
if (!opts.payload.html) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
let {payload, env: {dom}} = opts;
|
|
|
|
|
|
|
|
let figure = dom.createElement('figure');
|
2018-08-31 11:05:27 +01:00
|
|
|
figure.setAttribute('class', 'kg-card kg-embed-card');
|
2018-06-07 12:35:38 +01:00
|
|
|
|
|
|
|
let html = dom.createRawHTMLSection(payload.html);
|
|
|
|
figure.appendChild(html);
|
|
|
|
|
|
|
|
if (payload.caption) {
|
|
|
|
let figcaption = dom.createElement('figcaption');
|
2018-08-08 14:29:20 +01:00
|
|
|
figcaption.appendChild(dom.createRawHTMLSection(payload.caption));
|
2018-06-07 12:35:38 +01:00
|
|
|
figure.appendChild(figcaption);
|
2019-02-25 10:14:45 +07:00
|
|
|
figure.setAttribute('class', `${figure.getAttribute('class')} kg-card-hascaption`);
|
2018-06-07 12:35:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return figure;
|
2019-10-03 10:44:05 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
absoluteToRelative(urlUtils, payload, options) {
|
|
|
|
payload.caption = payload.caption && urlUtils.htmlAbsoluteToRelative(payload.caption, options);
|
|
|
|
return payload;
|
|
|
|
},
|
|
|
|
|
|
|
|
relativeToAbsolute(urlUtils, payload, options) {
|
|
|
|
payload.caption = payload.caption && urlUtils.htmlRelativeToAbsolute(payload.caption, options);
|
|
|
|
return payload;
|
2018-06-07 12:35:38 +01:00
|
|
|
}
|
2019-02-25 18:04:49 +07:00
|
|
|
});
|