[FIX] web_editor: add thumbnail image to send attachment

This commit is contained in:
Christophe Matthieu
2018-02-08 11:25:51 +01:00
parent 6494f51171
commit ae39a89a09
3 changed files with 32 additions and 0 deletions
@@ -118,6 +118,7 @@ var FieldTextHtmlSimple = basic_fields.DebouncedField.extend(TranslatableFieldMi
*/
_getValue: function () {
if (this.nodeOptions['style-inline']) {
transcoder.linkImgToAttachmentThumbnail(this.$content);
transcoder.classToStyle(this.$content);
transcoder.fontToImg(this.$content);
}
@@ -259,10 +259,40 @@ function styleToClass($editable) {
$c.remove();
}
/**
* Converts css display for attachment link to real image.
* Without this post process, the display depends on the css and the picture
* does not appear when we use the html without css (to send by email for e.g.)
*
* @param {jQuery} $editable
*/
function attachmentThumbnailToLinkImg($editable) {
$editable.find('a[href*="/web/content/"][data-mimetype]:empty').each(function () {
var $link = $(this);
var $img = $('<img/>')
.attr('src', $link.css('background-image').replace(/(^url\(['"])|(['"]\)$)/g, ''))
.css('height', Math.max(1, $link.height()) + 'px')
.css('width', Math.max(1, $link.width()) + 'px');
$link.append($img);
});
}
/**
* Revert attachmentThumbnailToLinkImg changes
*
* @see attachmentThumbnailToLinkImg
* @param {jQuery} $editable
*/
function linkImgToAttachmentThumbnail($editable) {
$editable.find('a[href*="/web/content/"][data-mimetype] > img').remove();
}
return {
fontToImg: fontToImg,
imgToFont: imgToFont,
classToStyle: classToStyle,
styleToClass: styleToClass,
attachmentThumbnailToLinkImg: attachmentThumbnailToLinkImg,
linkImgToAttachmentThumbnail: linkImgToAttachmentThumbnail,
};
});
@@ -53,6 +53,7 @@ snippet_editor.Class.include({
this._super.apply(this, arguments);
var $editable = $('#editable_area');
transcoder.linkImgToAttachmentThumbnail($editable);
transcoder.fontToImg($editable);
transcoder.classToStyle($editable);