Remove lazy loading background-image on composer
Signed-off-by: dab246 <tdvu@linagora.com> (cherry picked from commit ef5da059628de3e1de6c240836af9488fc9d3cfb)
This commit is contained in:
+32
@@ -0,0 +1,32 @@
|
||||
import 'package:core/data/network/dio_client.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/base/dom_transformer.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:html/dom.dart';
|
||||
|
||||
class RemoveLazyLoadingForBackgroundImageTransformer extends DomTransformer {
|
||||
const RemoveLazyLoadingForBackgroundImageTransformer();
|
||||
|
||||
@override
|
||||
Future<void> process({
|
||||
required Document document,
|
||||
required DioClient dioClient,
|
||||
Map<String, String>? mapUrlDownloadCID,
|
||||
}) async {
|
||||
final elements = document.querySelectorAll('[lazy]');
|
||||
log('RemoveLazyLoadingForBackgroundImageTransformer::process:elements: ${elements.length}');
|
||||
await Future.wait(elements.map((element) async {
|
||||
var exStyle = element.attributes['style'];
|
||||
final dataSrc = element.attributes['data-src'];
|
||||
final backgroundImgUrl = 'background-image:url($dataSrc);';
|
||||
if (exStyle != null) {
|
||||
exStyle = '$exStyle;$backgroundImgUrl';
|
||||
element.attributes['style'] = exStyle;
|
||||
} else {
|
||||
element.attributes['style'] = backgroundImgUrl;
|
||||
}
|
||||
element.attributes.remove('data-src');
|
||||
element.attributes.remove('lazy');
|
||||
log('RemoveLazyLoadingForBackgroundImageTransformer::process:NEW_ELEMENT: ${element.outerHtml}');
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import 'package:core/presentation/utils/html_transformer/dom/add_tooltip_link_tr
|
||||
import 'package:core/presentation/utils/html_transformer/dom/blockcode_transformers.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/dom/blockquoted_transformers.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/dom/image_transformers.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/dom/remove_lazy_loading_for_background_image_transformers.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/dom/remove_tooltip_link_transformers.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/dom/script_transformers.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/dom/sigature_transformers.dart';
|
||||
@@ -38,6 +39,7 @@ class TransformConfiguration {
|
||||
if (PlatformInfo.isWeb)
|
||||
const RemoveTooltipLinkTransformer(),
|
||||
const SignatureTransformer(),
|
||||
const RemoveLazyLoadingForBackgroundImageTransformer(),
|
||||
]);
|
||||
|
||||
factory TransformConfiguration.forDraftsEmail() => TransformConfiguration.empty();
|
||||
|
||||
@@ -1418,7 +1418,7 @@ class ComposerController extends BaseController {
|
||||
accountId,
|
||||
emailId,
|
||||
mailboxDashBoardController.baseDownloadUrl,
|
||||
TransformConfiguration.empty()
|
||||
TransformConfiguration.forDraftsEmail()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user