[FIX] web_editor: remove divs created by default shadow computation

The shadow option needs to create a div on the fly to be able to
retrieve the default shadow value. This commit makes sure these divs
are also removed when no longer needed.

This also simplifies the code and actually avoids that div creation when
it is not needed.

task-2752326

closes odoo/odoo#84324

X-original-commit: 309f03c011fc8e5e0bec9882af54a8147025118f
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
qsm-odoo
2022-02-11 15:04:48 +00:00
parent bc616dd053
commit 7c0b026487
@@ -4536,22 +4536,17 @@ registry.Box = SnippetOptionWidget.extend({
* @returns {string}
*/
_getDefaultShadow(type, shadowClass) {
if (!type) {
return 'none';
}
const el = document.createElement('div');
if (type) {
el.classList.add(shadowClass);
}
el.classList.add(shadowClass);
document.body.appendChild(el);
switch (type) {
case 'outset': {
return $(el).css('box-shadow');
}
case 'inset': {
return $(el).css('box-shadow') + ' inset';
}
}
const shadow = `${$(el).css('box-shadow')}${type === 'inset' ? ' inset' : ''}`;
el.remove();
return 'none';
}
return shadow;
},
});