summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web_editor/static/src')
-rw-r--r--addons/web_editor/static/src/js/base.js9
-rw-r--r--addons/web_editor/static/src/js/rte.js44
-rw-r--r--addons/web_editor/static/src/js/rte.summernote.js3
-rw-r--r--addons/web_editor/static/src/js/summernote.js12
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);