From 78a556601e6b1e72c6d1ac776e31588dd2ffa28f Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Tue, 23 Jan 2018 14:10:48 +0100 Subject: [FIX] web_editor: prevent crash when dropping snippets For some unknown reasons, the editor sometimes crashes when dropping a snippet. As a temporary fix, the non-critical line that causes the problem is try/catch protected by this commit. --- addons/web_editor/static/src/js/rte.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'addons/web_editor/static/src') diff --git a/addons/web_editor/static/src/js/rte.js b/addons/web_editor/static/src/js/rte.js index 20c70e9d235..7748ccf7762 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); }, /** -- cgit v1.2.3 From 2fad2e43b855e728f0534012012ec3720035768c Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Tue, 23 Jan 2018 16:16:20 +0100 Subject: [FIX] web_editor: solve all triple-click issues ... hopefully. This *must* be forward-ported. Depending on the browser, the triple-click behavior is different. This is especially problematic on Chrome, where blank characters at the start of the neighbor of the clicked element are selected. A weak attempt to solve that was made by commit https://github.com/odoo/odoo/commit/b85bd358234684974f9af63bc5f28cfabb527767 This commit hopes to solve all the issues once and for all by fully reimplementing the triple-click for all browsers. The concept is simple: when a triple-click occurs, select the whole *inner* content of the deepest DOM *element* that was clicked. --- addons/web_editor/static/src/js/rte.js | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) (limited to 'addons/web_editor/static/src') diff --git a/addons/web_editor/static/src/js/rte.js b/addons/web_editor/static/src/js/rte.js index 7748ccf7762..adbc7d4bd49 100644 --- a/addons/web_editor/static/src/js/rte.js +++ b/addons/web_editor/static/src/js/rte.js @@ -583,8 +583,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.size()) { @@ -596,26 +596,16 @@ var RTE = Widget.extend({ self.historyRecordUndo($target, 'activate', true); },0); - // 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(); } }, -- cgit v1.2.3 From fb81c331f869a06ffa9332a294492d4307ea65b3 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Thu, 25 Jan 2018 12:38:32 +0100 Subject: [FIX] web_editor: fix double Shift + Enter Pressing Shift + Enter twice was buggy because of small refactoring made by https://github.com/odoo/odoo/commit/c227b8fd88e0ed635a8e807501b559b46fee7786#diff-cc5180b5ec2395c1df5c4e475aff43fbL416 opw-806003 --- addons/web_editor/static/src/js/rte.summernote.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'addons/web_editor/static/src') 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 () {}; -- cgit v1.2.3 From 25849e918651eba080dac3af4e4fcdc8f1280241 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Thu, 25 Jan 2018 14:25:35 +0100 Subject: [FIX] web_editor: properly allow formatting text (normal/header 1/...) Sometimes the formatting buttons had no effect or formatted more than they should (like a whole column when triple clicking on a paragraph only). This was because of the `listBetween` function implementation. This is supposed to return all the nodes between one element and another one... but the logic is wrong without saying from which *point* to start and which *point* to end. For example, when asking the list between an element and its parent, the result is very wrong as there is no way to go from the beginning of an element to the beginning of its parent using the `walkPoint` function as the `listBetween` function is doing. Ideally, the function should be entirely fixed but this can be tricky. For now, the function is just extended to allow to specify points instead of nodes, and those are used by the `formatBlock` function to solve the current problem. --- addons/web_editor/static/src/js/summernote.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'addons/web_editor/static/src') diff --git a/addons/web_editor/static/src/js/summernote.js b/addons/web_editor/static/src/js/summernote.js index 1f2176f3751..cdf4329c0b9 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); } @@ -1923,7 +1929,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 Date: Tue, 23 Jan 2018 17:02:33 +0100 Subject: [FIX] web_editor: ready when translations ready $('web_editor.base').ready() returns a deferred that: - wait at least for $(document).ready() - wait at least for require('web.ajax').loadXML() - at most once starts translations configuration But there is an issue since there is unexpectedly no reference to the translations, whilst it should have also been ready when ready was resolved. This commit keep the reference so translations can be used after $('web_editor.base').ready() is resolved as it was before 7dfdfa0103. note: in 11.0 it should be solved with 29729769 (so fix is for [10,11[) opw-804148 closes #22522 --- addons/web_editor/static/src/js/base.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'addons/web_editor/static/src') diff --git a/addons/web_editor/static/src/js/base.js b/addons/web_editor/static/src/js/base.js index 7bf9c2aa641..3135f7def66 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(translations); + all_ready = all_ready.then(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 translations() { -- cgit v1.2.3 From 7c959e3fd55d8faab1c0a9ea0e32fc0fdb975165 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Fri, 26 Jan 2018 14:29:27 +0100 Subject: [FIX] web_editor: properly show link alignment in toolbar When clicking on a link in the editor, the "center" alignment button was always marked as active whatever the real alignment of the link. This was because it considered the alignment of the text inside the link instead of the link's one inside its parent. --- addons/web_editor/static/src/js/summernote.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'addons/web_editor/static/src') diff --git a/addons/web_editor/static/src/js/summernote.js b/addons/web_editor/static/src/js/summernote.js index cdf4329c0b9..da837d67354 100644 --- a/addons/web_editor/static/src/js/summernote.js +++ b/addons/web_editor/static/src/js/summernote.js @@ -2015,6 +2015,14 @@ eventHandler.modules.editor.currentStyle = function(target) { if(r) styleInfo.image = r.isOnImg(); } + // Fix when the target is a link: the text-align buttons state should + // indicate the alignment of the link in the parent, not the text inside + // the link (which is not possible to customize with summernote). Summernote fixed + // this in their newest version... by just not showing the active button + // for alignments. + if (styleInfo.anchor) { + styleInfo['text-align'] = $(styleInfo.anchor).parent().css('text-align'); + } return styleInfo; } -- cgit v1.2.3 From 109ecd5205ad684a3ba85e94ce419c326696ec34 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Mon, 29 Jan 2018 15:05:02 +0100 Subject: [FIX] web_editor: firefox RTEWidget if hidden It seems that firefox has some difference of behavior from other browsers as said in: - https://bugzilla.mozilla.org/show_bug.cgi?id=548397 - https://github.com/whatwg/html/issues/1813 - https://github.com/w3c/csswg-drafts/issues/571 It seems that at least in one instance (a html field hidden on the pos configuration), firefox fails because of something similar: window.getComputedStyle(element) returns `null` instead of the element styles. In my tests, using the parent window (possible if current frame and parent have the same origin which should be the case) worked in this instance, this is examplified by this jsfiddle: https://jsfiddle.net/Lpv898ve/2/ This work with window.parent and not using window directly. So this commit adds fallback on doing getComputedStyle from the parent window (when testing on chromium this gave exactly the same result that before). opw-813363 fixes #22211 closes #22610 --- addons/web_editor/static/src/js/editor/rte.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'addons/web_editor/static/src') diff --git a/addons/web_editor/static/src/js/editor/rte.js b/addons/web_editor/static/src/js/editor/rte.js index 014a3faf40e..ee0ec7932c0 100644 --- a/addons/web_editor/static/src/js/editor/rte.js +++ b/addons/web_editor/static/src/js/editor/rte.js @@ -281,8 +281,10 @@ var RTEWidget = Widget.extend({ .each(function () { var $node = $(this); + // fallback for firefox iframe display:none see https://github.com/odoo/odoo/pull/22610 + var computedStyles = window.getComputedStyle(this) || window.parent.getComputedStyle(this); // add class to display inline-block for empty t-field - if (window.getComputedStyle(this).display === 'inline' && $node.data('oe-type') !== 'image') { + if (computedStyles.display === 'inline' && $node.data('oe-type') !== 'image') { $node.addClass('o_is_inline_editable'); } }); -- cgit v1.2.3 From 13c326caaa38eb8c1f9341da854a5045949fcf24 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Tue, 30 Jan 2018 15:01:39 +0100 Subject: [FIX] web_editor: firefox editor hidden mass mail When saving a modified mass mailing, the editor will do a number of things to improve the mail readability accross mail client. One of those is replacing font awesome icons by image, but firefox acts differently than other browser. On a display:none iframe, doing .css('color') or .height() on an element returns respectively `undefined` and 0. This caused an error when getting the color that we could solve by doing a fallback for firefox like this: window.parent.getComputedStyle($font[0]).color But to get the height() of an element, it seems we always need the iframe displayed. With this change, when the iframe is hidden and the browser is firefox, the code try to display the iframe (with "visibility:hidden;height:1px") when this part of the code happen. opw-807180 closes #22639 --- addons/web_editor/static/src/js/backend.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'addons/web_editor/static/src') diff --git a/addons/web_editor/static/src/js/backend.js b/addons/web_editor/static/src/js/backend.js index f4f8d7144b6..23505c082fa 100644 --- a/addons/web_editor/static/src/js/backend.js +++ b/addons/web_editor/static/src/js/backend.js @@ -405,7 +405,19 @@ var FieldTextHtml = widget.extend({ var layoutInfo = this.editor.rte.editable().data('layoutInfo'); $.summernote.pluginEvents.codeview(undefined, undefined, layoutInfo, false); } + var $ancestors = this.$iframe.filter(':not(:visible)').parentsUntil(':visible').addBack(); + var ancestorsStyle = []; + // temporarily force displaying iframe (needed for firefox) + _.each($ancestors, function (el) { + var $el = $(el); + ancestorsStyle.unshift($el.attr('style') || null); + $el.css({display: 'initial', visibility: 'hidden', height: 1}); + }); this.editor.buildingBlock.clean_for_save(); + _.each($ancestors, function (el) { + var $el = $(el); + $el.attr('style', ancestorsStyle.pop()); + }); this.internal_set_value( this.$content.html() ); } }, -- cgit v1.2.3 From 5af12238781a147b56572d5b576f64a4e1473083 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Thu, 1 Feb 2018 12:34:16 +0100 Subject: [FIX] web_editor: xml editor first level not shown There is a slight visual inconsistency since: 9af8d5e6 the xml/less editor for first level of descendants were just prefixed by an invisible space. opw-807624 closes #22704 --- addons/web_editor/static/src/js/widgets/ace.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web_editor/static/src') diff --git a/addons/web_editor/static/src/js/widgets/ace.js b/addons/web_editor/static/src/js/widgets/ace.js index 80bb28a4c01..6c28c1e2332 100644 --- a/addons/web_editor/static/src/js/widgets/ace.js +++ b/addons/web_editor/static/src/js/widgets/ace.js @@ -742,7 +742,7 @@ var ViewEditor = Widget.extend({ var text = data.text || ''; if (!isSelected) { - text = Array($elem.data('level')).join('-') + ' ' + text; + text = Array($elem.data('level') + 1).join('-') + ' ' + text; } var $div = $('
', { text: text, -- cgit v1.2.3