diff options
| author | qdp-odoo <qdp@odoo.com> | 2017-12-15 16:58:40 +0100 |
|---|---|---|
| committer | qdp-odoo <qdp@odoo.com> | 2017-12-15 16:58:40 +0100 |
| commit | 78ae6f470b06bcb93afaaedb393eb58a97dc20f0 (patch) | |
| tree | 6d22838ced833f9eeb5fa66cb0204784420c7534 /addons/web_editor/static | |
| parent | 601bf82ba9e9cd7037ba5fdfc0dec483b72e10f6 (diff) | |
| parent | 9bba7fea42be534fd100d809dfd1dc632ee9ace4 (diff) | |
[MERGE] forward port branch 9.0 up to 9bba7fea42be534fd100d809dfd1dc632ee9ace4
Diffstat (limited to 'addons/web_editor/static')
| -rw-r--r-- | addons/web_editor/static/src/js/summernote.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/addons/web_editor/static/src/js/summernote.js b/addons/web_editor/static/src/js/summernote.js index fe2ff837142..af5e0112e38 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*/ |
