From 13f987a9fed4ea18babd074a741d66586332fe52 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 17 Jun 2022 15:32:46 +0300 Subject: [PATCH] csss editor reset --- .../microweber/api/libs/cssjson/cssjson.js | 9 ++++---- .../microweber/api/stylesheet.editor.js | 23 +++++++++++++++++++ .../editor_tools/rte_css_editor/index.php | 7 ++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/userfiles/modules/microweber/api/libs/cssjson/cssjson.js b/userfiles/modules/microweber/api/libs/cssjson/cssjson.js index 3fab9cf2bb3..28602da22ba 100644 --- a/userfiles/modules/microweber/api/libs/cssjson/cssjson.js +++ b/userfiles/modules/microweber/api/libs/cssjson/cssjson.js @@ -180,14 +180,14 @@ var CSSJSON = new function () { */ base.toCSS = function (node, depth, breaks) { var cssString = ''; - if (typeof depth == 'undefined') { + if (typeof depth === 'undefined') { depth = 0; } - if (typeof breaks == 'undefined') { + if (typeof breaks === 'undefined') { breaks = false; } if (node.attributes) { - for (i in node.attributes) { + for (var i in node.attributes) { var att = node.attributes[i]; if (att instanceof Array) { for (var j = 0; j < att.length; j++) { @@ -200,7 +200,8 @@ var CSSJSON = new function () { } if (node.children) { var first = true; - for (i in node.children) { + for (var i in node.children) { + console.log(node.children[i]) if (breaks && !first) { cssString += '\n'; } else { diff --git a/userfiles/modules/microweber/api/stylesheet.editor.js b/userfiles/modules/microweber/api/stylesheet.editor.js index 10a388d5cf7..9e47b252564 100644 --- a/userfiles/modules/microweber/api/stylesheet.editor.js +++ b/userfiles/modules/microweber/api/stylesheet.editor.js @@ -42,6 +42,7 @@ mw.liveeditCSSEditor = function (config) { this._cssTemp = function (json) { + var css = CSSJSON.toCSS(json); if(!mw.liveedit._cssTemp) { mw.liveedit._cssTemp = mw.tools.createStyle('#mw-liveedit-dynamic-temp-style', css, document.body); @@ -51,9 +52,20 @@ mw.liveeditCSSEditor = function (config) { } }; + var removeSheetRuleProperty = function (selector, property) { + var sheet = document.querySelector('link#mw-template-settings').sheet; + var i = 0, l = sheet.cssRules.length; + for ( ; i < l ; i++) { + if(sheet.cssRules[i].selectorText === selector) { + sheet.cssRules[i].style.removeProperty(property); + } + } + }; + this.changed = false; this._temp = {children: {}, attributes: {}}; this.temp = function (node, prop, val) { + val = (val || '').trim(); this.changed = true; if(node.length) { node = node[0]; @@ -65,7 +77,18 @@ mw.liveeditCSSEditor = function (config) { if (!this._temp.children[sel].attributes ) { this._temp.children[sel].attributes = {}; } + + this._temp.children[sel].attributes[prop] = val; + + if(val === '' || val === '!important') { + this._temp.children[sel].attributes[prop] = ''; + // delete this._temp.children[sel].attributes[prop]; + removeSheetRuleProperty (sel, prop); + + } + + this._cssTemp(this._temp); }; diff --git a/userfiles/modules/microweber/toolbar/editor_tools/rte_css_editor/index.php b/userfiles/modules/microweber/toolbar/editor_tools/rte_css_editor/index.php index 5651e6094b3..77475195c6d 100644 --- a/userfiles/modules/microweber/toolbar/editor_tools/rte_css_editor/index.php +++ b/userfiles/modules/microweber/toolbar/editor_tools/rte_css_editor/index.php @@ -395,7 +395,14 @@ interface: 'shadow', + var isbg = prev.prev().find('.mw-field-color-indicator-display'); + if(isbg.length) { + isbg.css('backgroundColor', val); + } + + + prev.val(val); prev.find('input').val(val); var n = parseFloat(val) $('.mw-range.ui-slider', prev).slider('value', !isNaN(n) ? n : 0)