summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js/editor/summernote.js
diff options
context:
space:
mode:
authorDipalee Bhalodia <dbh@odoo.com>2018-08-08 11:58:57 +0530
committerqsm-odoo <qsm@odoo.com>2018-08-12 18:37:08 +0200
commita17771f591411d744abd4ee45b4c5effb3bf16e4 (patch)
tree71f3a93460782e17297011134c0bd573f435a5c8 /addons/web_editor/static/src/js/editor/summernote.js
parentaf30c2ee6136e2f6e693881fa4e81af76d7cb215 (diff)
[IMP] web_editor: improve text colorpicker
- Split editor button: one for font color and one for background color - Remove recent color button feature - Add only theme colors and remove other color sections like graypalette/standard colors - Button's icon for font color and background color buttons have the same color of currently selected element task-37974 Closes #26274
Diffstat (limited to 'addons/web_editor/static/src/js/editor/summernote.js')
-rw-r--r--addons/web_editor/static/src/js/editor/summernote.js99
1 files changed, 46 insertions, 53 deletions
diff --git a/addons/web_editor/static/src/js/editor/summernote.js b/addons/web_editor/static/src/js/editor/summernote.js
index 784aab3493e..7169c27ee8d 100644
--- a/addons/web_editor/static/src/js/editor/summernote.js
+++ b/addons/web_editor/static/src/js/editor/summernote.js
@@ -970,6 +970,43 @@ renderer.tplButtonInfo.fontsize = function (lang, options) {
});
};
+renderer.tplButtonInfo.color = function (lang, options) {
+ var foreColorButtonLabel = '<i class="' + options.iconPrefix + options.icons.color.recent + '"></i>';
+ var backColorButtonLabel = '<i class="' + options.iconPrefix + 'paint-brush"></i>';
+ // TODO Remove recent color button if possible.
+ // It is still put to avoid JS errors when clicking other buttons as the
+ // editor still expects it to exist.
+ var recentColorButton = renderer.getTemplate().button(foreColorButtonLabel, {
+ className: 'note-recent-color d-none',
+ title: lang.color.foreground,
+ event: 'color',
+ value: '{"backColor":"#B35E9B"}'
+ });
+ var foreColorItems = [
+ '<li><div class="btn-group flex-column">',
+ '<div class="note-color-palette" data-target-event="foreColor"></div>',
+ '</div></li>',
+ ];
+ var backColorItems = [
+ '<li><div class="btn-group flex-column">',
+ '<div class="note-color-reset" data-event="backColor" data-value="inherit" title="' + lang.color.transparent + '">',
+ lang.color.setTransparent + '</div>',
+ '<div class="note-color-palette" data-target-event="backColor"></div>',
+ '</div></li>',
+ ];
+ var foreColorButton = renderer.getTemplate().button(foreColorButtonLabel, {
+ className: 'note-fore-color-preview mx-1',
+ title: lang.color.foreground,
+ dropdown: renderer.getTemplate().dropdown(foreColorItems)
+ });
+ var backColorButton = renderer.getTemplate().button(backColorButtonLabel, {
+ className: 'note-back-color-preview mx-1',
+ title: lang.color.background,
+ dropdown: renderer.getTemplate().dropdown(backColorItems)
+ });
+ return recentColorButton + foreColorButton + backColorButton;
+},
+
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
key.nameFromCode[46] = 'DELETE';
@@ -1922,59 +1959,6 @@ $.summernote.pluginEvents.removeFormat = function (event, editor, layoutInfo, va
event.preventDefault();
return false;
};
-var fn_boutton_updateRecentColor = eventHandler.modules.toolbar.button.updateRecentColor;
-eventHandler.modules.toolbar.button.updateRecentColor = function (elBtn, sEvent, sValue) {
- fn_boutton_updateRecentColor.call(this, elBtn, sEvent, sValue);
- var $recentcolor = $.find('.note-recent-color i');
- var $recentcolorbtn = $.find('.note-recent-color');
-
- //find last used color for fonts or for icons
- //set this color into recentcolor button of both font and icon
- for (var i in $recentcolor) {
- var $font = $recentcolor[i];
- var $button = $($recentcolorbtn[i]);
- var className = $font.className.split(/\s+/);
- var k;
- if (sEvent === "foreColor") {
- //set class for forecolor to recentcolor button font-icon
- for (k=2; k<className.length; k++) {
- if (className[k].length && className[k].slice(0,5) === "text-") {
- className.splice(k,1);
- k--;
- }
- }
- if (sValue.indexOf('text-') !== -1) {
- $font.className = className.join(' ') + ' ' + sValue;
- $font.style.color = '';
- } else {
- $font.className = $font.className.replace(/(^|\s+)text-\S+/, '');
- $font.style.color = sValue !== 'inherit' ? sValue : "";
- }
- } else {
- //set class for backcolor to recentcolor button font-icon
- for (k=2; k<className.length; k++) {
- if (className[k].length && className[k].slice(0,3) === "bg-") {
- className.splice(k,1);
- k--;
- }
- }
- if (sValue.indexOf('bg-') !== -1) {
- $font.className =className.join(' ') + ' ' + sValue;
- $font.style.backgroundColor = "";
- } else {
- $font.className = $font.className.replace(/(^|\s+)bg-\S+/, '');
- $font.style.backgroundColor = sValue !== 'inherit' ? sValue : "";
- }
- }
- if (sValue !== 'inherit') {
- //set attribute for color to the recentcolor button
- var colorInfo = JSON.parse($button.attr('data-value'));
- colorInfo[sEvent] = sValue;
- $button.attr('data-value', JSON.stringify(colorInfo));
- }
- }
- return false;
-};
eventHandler.modules.editor.undo = function ($popover) {
if (!$popover.attr('disabled')) $popover.data('NoteHistory').undo();
@@ -1983,6 +1967,15 @@ eventHandler.modules.editor.redo = function ($popover) {
if (!$popover.attr('disabled')) $popover.data('NoteHistory').redo();
};
+// Get color and background color of node to update recent color button
+var fn_from_node = eventHandler.modules.editor.style.fromNode;
+eventHandler.modules.editor.style.fromNode = function ($node) {
+ var styleInfo = fn_from_node.apply(this, arguments);
+ styleInfo['color'] = $node.css('color');
+ styleInfo['background-color'] = $node.css('background-color');
+ return styleInfo;
+};
+
// use image toolbar if current range is on image
var fn_editor_currentstyle = eventHandler.modules.editor.currentStyle;
eventHandler.modules.editor.currentStyle = function (target) {