diff options
| author | Christophe Matthieu <chm@odoo.com> | 2016-06-13 11:37:09 +0200 |
|---|---|---|
| committer | Christophe Matthieu <chm@odoo.com> | 2016-06-22 14:26:42 +0200 |
| commit | f38f8930f0436a40f675fa1d054a9d46f550d440 (patch) | |
| tree | 26910c115139b3462c9ca5a0267024a8aeaec502 /addons/web_editor/static/src/js/inline.js | |
| parent | cecc12ffc6a26ae61319b358f69d9fc5e0ad5bcc (diff) | |
[FIX] web_editor: test jinja content to load editor in codeview
The preview change the content because the browser try to fix the dom.
If a user use jinja and activate the preview, the jinja code is (re)moved by the browser and broke the template.
Diffstat (limited to 'addons/web_editor/static/src/js/inline.js')
| -rw-r--r-- | addons/web_editor/static/src/js/inline.js | 70 |
1 files changed, 39 insertions, 31 deletions
diff --git a/addons/web_editor/static/src/js/inline.js b/addons/web_editor/static/src/js/inline.js index 2b6ee1c6595..6e047537262 100644 --- a/addons/web_editor/static/src/js/inline.js +++ b/addons/web_editor/static/src/js/inline.js @@ -6,6 +6,45 @@ var rte = require('web_editor.rte'); var widget = require('web_editor.widget'); var transcoder = require('web_editor.transcoder'); var snippet_editor = require('web_editor.snippet.editor'); +var summernote = require('web_editor.rte.summernote'); +var pluginEvents = summernote.pluginEvents; +var dom = summernote.core.dom; + +var _html = dom.html; +dom.html = function ($dom, prettifyHtml) { + if (prettifyHtml) { + transcoder.font_to_img($dom); + transcoder.class_to_style($dom); + + // fix outlook image rendering bug + _.each(['width', 'height'], function(attribute) { + $dom.find('img[style*="width"], img[style*="height"]').attr(attribute, function(){ + return $(this)[attribute](); + }).css(attribute, function(){ + return $(this).get(0).style[attribute] || 'auto'; + }); + }); + } + return _html($dom, prettifyHtml); +}; + +var _value = dom.value; +dom.value = function ($dom, stripLinebreaks, $editable) { + var value = _value($dom, stripLinebreaks); + if (stripLinebreaks) { + $editable = $editable || $('<div/>'); + $editable.html(value); + transcoder.img_to_font($editable); + transcoder.style_to_class($editable); + + // fix outlook image rendering bug + $editable.find('img[style*="width"], img[style*="height"]').removeAttr('height width'); + + value = $editable.html(); + } + return value; +}; + widget.MediaDialog.include({ start: function () { @@ -37,37 +76,6 @@ editor.Class.include({ }, }); -snippet_editor.Class.include({ - start: function () { - var self = this; - this._super(); - setTimeout(function () { - var $editable = $("#editable_area"); - transcoder.img_to_font($editable); - transcoder.style_to_class($editable); - - // fix outlook image rendering bug - $editable.find('img[style*="width"], img[style*="height"]').removeAttr('height width'); - }); - }, - clean_for_save: function () { - this._super(); - var $editable = $("#editable_area"); - transcoder.font_to_img($editable); - transcoder.class_to_style($editable); - - // fix outlook image rendering bug - _.each(['width', 'height'], function(attribute) { - $editable.find('img[style*="width"], img[style*="height"]').attr(attribute, function(){ - return $(this)[attribute](); - }).css(attribute, function(){ - return $(this).get(0).style[attribute] || 'auto'; - }); - }); - }, - -}); - window.top.odoo[callback+"_updown"] = function (value, fields_values) { var $editable = $("#editable_area"); value = value || ""; |
