From 612cd4e09222465ed8d4810282721b1325d5b7d7 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Mon, 31 Jan 2022 13:41:27 +0000 Subject: [PATCH] [REF] web_editor: remove _applyOverDescendants Rules used to be applied in the DOM sequencially, in traversal order. This is slow and confusing to debug. Meanwhile, most functions had been adapted to process the rules in a simple loop on the concerned nodes. This commit does that for `classToStyle`, the last remaining function that wasn't doing it yet, and removes the utility function `_applyOverDescendants` altogether. X-original-commit: 70253a98bd9d6752c29cfe61debf4567d0a872e8 Part-of: odoo/odoo#84513 --- .../static/src/js/backend/convert_inline.js | 30 ++----------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/addons/web_editor/static/src/js/backend/convert_inline.js b/addons/web_editor/static/src/js/backend/convert_inline.js index f2bb38b01c0..15673108ba7 100644 --- a/addons/web_editor/static/src/js/backend/convert_inline.js +++ b/addons/web_editor/static/src/js/backend/convert_inline.js @@ -312,7 +312,7 @@ function classToStyle($editable, cssRules) { rules.sort((a, b) => a.specificity - b.specificity); } - _applyOverDescendants($editable[0], function (node) { + for (const node of nodeToRules.keys()) { const $target = $(node); const nodeRules = nodeToRules.get(node); const css = nodeRules ? _getMatchedCSSRules(node, nodeRules) : {}; @@ -362,7 +362,7 @@ function classToStyle($editable, cssRules) { } else if (node.nodeName === 'IMG' && $target.is('.mx-auto.d-block')) { writes.push(() => { $target.wrap('

'); }); } - }); + }; writes.forEach(fn => fn()); } /** @@ -768,32 +768,6 @@ function _applyColspan($element, colspan) { $element.attr('width', width); $element.css('width', width); } -/* - * 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); - } - var $node = $(node); - if (node.nodeName === 'A' && $node.hasClass('btn') && !$node.children().length && $(node).parents('.o_outlook_hack').length) { - node = $(node).parents('.o_outlook_hack')[0]; - } - else if (node.nodeName === 'IMG' && $node.parent('p').hasClass('o_outlook_hack')) { - node = $node.parent()[0]; - } - node = node.nextSibling; - } -} /** * Take a selector and return its specificity according to the w3 specification. *