snappymail/dev/Component/SvgIcon.js

28 lines
574 B
JavaScript
Raw Normal View History

2015-11-15 08:23:16 +08:00
2016-07-02 06:49:59 +08:00
import $ from '$';
2015-11-15 08:23:16 +08:00
2016-06-30 08:02:45 +08:00
let cachedUrl = null;
const getUrl = () => {
if (!cachedUrl)
{
const version = $('#rlAppVersion').attr('content') || '0.0.0';
cachedUrl = `rainloop/v/${version}/static/css/svg/icons.svg`;
2015-11-15 08:23:16 +08:00
}
2016-06-30 08:02:45 +08:00
return cachedUrl;
};
2015-11-15 08:23:16 +08:00
2017-03-01 02:44:13 +08:00
export default {
2015-11-15 08:23:16 +08:00
template: '<b></b>',
viewModel: {
2016-06-30 08:02:45 +08:00
createViewModel: ({icon = 'null'}, componentInfo) => {
2015-11-15 08:23:16 +08:00
if (componentInfo && componentInfo.element)
{
$(componentInfo.element).replaceWith(
2016-06-30 08:02:45 +08:00
`<svg class="svg-icon svg-icon-${icon}"><use xlink:href="${getUrl()}#svg-icon-${icon}"></use></svg>`
2015-11-15 08:23:16 +08:00
);
}
}
}
};