[IMP] mass_mailing: do not load images on add sidebar and commitChanges
Images in mass_mailing are not lazy loaded, which is deliberate for the mailing itself and its conversion, but when we load the sidebar we add the HTML to all the snippets and hide it so if these images are not lazy loaded, they all get loaded along with the sidebar, which is slow and unnecessary. This loads the images only once we add them to the mailing, which is when we remove the lazy loading attribute. task-3323894 Part-of: odoo/odoo#126845
This commit is contained in:
@@ -535,6 +535,7 @@ export class MassMailingHtmlField extends HtmlField {
|
||||
for (const img of $container.find("img")) {
|
||||
const $img = $(img);
|
||||
const src = $img.attr("src");
|
||||
$img.removeAttr('loading');
|
||||
|
||||
let m = src.match(/^\/web\/image\/\w+\.s_default_image_(?:theme_[a-z]+_)?(.+)$/);
|
||||
if (!m) {
|
||||
|
||||
@@ -32,11 +32,26 @@ export const MassMailingSnippetsMenu = snippetsEditor.SnippetsMenu.extend({
|
||||
this.$editable = this.options.wysiwyg.getEditable();
|
||||
});
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
callPostSnippetDrop: async function ($target) {
|
||||
$target.find('img[loading=lazy]').removeAttr('loading');
|
||||
return this._super(...arguments);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
_computeSnippetTemplates: function (html) {
|
||||
const $html = $(`<div>${html}</div>`);
|
||||
$html.find('img').attr('loading', 'lazy');
|
||||
return this._super($html.html().trim());
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user