diff options
| author | Christophe Simonis <chs@odoo.com> | 2018-01-02 15:02:26 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2018-01-02 15:02:26 +0100 |
| commit | ddd293065eccd005327139c9963cf1cdf5ab3cde (patch) | |
| tree | 83d390ee7de4ef290726661f51662328ada10a15 /addons/web_editor/static/src | |
| parent | 3415a8712f262035945c9a4c0ad135d0b0cde856 (diff) | |
| parent | ba2a83ddfac149715846113b07d361fa2c63a7f5 (diff) | |
[MERGE] forward port branch saas-14 up to ba2a83ddfac
Diffstat (limited to 'addons/web_editor/static/src')
| -rw-r--r-- | addons/web_editor/static/src/js/base.js | 13 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/summernote.js | 71 |
2 files changed, 56 insertions, 28 deletions
diff --git a/addons/web_editor/static/src/js/base.js b/addons/web_editor/static/src/js/base.js index 4368f6de274..ac36b706f50 100644 --- a/addons/web_editor/static/src/js/base.js +++ b/addons/web_editor/static/src/js/base.js @@ -32,14 +32,11 @@ data.dom_ready = dom_ready; var all_ready; data.ready = function () { if (!all_ready) { - all_ready = $.when(dom_ready, ajax.loadXML()).then(function () { - // TODO find a better way to find if we are in the backend or not - // We don't load translation if we are in the backend since it's already done by the webclient - if (!$(document).find('.o_web_client').length) { - return load_translations(); - } - }); - } else if(all_ready.state() === "resolved") { // can add async template + all_ready = $.when(dom_ready, ajax.loadXML()); + if (!odoo._modules) { + all_ready.then(load_translations); + } + } else { // can add async template all_ready = $.when(dom_ready, ajax.loadXML()); } return all_ready; diff --git a/addons/web_editor/static/src/js/summernote.js b/addons/web_editor/static/src/js/summernote.js index fe2ff837142..e439f52824a 100644 --- a/addons/web_editor/static/src/js/summernote.js +++ b/addons/web_editor/static/src/js/summernote.js @@ -19,6 +19,57 @@ 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 method to Summernote*/ @@ -2319,26 +2370,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; |
