TF-4152 Fix tooltip stay out of screen in Email View
This commit is contained in:
-41
@@ -1,41 +0,0 @@
|
||||
|
||||
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:core/utils/html/html_template.dart';
|
||||
import 'package:html/dom.dart';
|
||||
|
||||
class RemoveTooltipLinkTransformer extends DomTransformer {
|
||||
|
||||
const RemoveTooltipLinkTransformer();
|
||||
|
||||
@override
|
||||
Future<void> process({
|
||||
required Document document,
|
||||
required DioClient dioClient,
|
||||
Map<String, String>? mapUrlDownloadCID,
|
||||
}) async {
|
||||
try {
|
||||
final linkElements = document.querySelectorAll('a.${HtmlTemplate.nameClassToolTip}');
|
||||
|
||||
if (linkElements.isEmpty) return;
|
||||
|
||||
await Future.wait(linkElements.map((linkElement) async {
|
||||
final classAttribute = linkElement.attributes['class'];
|
||||
if (classAttribute != null) {
|
||||
final newClassAttribute = classAttribute.replaceFirst(HtmlTemplate.nameClassToolTip, '');
|
||||
linkElement.attributes['class'] = newClassAttribute;
|
||||
}
|
||||
final listSpanTag = linkElement.querySelectorAll('span.tooltiptext');
|
||||
if (listSpanTag.isNotEmpty) {
|
||||
for (var element in listSpanTag) {
|
||||
element.remove();
|
||||
}
|
||||
}
|
||||
}));
|
||||
} catch (e) {
|
||||
logError('$runtimeType::process:Exception = $e');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-22
@@ -2,14 +2,12 @@ import 'package:core/data/network/dio_client.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/base/dom_transformer.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/sanitize_url.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/utils/html/html_template.dart';
|
||||
import 'package:html/dom.dart';
|
||||
|
||||
class SanitizeHyperLinkTagInHtmlTransformer extends DomTransformer {
|
||||
final _sanitizeUrl = SanitizeUrl();
|
||||
final bool useTooltip;
|
||||
|
||||
SanitizeHyperLinkTagInHtmlTransformer({this.useTooltip = false});
|
||||
SanitizeHyperLinkTagInHtmlTransformer();
|
||||
|
||||
@override
|
||||
Future<void> process({
|
||||
@@ -24,9 +22,6 @@ class SanitizeHyperLinkTagInHtmlTransformer extends DomTransformer {
|
||||
|
||||
await Future.wait(elements.map((element) async {
|
||||
_sanitizeUrlResource(element);
|
||||
if (useTooltip) {
|
||||
_addToolTipWhenHoverLink(element);
|
||||
}
|
||||
_addBlankForTargetProperty(element);
|
||||
_addNoReferrerForRelProperty(element);
|
||||
}));
|
||||
@@ -46,22 +41,6 @@ class SanitizeHyperLinkTagInHtmlTransformer extends DomTransformer {
|
||||
element.attributes['href'] = urlSanitized;
|
||||
}
|
||||
|
||||
void _addToolTipWhenHoverLink(Element element) {
|
||||
final url = element.attributes['href'] ?? '';
|
||||
final text = element.text;
|
||||
final children = element.children;
|
||||
if (children.isEmpty && text.isNotEmpty) {
|
||||
final innerHtml = element.innerHtml;
|
||||
final tagClass = element.attributes['class'];
|
||||
if (tagClass != null) {
|
||||
element.attributes['class'] = '$tagClass ${HtmlTemplate.nameClassToolTip}';
|
||||
} else {
|
||||
element.attributes['class'] = HtmlTemplate.nameClassToolTip;
|
||||
}
|
||||
element.innerHtml = '$innerHtml <span class="tooltiptext">$url</span>';
|
||||
}
|
||||
}
|
||||
|
||||
void _addBlankForTargetProperty(Element element) {
|
||||
element.attributes['target'] = '_blank';
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import 'package:core/presentation/utils/html_transformer/dom/remove_lazy_loading
|
||||
import 'package:core/presentation/utils/html_transformer/dom/remove_lazy_loading_image_transformers.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/dom/remove_max_width_in_image_style_transformers.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/dom/remove_style_tag_outside_transformers.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/dom/remove_tooltip_link_transformers.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/dom/sanitize_hyper_link_tag_in_html_transformers.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/dom/script_transformers.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/dom/signature_transformers.dart';
|
||||
@@ -43,8 +42,6 @@ class TransformConfiguration {
|
||||
) => TransformConfiguration([], textTransformers);
|
||||
|
||||
factory TransformConfiguration.forReplyForwardEmail() => TransformConfiguration.fromDomTransformers([
|
||||
if (PlatformInfo.isWeb)
|
||||
const RemoveTooltipLinkTransformer(),
|
||||
const SignatureTransformer(),
|
||||
const RemoveCollapsedSignatureButtonTransformer(),
|
||||
const NormalizeLineHeightInStyleTransformer(),
|
||||
@@ -74,7 +71,7 @@ class TransformConfiguration {
|
||||
const RemoveScriptTransformer(),
|
||||
const BlockQuotedTransformer(),
|
||||
const BlockCodeTransformer(),
|
||||
SanitizeHyperLinkTagInHtmlTransformer(useTooltip: true),
|
||||
SanitizeHyperLinkTagInHtmlTransformer(),
|
||||
const ImageTransformer(),
|
||||
const AddLazyLoadingForBackgroundImageTransformer(),
|
||||
const RemoveCollapsedSignatureButtonTransformer(),
|
||||
@@ -89,8 +86,6 @@ class TransformConfiguration {
|
||||
);
|
||||
|
||||
factory TransformConfiguration.forPrintEmail() => TransformConfiguration.fromDomTransformers([
|
||||
if (PlatformInfo.isWeb)
|
||||
const RemoveTooltipLinkTransformer(),
|
||||
const RemoveLazyLoadingForBackgroundImageTransformer(),
|
||||
const RemoveLazyLoadingImageTransformer(),
|
||||
const RemoveCollapsedSignatureButtonTransformer(),
|
||||
@@ -103,7 +98,7 @@ class TransformConfiguration {
|
||||
const RemoveScriptTransformer(),
|
||||
const BlockQuotedTransformer(),
|
||||
const BlockCodeTransformer(),
|
||||
SanitizeHyperLinkTagInHtmlTransformer(useTooltip: PlatformInfo.isWeb),
|
||||
SanitizeHyperLinkTagInHtmlTransformer(),
|
||||
const ImageTransformer(),
|
||||
],
|
||||
);
|
||||
@@ -139,7 +134,7 @@ class TransformConfiguration {
|
||||
const RemoveScriptTransformer(),
|
||||
const BlockQuotedTransformer(),
|
||||
const BlockCodeTransformer(),
|
||||
SanitizeHyperLinkTagInHtmlTransformer(useTooltip: PlatformInfo.isWeb),
|
||||
SanitizeHyperLinkTagInHtmlTransformer(),
|
||||
const ImageTransformer(),
|
||||
const AddLazyLoadingForBackgroundImageTransformer(),
|
||||
const RemoveCollapsedSignatureButtonTransformer(),
|
||||
|
||||
Reference in New Issue
Block a user