widgets: add scoped css support

This commit is contained in:
jean-emmanuel 2017-02-21 21:40:00 +01:00
parent 82df4c6c33
commit 73666425b8

View file

@ -178,9 +178,20 @@ module.exports.widgets = function(data,parent) {
widgetData.id:
iconify(widgetData.label)
var css = ';' + widgetData.css,
scopedCss = ''
css.replace(/[;\}]*([^\;\{]*\{[^\}]*\})/g, (m)=>{
if (m[0]==';') m = m.substr(1,m.length)
scopedCss += '${id}' + m
return ''
})
// create container
var widgetContainer = $(`
<div class="widget ${widgetData.type}-container ${styleL.length || styleT.length?'absolute-position':''}" style="${styleW + styleH + styleL + styleT + widgetData.css}">
<div class="widget ${widgetData.type}-container ${styleL.length || styleT.length?'absolute-position':''}" style="${styleW + styleH + styleL + styleT + css}">
<div class="label"><span>${label}</span></div>
</div>
`)
@ -198,6 +209,12 @@ module.exports.widgets = function(data,parent) {
widgetManager.addWidget(widgetInner)
if (scopedCss.length) {
widgetContainer.addClass('css-scope-' + widgetInner.hash)
scopedCss = scopedCss.split('${id}').join('.css-scope-' + widgetInner.hash + ' ')
widgetContainer.append(`<style>${scopedCss}</style>`)
}
// set widget's initial state
if (widgetData.value !== '' && widgetInner.setValue) {
widgetInner.setValue(widgetData.value)