summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js/editor/transcoder.js
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2018-05-14 14:37:08 +0200
committerChristophe Simonis <chs@odoo.com>2018-05-14 14:37:08 +0200
commitbd2de7ae7884deb8fbde0354d617c0776384ad4a (patch)
tree9dc22107364554a9c590a4e346e8d9e25a0df3cd /addons/web_editor/static/src/js/editor/transcoder.js
parentf88a05d18e43c0d6dc36bc50df0db4507865e9e1 (diff)
parentd818b516c14947235152f14827c996c5bb01655d (diff)
[MERGE] forward port branch saas-15 up to d818b516c14
Diffstat (limited to 'addons/web_editor/static/src/js/editor/transcoder.js')
-rw-r--r--addons/web_editor/static/src/js/editor/transcoder.js34
1 files changed, 27 insertions, 7 deletions
diff --git a/addons/web_editor/static/src/js/editor/transcoder.js b/addons/web_editor/static/src/js/editor/transcoder.js
index d207efdd54b..9ca19f01ac3 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))) {
@@ -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))) {