From d9c4d928f7c7e148d024cb56f53e6bfb98389f6d Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Thu, 28 May 2020 10:04:43 +0000 Subject: [IMP] web_editor, *: integrate new o_cc${xxx} classes in the colorpicker *: website Part of https://github.com/odoo/odoo/pull/45856 task-2197038 --- addons/web_editor/static/src/js/common/utils.js | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'addons/web_editor/static/src/js/common/utils.js') diff --git a/addons/web_editor/static/src/js/common/utils.js b/addons/web_editor/static/src/js/common/utils.js index 912b4717c69..e7e2a4fad97 100644 --- a/addons/web_editor/static/src/js/common/utils.js +++ b/addons/web_editor/static/src/js/common/utils.js @@ -139,6 +139,33 @@ function _areCssValuesEqual(value1, value2, cssProp, $target) { const numValue2 = _convertValueToUnit(value2, data[1], cssProp, $target); return (Math.abs(numValue1 - numValue2) < Number.EPSILON); } +/** + * @param {string|number} name + * @returns {boolean} + */ +function _isColorCombinationName(name) { + const number = parseInt(name); + return (!isNaN(number) && number % 100 !== 0); +} +/** + * @param {string[]} colorNames + * @param {string} [prefix='bg-'] + * @returns {string[]} + */ +function _computeColorClasses(colorNames, prefix = 'bg-') { + let hasCCClasses = false; + const classes = colorNames.map(c => { + if (_isColorCombinationName(c)) { + hasCCClasses = true; + return `o_cc${c}`; + } + return (prefix + c); + }); + if (hasCCClasses) { + classes.push('o_cc'); + } + return classes; +} return { CSS_SHORTHANDS: CSS_SHORTHANDS, @@ -148,5 +175,7 @@ return { convertNumericToUnit: _convertNumericToUnit, getNumericAndUnit: _getNumericAndUnit, areCssValuesEqual: _areCssValuesEqual, + isColorCombinationName: _isColorCombinationName, + computeColorClasses: _computeColorClasses, }; }); -- cgit v1.2.3