diff options
| author | Olivier Dony <odo@openerp.com> | 2017-06-01 01:46:13 +0200 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2017-06-01 01:46:13 +0200 |
| commit | 5d2869cbc812f716e3115b5efb9bd1c3082f47b7 (patch) | |
| tree | 364844fc326f0d095997120d10d83e67fdf341e9 /addons/web_editor/static/src/js | |
| parent | 04111cae39e36015d3c8494f52b110ab5ab6ad80 (diff) | |
| parent | ba15df47cb25625cb0921cba554aa0879048c90a (diff) | |
[MERGE] Forward-port saas-16 up to ba15df47cb25625cb0921cba554aa0879048c90a
Diffstat (limited to 'addons/web_editor/static/src/js')
| -rw-r--r-- | addons/web_editor/static/src/js/backend.js | 25 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/rte.summernote.js | 7 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/snippets.editor.js | 22 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/transcoder.js | 10 |
4 files changed, 56 insertions, 8 deletions
diff --git a/addons/web_editor/static/src/js/backend.js b/addons/web_editor/static/src/js/backend.js index 00faf80c70f..c12ab41b4bb 100644 --- a/addons/web_editor/static/src/js/backend.js +++ b/addons/web_editor/static/src/js/backend.js @@ -3,6 +3,7 @@ odoo.define('web_editor.backend', function (require) { var AbstractField = require('web.AbstractField'); var basic_fields = require('web.basic_fields'); +var config = require('web.config'); var core = require('web.core'); var session = require('web.session'); var field_registry = require('web.field_registry'); @@ -23,12 +24,28 @@ var QWeb = core.qweb; */ var FieldTextHtmlSimple = basic_fields.DebouncedField.extend({ className: 'oe_form_field oe_form_field_html_text', + supportedFieldTypes: ['html'], //-------------------------------------------------------------------------- // Public //-------------------------------------------------------------------------- /** + * Summernote doesn't notify for changes done in code mode. We override + * commitChanges to manually switch back to normal mode before committing + * changes, so that the widget is aware of the changes done in code mode. + * + * @override + */ + commitChanges: function () { + // switch to WYSIWYG mode if currently in code mode to get all changes + if (config.debug && this.mode === 'edit') { + var layoutInfo = this.$textarea.data('layoutInfo'); + $.summernote.pluginEvents.codeview(undefined, undefined, layoutInfo, false); + } + this._super.apply(this, arguments); + }, + /** * @override */ isSet: function () { @@ -60,7 +77,7 @@ var FieldTextHtmlSimple = basic_fields.DebouncedField.extend({ * @returns {Object} the summernote configuration */ _getSummernoteConfig: function () { - var config = { + var summernoteConfig = { focus: false, height: 180, toolbar: [ @@ -79,10 +96,10 @@ var FieldTextHtmlSimple = basic_fields.DebouncedField.extend({ lang: "odoo", onChange: this._doDebouncedAction.bind(this), }; - if (this.getSession().debug) { - config.toolbar.splice(7, 0, ['view', ['codeview']]); + if (config.debug) { + summernoteConfig.toolbar.splice(7, 0, ['view', ['codeview']]); } - return config; + return summernoteConfig; }, /** * @override diff --git a/addons/web_editor/static/src/js/rte.summernote.js b/addons/web_editor/static/src/js/rte.summernote.js index 60c096603d8..4ab1e7bed06 100644 --- a/addons/web_editor/static/src/js/rte.summernote.js +++ b/addons/web_editor/static/src/js/rte.summernote.js @@ -511,7 +511,12 @@ function prettify_html(html) { level--; } - result += token.trim().replace(/\s+/, ' '); + // don't trim inline content (which could change appearance) + if (!inline) { + token = token.trim(); + } + + result += token.replace(/\s+/, ' '); if (inline_level > level) { result += '\n'; diff --git a/addons/web_editor/static/src/js/snippets.editor.js b/addons/web_editor/static/src/js/snippets.editor.js index 20a96a91e84..42f2103f95f 100644 --- a/addons/web_editor/static/src/js/snippets.editor.js +++ b/addons/web_editor/static/src/js/snippets.editor.js @@ -107,7 +107,7 @@ data.Class = Widget.extend({ return $from.closest(selector, parentNode); }, all: function ($from) { - return $from ? $from.find(selector) : $(selector); + return $from ? cssFind($from, selector) : $(selector); }, is: function ($from) { return $from.is(selector); @@ -130,15 +130,31 @@ data.Class = Widget.extend({ }); }, all: is_children ? function ($from) { - return ($from || self.$editable).find(selector); + return cssFind($from || self.$editable, selector); } : function ($from) { - return $from ? $from.find(selector) : self.$editable.filter(selector).add(self.$editable.find(selector)); + $from = $from || self.$editable; + return $from.filter(selector).add(cssFind($from, selector)); }, is: function ($from) { return $from.is(selector); } }; } + + /** + * jQuery find function behavior is: + * $('A').find('A B') <=> $('A A B') + * The searches behavior to find options' DOM needs to be + * $('A').find('A B') <=> $('A B') + * This is what this function does. + * + * @param {jQuery} $from - the jQuery element(s) from which to search + * @param {string} selector - the CSS selector to match + * @returns {jQuery} + */ + function cssFind($from, selector) { + return $from.find('*').filter(selector); + } }, fetch_snippet_templates: function () { diff --git a/addons/web_editor/static/src/js/transcoder.js b/addons/web_editor/static/src/js/transcoder.js index 05068972532..6b42e028b3a 100644 --- a/addons/web_editor/static/src/js/transcoder.js +++ b/addons/web_editor/static/src/js/transcoder.js @@ -121,6 +121,16 @@ var getMatchedCSSRules = function (a) { } }); + // text-decoration rule is decomposed in -line, -color and -style. This is + // however not supported by many browser/mail clients and the editor does + // not allow to change -color and -style rule anyway + if (style['text-decoration-line']) { + style['text-decoration'] = style['text-decoration-line']; + delete style['text-decoration-line']; + delete style['text-decoration-color']; + delete style['text-decoration-style']; + } + return style; }; |
