diff options
| author | Christophe Simonis <chs@odoo.com> | 2018-01-26 16:06:51 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2018-01-26 16:06:51 +0100 |
| commit | bcf6529755b01f00552eaca9171b8a21a71b2f70 (patch) | |
| tree | 55cb0860eff7abd6069870051f0133fed05de13a /addons/web_editor/static/src | |
| parent | 4ea4f99df99e0f8d6e01b3116020cd1b525ec1fd (diff) | |
| parent | 8e38a3d069cd3bb63bbfbe1ca8a7db9d2eda6263 (diff) | |
[MERGE] forward port branch 10.0 up to 8e38a3d069c
Diffstat (limited to 'addons/web_editor/static/src')
| -rw-r--r-- | addons/web_editor/static/src/js/base.js | 9 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/rte.js | 44 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/rte.summernote.js | 3 | ||||
| -rw-r--r-- | addons/web_editor/static/src/js/summernote.js | 12 |
4 files changed, 37 insertions, 31 deletions
diff --git a/addons/web_editor/static/src/js/base.js b/addons/web_editor/static/src/js/base.js index ac36b706f50..f7ba58ac636 100644 --- a/addons/web_editor/static/src/js/base.js +++ b/addons/web_editor/static/src/js/base.js @@ -32,14 +32,13 @@ data.dom_ready = dom_ready; var all_ready; data.ready = function () { if (!all_ready) { - all_ready = $.when(dom_ready, ajax.loadXML()); + all_ready = dom_ready; if (!odoo._modules) { - all_ready.then(load_translations); + all_ready = all_ready.then(load_translations); } - } else { // can add async template - all_ready = $.when(dom_ready, ajax.loadXML()); } - return all_ready; + // also load new templates since previous ready call + return $.when(all_ready, ajax.loadXML()); }; function load_translations() { diff --git a/addons/web_editor/static/src/js/rte.js b/addons/web_editor/static/src/js/rte.js index 9ce1e5fb255..595602d6305 100644 --- a/addons/web_editor/static/src/js/rte.js +++ b/addons/web_editor/static/src/js/rte.js @@ -280,7 +280,15 @@ var RTE = Widget.extend({ } else { rng = $editable.data('range') || rng; } - rng.select(); + try { + // TODO this line might break for unknown reasons. I suppose that + // the created range is an invalid one. As it might be tricky to + // adapt that line and that it is not a critical one, temporary fix + // is to ignore the errors that this generates. + rng.select(); + } catch (e) { + console.log('error', e); + } history.recordUndo($editable, event, internal_history); }, /** @@ -567,8 +575,8 @@ var RTE = Widget.extend({ onEnableEditableArea: function ($editable) { }, - onMouseup: function (event) { - var $target = $(event.target); + onMouseup: function (ev) { + var $target = $(ev.target); var $editable = $target.closest('.o_editable'); if (!$editable.length) { @@ -580,26 +588,16 @@ var RTE = Widget.extend({ self.historyRecordUndo($target, 'activate', true); }); - // To Fix Google Chrome Tripleclick Issue, which selects the ending - // whitespace characters (so Tripleclicking then typing text will remove - // the whole paragraph instead of its content). - // http://stackoverflow.com/questions/38467334/why-does-google-chrome-always-add-space-after-selected-text - if ($.browser.chrome === true && event.originalEvent.detail === 3) { - var currentSelection = range.create(); - if (currentSelection.sc.parentNode === currentSelection.ec) { - _selectSC(currentSelection); - } else if (currentSelection.eo === 0) { - var $hasNext = $(currentSelection.sc).parent(); - while (!$hasNext.next().length && !$hasNext.is('body')) { - $hasNext = $hasNext.parent(); - } - if ($hasNext.next()[0] === currentSelection.ec) { - _selectSC(currentSelection); - } - } - } - function _selectSC(selection) { - range.create(selection.sc, selection.so, selection.sc, selection.sc.length).select(); + // Browsers select different content from one to another after a + // triple click (especially: if triple-clicking on a paragraph on + // Chrome, blank characters of the element following the paragraph are + // selected too) + // + // The triple click behavior is reimplemented for all browsers here + if (ev.originalEvent.detail === 3) { + // Select the whole content inside the deepest DOM element that was + // triple-clicked + range.create(ev.target, 0, ev.target, ev.target.childNodes.length).select(); } }, diff --git a/addons/web_editor/static/src/js/rte.summernote.js b/addons/web_editor/static/src/js/rte.summernote.js index 5f28c9510bb..b8f3198dae2 100644 --- a/addons/web_editor/static/src/js/rte.summernote.js +++ b/addons/web_editor/static/src/js/rte.summernote.js @@ -422,6 +422,9 @@ dom.isImg = function (node) { }; var fn_is_forbidden_node = dom.isForbiddenNode || function () {}; dom.isForbiddenNode = function (node) { + if (node.tagName === "BR") { + return false; + } return fn_is_forbidden_node(node) || $(node).is(".media_iframe_video"); }; var fn_is_img_font = dom.isImgFont || function () {}; diff --git a/addons/web_editor/static/src/js/summernote.js b/addons/web_editor/static/src/js/summernote.js index 35e49346ee0..a3e3db42a71 100644 --- a/addons/web_editor/static/src/js/summernote.js +++ b/addons/web_editor/static/src/js/summernote.js @@ -703,10 +703,16 @@ dom.isRemovableEmptyNode = function (node) { dom.isForbiddenNode = function (node) { return node.tagName === "BR" || $(node).is(".fa, img"); }; -dom.listBetween = function (sc, ec) { +/** + * @todo 'so' and 'eo' were added as a bugfix and are not given everytime. They + * however should be as the function may be wrong without them (for example, + * when asking the list between an element and its parent, as there is no path + * from the beginning of the former to the beginning of the later). + */ +dom.listBetween = function (sc, ec, so, eo) { var nodes = []; var ancestor = dom.commonAncestor(sc, ec); - dom.walkPoint({'node': sc, 'offset': 0}, {'node': ec, 'offset': 0}, function (point) { + dom.walkPoint({'node': sc, 'offset': so || 0}, {'node': ec, 'offset': eo || 0}, function (point) { if (ancestor !== point.node || ancestor === sc || ancestor === ec) { nodes.push(point.node); } @@ -1926,7 +1932,7 @@ $.summernote.pluginEvents.formatBlock = function (event, editor, layoutInfo, sTa } // fix by odoo because if you select a style in a li with no p tag all the ul is wrapped by the style tag - var nodes = dom.listBetween(r.sc, r.ec); + var nodes = dom.listBetween(r.sc, r.ec, r.so, r.eo); for (var i=0; i<nodes.length; i++) { if (dom.isBR(nodes[i]) || (dom.isText(nodes[i]) && dom.isVisibleText(nodes[i])) || dom.isB(nodes[i]) || dom.isU(nodes[i]) || dom.isS(nodes[i]) || dom.isI(nodes[i]) || dom.isFont(nodes[i])) { var ancestor = dom.ancestor(nodes[i], isFormatNode); |
