summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web_editor/static/src')
-rw-r--r--addons/web_editor/static/src/js/backend/fields.js33
-rw-r--r--addons/web_editor/static/src/js/editor/summernote.js75
2 files changed, 72 insertions, 36 deletions
diff --git a/addons/web_editor/static/src/js/backend/fields.js b/addons/web_editor/static/src/js/backend/fields.js
index 95afaa90073..cbdb6cbb88b 100644
--- a/addons/web_editor/static/src/js/backend/fields.js
+++ b/addons/web_editor/static/src/js/backend/fields.js
@@ -221,7 +221,8 @@ var FieldTextHtml = AbstractField.extend({
start: function () {
var self = this;
- this.loaded = false;
+ this.editorLoadedDeferred = $.Deferred();
+ this.contentLoadedDeferred = $.Deferred();
this.callback = _.uniqueId('FieldTextHtml_');
window.odoo[this.callback+"_editor"] = function (EditorBar) {
setTimeout(function () {
@@ -312,8 +313,6 @@ var FieldTextHtml = AbstractField.extend({
old_initialize_content: function () {
this.$el.closest('.modal-body').css('max-height', 'none');
this.$iframe = this.$el.find('iframe');
- // deactivate any button to avoid saving a not ready iframe
- $('.o_cp_buttons, .o_statusbar_buttons').find('button').addClass('o_disabled').attr('disabled', true);
this.document = null;
this.$body = $();
this.$content = $();
@@ -328,9 +327,7 @@ var FieldTextHtml = AbstractField.extend({
this.$content = this.$body.find("#editable_area");
this.render();
this.add_button();
- this.loaded = true;
- // reactivate all the buttons when the field's content (the iframe) is loaded
- $('.o_cp_buttons, .o_statusbar_buttons').find('button').removeClass('o_disabled').attr('disabled', false);
+ this.contentLoadedDeferred.resolve();
setTimeout(self.resize, 0);
},
on_editor_loaded: function (EditorBar) {
@@ -339,6 +336,7 @@ var FieldTextHtml = AbstractField.extend({
if (this.value && window.odoo[self.callback+"_updown"] && !(this.$content.html()||"").length) {
this.render();
}
+ this.editorLoadedDeferred.resolve();
setTimeout(function () {
setTimeout(self.resize,0);
}, 0);
@@ -395,20 +393,25 @@ var FieldTextHtml = AbstractField.extend({
//--------------------------------------------------------------------------
/**
+ * Set the value when the widget is fully loaded (content + editor).
+ *
* @override
*/
commitChanges: function () {
- if (!this.loaded || this.mode === 'readonly') {
+ var self = this;
+ var result = this._super.bind(this, arguments);
+ if (this.mode === 'readonly') {
return;
}
- // switch to WYSIWYG mode if currently in code mode to get all changes
- if (config.debug && this.mode === 'edit' && this.editor.rte) {
- var layoutInfo = this.editor.rte.editable().data('layoutInfo');
- $.summernote.pluginEvents.codeview(undefined, undefined, layoutInfo, false);
- }
- this.editor.snippetsMenu && this.editor.snippetsMenu.cleanForSave();
- this._setValue(this.$content.html());
- return this._super.apply(this, arguments);
+ return $.when(this.contentLoadedDeferred, this.editorLoadedDeferred, result).then(function () {
+ // switch to WYSIWYG mode if currently in code mode to get all changes
+ if (config.debug && self.editor.rte) {
+ var layoutInfo = self.editor.rte.editable().data('layoutInfo');
+ $.summernote.pluginEvents.codeview(undefined, undefined, layoutInfo, false);
+ }
+ self.editor.snippetsMenu && self.editor.snippetsMenu.cleanForSave();
+ self._setValue(self.$content.html());
+ });
},
});
diff --git a/addons/web_editor/static/src/js/editor/summernote.js b/addons/web_editor/static/src/js/editor/summernote.js
index 33bf1f38046..d6f9805599e 100644
--- a/addons/web_editor/static/src/js/editor/summernote.js
+++ b/addons/web_editor/static/src/js/editor/summernote.js
@@ -13,11 +13,64 @@ var range = $.summernote.core.range;
var list = $.summernote.core.list;
var key = $.summernote.core.key;
var eventHandler = $.summernote.eventHandler;
-// var editor = eventHandler.modules.editor;
+var editor = eventHandler.modules.editor;
var renderer = $.summernote.renderer;
var options = $.summernote.options;
+// Browser-unify execCommand
+var oldJustify = {};
+_.each(['Left', 'Right', 'Full', 'Center'], function (align) {
+ oldJustify[align] = editor['justify' + align];
+ editor['justify' + align] = function ($editable, value) {
+ // Before calling the standard function, check all elements which have
+ // an 'align' attribute and mark them with their value
+ var $align = $editable.find('[align]');
+ _.each($align, function (el) {
+ var $el = $(el);
+ $el.data('__align', $el.attr('align'));
+ });
+
+ // Call the standard function
+ oldJustify[align].apply(this, arguments);
+
+ // Then:
+
+ // Remove the text-align of elements which lost the 'align' attribute
+ var $newAlign = $editable.find('[align]');
+ $align.not($newAlign).css('text-align', '');
+
+ // Transform the 'align' attribute into the 'text-align' css
+ // property for elements which received the 'align' attribute or whose
+ // 'align' attribute changed
+ _.each($newAlign, function (el) {
+ var $el = $(el);
+
+ var oldAlignValue = $align.data('__align');
+ var alignValue = $el.attr('align');
+ if (oldAlignValue === alignValue) {
+ // If the element already had an 'align' attribute and that it
+ // did not changed, do nothing (compatibility)
+ return;
+ }
+
+ $el.removeAttr('align');
+ $el.css('text-align', alignValue);
+
+ // Note the first step (removing the text-align of elemnts which
+ // lost the 'align' attribute) is kinda the same as this one, but
+ // this one handles the elements which have been edited with chrome
+ // or with this new system
+ $el.find('*').css('text-align', '');
+ });
+
+ // Unmark the elements
+ $align.removeData('__align');
+ };
+});
+
+
// Add methods to summernote
+
dom.hasContentAfter = function (node) {
var next;
if (dom.isEditable(node)) return;
@@ -2289,26 +2342,6 @@ eventHandler.modules.popover.update = function ($popover, oStyle, isAirMode) {
}
};
-// override summernote clipboard functionality
-eventHandler.modules.clipboard.attach = function (layoutInfo) {
- var $editable = layoutInfo.editable();
- $editable.on('paste', function (e) {
- var clipboardData = ((e.originalEvent || e).clipboardData || window.clipboardData);
- // Change nothing if pasting html (copy from text editor / web / ...) or
- // if clipboardData is not available (IE / ...)
- if (clipboardData && clipboardData.types && clipboardData.types.length === 1 && clipboardData.types[0] === "text/plain") {
- e.preventDefault();
- $editable.data('NoteHistory').recordUndo($editable); // FIXME
- var pastedText = clipboardData.getData("text/plain");
- // Try removing linebreaks which are not really linebreaks (in a PDF,
- // when a sentence goes over the next line, copying it considers it
- // a linebreak for example).
- var formattedText = pastedText.replace(/([\w-])\r?\n([\w-])/g, "$1 $2").trim();
- document.execCommand("insertText", false, formattedText);
- }
- });
-};
-
var fn_attach = eventHandler.attach;
eventHandler.attach = function (oLayoutInfo, options) {
var $editable = oLayoutInfo.editor().hasClass('note-editable') ? oLayoutInfo.editor() : oLayoutInfo.editor().find('.note-editable');