From 995b20fd6ac3eb121ed469df70492845c00ffb58 Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Fri, 26 Jun 2020 09:17:15 +0000 Subject: [PATCH] [REF] web_editor: move normalizeColor function to we-utils for reuse Part of https://github.com/odoo/odoo/pull/53017 task-2210790 --- .../web_editor/static/src/js/common/utils.js | 14 +++++++++++++ .../static/src/js/editor/snippets.options.js | 20 ++----------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/addons/web_editor/static/src/js/common/utils.js b/addons/web_editor/static/src/js/common/utils.js index 61e8f648ee8..aaa02c58589 100644 --- a/addons/web_editor/static/src/js/common/utils.js +++ b/addons/web_editor/static/src/js/common/utils.js @@ -187,6 +187,19 @@ function _getCSSVariableValue(key, htmlStyle) { // double-quotes when reading them through getPropertyValue... return value.replace(/"/g, "'"); } +/** + * Normalize a color in case it is a variable name so it can be used outside of + * css. + * + * @param {string} color the color to normalize into a css value + * @returns {string} the normalized color + */ +function _normalizeColor(color) { + if (ColorpickerWidget.isCSSColor(color)) { + return color; + } + return _getCSSVariableValue(color); +} return { CSS_SHORTHANDS: CSS_SHORTHANDS, @@ -199,5 +212,6 @@ return { isColorCombinationName: _isColorCombinationName, computeColorClasses: _computeColorClasses, getCSSVariableValue: _getCSSVariableValue, + normalizeColor: _normalizeColor, }; }); diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index 1c78a420dd1..92438f33a6c 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -8,6 +8,7 @@ const time = require('web.time'); var Widget = require('web.Widget'); var ColorPaletteWidget = require('web_editor.ColorPalette').ColorPaletteWidget; const weUtils = require('web_editor.utils'); +const {normalizeColor} = weUtils; var weWidgets = require('wysiwyg.widgets'); const { loadImage, @@ -2831,7 +2832,7 @@ const ImageHandlerOption = SnippetOptionWidget.extend({ * @see this.selectClass for parameters */ setFilter(previewMode, widgetValue, params) { - this._getImg().dataset.filter = this._normalizeColor(widgetValue); + this._getImg().dataset.filter = normalizeColor(widgetValue); return this._applyOptions(); }, /** @@ -2967,23 +2968,6 @@ const ImageHandlerOption = SnippetOptionWidget.extend({ * @returns {Int} the maximum width at which the image can be displayed */ _computeMaxDisplayWidth() {}, - - //-------------------------------------------------------------------------- - // Util - //-------------------------------------------------------------------------- - - /** - * Normalize a color into a css value usable by the canvas rendering context. - * - * @private - * @param {string} color the color to normalize into a css value - */ - _normalizeColor(color) { - if (!ColorpickerWidget.isCSSColor(color)) { - color = weUtils.getCSSVariableValue(color); - } - return color; - }, }); /**