diff options
| author | Christophe Simonis <chs@odoo.com> | 2018-05-29 17:34:43 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2018-05-29 17:34:43 +0200 |
| commit | f36e6917bd73a56dc0c7468b4849920df4088154 (patch) | |
| tree | b63d02ae3e5ffc0815de009407363e0cf906f547 /addons/web_editor/static/src/js/editor | |
| parent | bc0173c2d58ac26d80cb2f483a95c0c13b047dab (diff) | |
| parent | 37eed7c509fb5846c89ef37046df4b3cab299719 (diff) | |
[MERGE] forward port branch saas-11.3 up to 37eed7c509f
Diffstat (limited to 'addons/web_editor/static/src/js/editor')
| -rw-r--r-- | addons/web_editor/static/src/js/editor/rte.js | 8 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/editor/rte.summernote.js | 4 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/editor/transcoder.js | 40 |
3 files changed, 39 insertions, 13 deletions
diff --git a/addons/web_editor/static/src/js/editor/rte.js b/addons/web_editor/static/src/js/editor/rte.js index 44f69fc2026..b4a42f843c8 100644 --- a/addons/web_editor/static/src/js/editor/rte.js +++ b/addons/web_editor/static/src/js/editor/rte.js @@ -270,7 +270,13 @@ var RTEWidget = Widget.extend({ $.fn.carousel = this.edit_bootstrap_carousel; $(document).on('click.rte keyup.rte', function () { - var $popover = $((range.create()||{}).sc).closest('[contenteditable]'); + var current_range = {}; + try { + current_range = range.create() || {}; + } catch (e) { + // if range is on Restricted element ignore error + } + var $popover = $(current_range.sc).closest('[contenteditable]'); var popover_history = ($popover.data()||{}).NoteHistory; if (!popover_history || popover_history === history) return; var editor = $popover.parent('.note-editor'); diff --git a/addons/web_editor/static/src/js/editor/rte.summernote.js b/addons/web_editor/static/src/js/editor/rte.summernote.js index 8d9d19be795..ce20c53ff49 100644 --- a/addons/web_editor/static/src/js/editor/rte.summernote.js +++ b/addons/web_editor/static/src/js/editor/rte.summernote.js @@ -403,7 +403,7 @@ eventHandler.modules.imageDialog.showImageDialog = function ($editable) { media: media, options: { lastFilters: ['background'], - onUpload: $editable.data('callbacks').onImageUpload, + onUpload: $editable.data('callbacks').onUpload, }, }); return new $.Deferred().reject(); @@ -689,7 +689,7 @@ function summernote_mousedown(event) { return; } var editables = $(".o_editable[contenteditable], .note-editable[contenteditable]"); - var r_editable = editables.has((r||{}).sc); + var r_editable = editables.has((r||{}).sc).addBack(editables.filter((r||{}).sc)); if (!r_editable.closest('.note-editor').is($editable) && !r_editable.filter('.o_editable').is(editables)) { var saved_editable = editables.has((remember_selection||{}).sc); if ($editable.length && !saved_editable.closest('.o_editable, .note-editor').is($editable)) { diff --git a/addons/web_editor/static/src/js/editor/transcoder.js b/addons/web_editor/static/src/js/editor/transcoder.js index 4fa30978f84..fb3e69eda29 100644 --- a/addons/web_editor/static/src/js/editor/transcoder.js +++ b/addons/web_editor/static/src/js/editor/transcoder.js @@ -227,6 +227,26 @@ function imgToFont($editable) { }); } +/* + * Utility function to apply function over descendants elements + * + * This is needed until the following issue of jQuery is solved: + * https://github.com./jquery/sizzle/issues/403 + * + * @param {Element} node The root Element node + * @param {Function} func The function applied over descendants + */ +function applyOverDescendants(node, func) { + node = node.firstChild; + while (node) { + if (node.nodeType === 1) { + func(node); + applyOverDescendants(node, func); + } + node = node.nextSibling; + } +} + /** * Converts css style to inline style (leave the classes on elements but forces * the style they give as inline style). @@ -237,9 +257,9 @@ function classToStyle($editable) { if (!rulesCache.length) { getMatchedCSSRules($editable[0]); } - $editable.find('*').each(function () { - var $target = $(this); - var css = getMatchedCSSRules(this); + applyOverDescendants($editable[0], function (node) { + var $target = $(node); + var css = getMatchedCSSRules(node); var style = $target.attr('style') || ''; _.each(css, function (v,k) { if (!(new RegExp('(^|;)\s*' + k).test(style))) { @@ -252,12 +272,12 @@ function classToStyle($editable) { $target.attr('style', style); } // Apple Mail - if (this.nodeName === 'TD' && !this.childNodes.length) { - this.innerHTML = ' '; + if (node.nodeName === 'TD' && !node.childNodes.length) { + node.innerHTML = ' '; } // Outlook - if (this.nodeName === 'A' && $target.hasClass('btn') && !$target.children().length) { + if (node.nodeName === 'A' && $target.hasClass('btn') && !$target.children().length) { var $hack = $('<table class="o_outlook_hack"><tr><td></td></tr></table>'); $hack.find('td') .attr('height', $target.outerHeight()) @@ -269,7 +289,7 @@ function classToStyle($editable) { $target.after($hack); $target.appendTo($hack.find('td')); // the space add a line when it's a table but it's invisible when it's a link - var node = $hack[0].previousSibling; + node = $hack[0].previousSibling; if (node && node.nodeType === Node.TEXT_NODE && !node.textContent.match(/\S/)) { $(node).remove(); } @@ -297,9 +317,9 @@ function styleToClass($editable) { var $c = $('<span/>').appendTo(document.body); - $editable.find('*').each(function () { - var $target = $(this); - var css = getMatchedCSSRules(this); + applyOverDescendants($editable[0], function (node) { + var $target = $(node); + var css = getMatchedCSSRules(node); var style = ''; _.each(css, function (v,k) { if (!(new RegExp('(^|;)\s*' + k).test(style))) { |
