diff options
| author | Christophe Simonis <chs@odoo.com> | 2018-02-09 16:13:08 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2018-02-09 16:13:08 +0100 |
| commit | 5f3301e5cbbb2c6e7bff732761eef80e8dd5a33d (patch) | |
| tree | 48ab6bd9bbda92dea713c0c52bca3396ef939d82 /addons/web_editor/static/src/js/editor/transcoder.js | |
| parent | 715e602bf04ae5a0c9704c599f2145b2808b31b7 (diff) | |
| parent | 20e4cd5bcd1816a478aedd441efa90a34cf63334 (diff) | |
[MERGE] forward port branch 11.0 up to 20e4cd5bcd1
Diffstat (limited to 'addons/web_editor/static/src/js/editor/transcoder.js')
| -rw-r--r-- | addons/web_editor/static/src/js/editor/transcoder.js | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/addons/web_editor/static/src/js/editor/transcoder.js b/addons/web_editor/static/src/js/editor/transcoder.js index 11d23bf603b..54bbc803645 100644 --- a/addons/web_editor/static/src/js/editor/transcoder.js +++ b/addons/web_editor/static/src/js/editor/transcoder.js @@ -18,7 +18,7 @@ function getMatchedCSSRules(a) { var sheets = document.styleSheets; for (i = sheets.length-1 ; i >= 0 ; i--) { var rules; - if (sheets[i].rules) { + if (sheets[i].hasOwnProperty('rules')) { rules = sheets[i].rules; } else { // try...catch because Firefox not able to enumerate @@ -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, }; }); |
