diff --git a/addons/mass_mailing/static/src/js/mass_mailing_widget.js b/addons/mass_mailing/static/src/js/mass_mailing_widget.js index d8000b201eb..9312ffc3053 100644 --- a/addons/mass_mailing/static/src/js/mass_mailing_widget.js +++ b/addons/mass_mailing/static/src/js/mass_mailing_widget.js @@ -72,26 +72,7 @@ var MassMailingFieldHtml = FieldHtml.extend({ self._isDirty = self.wysiwyg.isDirty(); self._doAction(); - // fix outlook image rendering bug (this change will be kept in both - // fields) - _.each(['width', 'height'], function (attribute) { - $editable.find('img').attr(attribute, function () { - return $(this)[attribute](); - }).css(attribute, function () { - return $(this).get(0).style[attribute] || attribute === 'width' ? $(this)[attribute]() + 'px' : ''; - }); - }); - - convertInline.attachmentThumbnailToLinkImg($editable); - convertInline.fontToImg($editable); - convertInline.classToStyle($editable, self.cssRules); - convertInline.bootstrapToTable($editable); - convertInline.cardToTable($editable); - convertInline.listGroupToTable($editable); - convertInline.addTables($editable); - convertInline.formatTables($editable); - convertInline.normalizeColors($editable); - convertInline.normalizeRem($editable); + convertInline.toInline($editable, self.cssRules); self.trigger_up('field_changed', { dataPointID: self.dataPointID, diff --git a/addons/web_editor/static/src/js/backend/convert_inline.js b/addons/web_editor/static/src/js/backend/convert_inline.js index 9104c2107d3..92ed8ec23a9 100644 --- a/addons/web_editor/static/src/js/backend/convert_inline.js +++ b/addons/web_editor/static/src/js/backend/convert_inline.js @@ -323,6 +323,42 @@ function classToStyle($editable, cssRules) { } }); } +/** + * Convert the contents of an editable area (as a JQuery element) into content + * that is widely compatible with email clients. If no CSS Rules are given, they + * will be computed for the editable element's owner document. + * + * @param {JQuery} $editable + * @param {Object[]} [cssRules] Array<{selector: string; + * style: {[styleName]: string}; + * specificity: number;}> + */ +function toInline($editable, cssRules) { + if (!cssRules) { + cssRules = getCSSRules($editable[0].ownerDocument); + } + + // Fix outlook image rendering bug (this change will be kept in both + // fields). + _.each(['width', 'height'], function (attribute) { + $editable.find('img').attr(attribute, function () { + return $(this)[attribute](); + }).css(attribute, function () { + return $(this).get(0).style[attribute] || attribute === 'width' ? $(this)[attribute]() + 'px' : ''; + }); + }); + + attachmentThumbnailToLinkImg($editable); + fontToImg($editable); + classToStyle($editable, cssRules); + bootstrapToTable($editable); + cardToTable($editable); + listGroupToTable($editable); + addTables($editable); + formatTables($editable); + normalizeColors($editable); + normalizeRem($editable); +} /** * Convert font icons to images. * @@ -953,25 +989,7 @@ FieldHtml.include({ $odooEditor.removeClass('odoo-editor'); $editable.html(html); - attachmentThumbnailToLinkImg($editable); - fontToImg($editable); - classToStyle($editable, this.cssRules); - bootstrapToTable($editable); - cardToTable($editable); - listGroupToTable($editable); - addTables($editable); - formatTables($editable); - normalizeColors($editable); - normalizeRem($editable); - - // fix outlook image rendering bug - _.each(['width', 'height'], function(attribute) { - $editable.find('img').attr(attribute, function(){ - return $(this)[attribute](); - }).css(attribute, function(){ - return $(this).get(0).style[attribute] || attribute === 'width' ? $(this)[attribute]() + 'px' : ''; - }); - }); + toInline($editable, this.cssRules); $odooEditor.addClass('odoo-editor'); this.wysiwyg.setValue($editable.html(), {