From 73666425b88ff4a6d3626d2852ddd840e4300384 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Tue, 21 Feb 2017 21:40:00 +0100 Subject: [PATCH] widgets: add scoped css support --- src/browser/js/app/parser.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/browser/js/app/parser.js b/src/browser/js/app/parser.js index d9cb990a..d8426d91 100644 --- a/src/browser/js/app/parser.js +++ b/src/browser/js/app/parser.js @@ -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 = $(` -
+
${label}
`) @@ -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(``) + } + // set widget's initial state if (widgetData.value !== '' && widgetInner.setValue) { widgetInner.setValue(widgetData.value)