From b6288efe655fb53696626dd3817b2b3cef1a3fed Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Tue, 2 May 2023 08:56:30 +0000 Subject: [PATCH] [REF] web_editor: replace all classList toggles true with classList adds In several places, `convert_inline` uses `classList.toggle('c', true)` to set classes. This is not a good practice, as it's not clear what the state of the class is. It's better to use `classList.add('c')` since this anyway checks whether the class is already present or not. closes odoo/odoo#124465 X-original-commit: 43afc5a5a30530bc3ede9f0a46249977a7896b5a Signed-off-by: David Monjoie (dmo) Signed-off-by: Antoine Guenet (age) --- .../static/src/js/backend/convert_inline.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 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 e7ce9a41ee3..3c011f0b4c4 100644 --- a/addons/web_editor/static/src/js/backend/convert_inline.js +++ b/addons/web_editor/static/src/js/backend/convert_inline.js @@ -525,11 +525,11 @@ function enforceTablesResponsivity(editable) { const div = document.createElement('div'); div.style.display = 'inline-block'; div.style.verticalAlign = 'top'; - div.classList.toggle('o_stacking_wrapper', true); + div.classList.add('o_stacking_wrapper'); commonTd.appendChild(div); const newTable = _createTable(); newTable.style.width = width; - newTable.classList.toggle('o_stacking_wrapper', true); + newTable.classList.add('o_stacking_wrapper'); div.appendChild(newTable); const newTr = document.createElement('tr'); newTable.appendChild(newTr); @@ -565,7 +565,7 @@ function handleMasonry(editable) { // TODO: this seems a duplicate of the other o_desktop_h100 set below. // Set the cells' heights to fill their parents. for (const tdWithTable of tdsWithTable) { - tdWithTable.classList.toggle('o_desktop_h100', true); + tdWithTable.classList.add('o_desktop_h100'); tdWithTable.style.setProperty('height', '100%'); } // We also have to set the same height on the cells' sibling TDs. @@ -582,10 +582,10 @@ function handleMasonry(editable) { } for (const tr of masonryTrs) { const height = tr.style.height.includes('px') ? parseFloat(tr.style.height.replace('px', '').trim()) : _getHeight(tr); - tr.closest('table').classList.toggle('o_desktop_h100', true); - tr.classList.toggle('o_desktop_h100', true); + tr.closest('table').classList.add('o_desktop_h100'); + tr.classList.add('o_desktop_h100'); for (const td of [...tr.children].filter(child => child.nodeName === 'TD')) { - td.classList.toggle('o_desktop_h100', true); + td.classList.add('o_desktop_h100'); td.style.setProperty('height', '100%'); const childrenNames = [...td.children].map(child => child.nodeName); if (!childrenNames.includes('TABLE')) { @@ -646,7 +646,7 @@ function enforceImagesResponsivity(editable) { // responsively, but leave it for Outlook. for (const image of editable.querySelectorAll('img[width="100%"][height]')) { image.before(_createMso(image.outerHTML)); - image.classList.toggle('mso-hide', true); + image.classList.add('mso-hide'); image.removeAttribute('height'); } } @@ -1249,7 +1249,7 @@ function _applyColspan(element, colspan, tableWidth) { // Round to 2 decimal places. const width = Math.round(tableWidth * widthPercentage * 100) / 100; element.style.setProperty('max-width', width + 'px'); - element.classList.toggle('o_converted_col', true); + element.classList.add('o_converted_col'); } /** * Take an element with a background image and return a string containing the