summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2020-10-26 10:18:58 +0000
committerqsm-odoo <qsm@odoo.com>2020-10-27 11:00:59 +0000
commit34238b77ace7e6feeb1f9e693d7cd3b12786505d (patch)
tree651b89434141d99599614347ebae5e34b54944d1 /addons/web_editor/static/src/js
parentc64b3c22bfab848e13145235acc03562aee43e76 (diff)
[FIX] web_editor: properly allow to select a bg color for badges
Before this commit, the badges' background color was not possible to edit: the previews were done correctly but the background color was removed after final selection. This was because the background color property is animated on badges, messing with the related edition function. Closes https://github.com/odoo/odoo/issues/59337 closes odoo/odoo#60742 X-original-commit: 0b0f3a9c6d60cd9883628d83b6893efd24556aa3 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Diffstat (limited to 'addons/web_editor/static/src/js')
-rw-r--r--addons/web_editor/static/src/js/editor/snippets.options.js21
1 files changed, 21 insertions, 0 deletions
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 d9716271528..d117df5e49a 100644
--- a/addons/web_editor/static/src/js/editor/snippets.options.js
+++ b/addons/web_editor/static/src/js/editor/snippets.options.js
@@ -1994,6 +1994,14 @@ const SnippetOptionWidget = Widget.extend({
* @returns {Promise|undefined}
*/
selectStyle: function (previewMode, widgetValue, params) {
+ // Disable all transitions for the duration of the method as many
+ // comparisons will be done on the element to know if applying a
+ // property has an effect or not. Also, changing a css property via the
+ // editor should not show any transition as previews would not be done
+ // immediately, which is not good for the user experience.
+ this.$target[0].classList.add('o_we_force_no_transition');
+ const _restoreTransitions = () => this.$target[0].classList.remove('o_we_force_no_transition');
+
if (params.cssProperty === 'background-color') {
this.$target.trigger('background-color-event', previewMode);
}
@@ -2019,6 +2027,7 @@ const SnippetOptionWidget = Widget.extend({
// Those are the special color combinations classes. Just have
// to add it (and adding the potential extra class) then leave.
this.$target[0].classList.add('o_cc', `o_cc${widgetValue}`, params.extraClass);
+ _restoreTransitions();
return;
}
if (params.colorNames.includes(widgetValue)) {
@@ -2030,6 +2039,7 @@ const SnippetOptionWidget = Widget.extend({
// property we are editing, nothing more has to be done.
// (except adding the extra class)
this.$target.addClass(params.extraClass);
+ _restoreTransitions();
return;
}
// Otherwise, it means that class probably does not exist,
@@ -2085,6 +2095,8 @@ const SnippetOptionWidget = Widget.extend({
if (params.extraClass) {
this.$target.toggleClass(params.extraClass, hasUserValue);
}
+
+ _restoreTransitions();
},
//--------------------------------------------------------------------------
@@ -2362,6 +2374,12 @@ const SnippetOptionWidget = Widget.extend({
}
}
+ // Disable all transitions for the duration of the style check
+ // as we want to know the final value of a property to properly
+ // update the UI.
+ this.$target[0].classList.add('o_we_force_no_transition');
+ const _restoreTransitions = () => this.$target[0].classList.remove('o_we_force_no_transition');
+
const styles = window.getComputedStyle(this.$target[0]);
const cssProps = weUtils.CSS_SHORTHANDS[params.cssProperty] || [params.cssProperty];
const cssValues = cssProps.map(cssProp => {
@@ -2384,6 +2402,9 @@ const SnippetOptionWidget = Widget.extend({
if (cssValues.length === 2 && weUtils.areCssValuesEqual(cssValues[1], cssValues[0], params.cssProperty, this.$target)) {
cssValues.pop();
}
+
+ _restoreTransitions();
+
return cssValues.join(' ');
}
}