[FIX] web_editor: use iframe instead of direct content for preview

The preview is not equal to the real email rendering because the backend css is present.
This commit is contained in:
Christophe Matthieu
2016-01-18 17:09:01 +01:00
parent 990597ba1c
commit 4e0e376b0a
2 changed files with 23 additions and 3 deletions
+5 -1
View File
@@ -5,8 +5,12 @@
line-height: initial !important;
color: initial !important;
}
.oe_form_field_html_text .note-editable.o_readonly {
.oe_form_field_html_text iframe.o_readonly {
min-height: 1em;
width: 100%;
margin: 0;
padding: 0;
border: 0;
}
.oe_form_field_html_text .note-editable p {
margin: initial;
+18 -2
View File
@@ -62,9 +62,15 @@ var FieldTextHtmlSimple = widget.extend({
initialize_content: function() {
var self = this;
this.$textarea = this.$("textarea").val(this.get('value') || "<p><br/></p>");
this.$content = $();
if (this.get("effective_readonly")) {
this.$textarea.hide().after('<div class="note-editable o_readonly"/>');
this.$textarea.hide().after('<iframe class="o_readonly"/>');
setTimeout(function () {
self.$content = $("body", self.$('iframe').contents()[0]);
self.$content.html(self.text_to_html(self.get('value')));
self.resize();
});
} else {
this.$textarea.summernote(this._config());
@@ -77,8 +83,10 @@ var FieldTextHtmlSimple = widget.extend({
var reset = _.bind(this.reset_history, this);
this.view.on('load_record', this, reset);
setTimeout(reset, 0);
this.$content = this.$('.note-editable:first');
transcoder.style_to_class(this.$content);
}
this.$content = this.$('.note-editable:first');
$(".oe-view-manager-content").on("scroll", function () {
$('.o_table_handler').remove();
@@ -113,10 +121,18 @@ var FieldTextHtmlSimple = widget.extend({
return this.$content.focus();
};
},
resize: function() {
this.$('iframe').css('height', '0px').css('height', Math.max(180, Math.min(this.$content[0] ? this.$content[0].scrollHeight : 0, 500)) + 'px');
},
render_value: function() {
var value = this.get('value');
this.$textarea.val(value || '');
this.$content.html(this.text_to_html(value));
if (this.get("effective_readonly")) {
this.resize();
} else {
transcoder.style_to_class(this.$content);
}
if (this.$content.is(document.activeElement)) {
this.focus();
}