TF-2903 Handle mailto link on web
This commit is contained in:
+3
-3
@@ -4,11 +4,11 @@ import 'package:core/presentation/utils/html_transformer/sanitize_url.dart';
|
|||||||
import 'package:core/utils/html/html_template.dart';
|
import 'package:core/utils/html/html_template.dart';
|
||||||
import 'package:html/dom.dart';
|
import 'package:html/dom.dart';
|
||||||
|
|
||||||
class SanitizeTagAInHtmlTransformer extends DomTransformer {
|
class SanitizeHyperLinkTagInHtmlTransformer extends DomTransformer {
|
||||||
final _sanitizeUrl = SanitizeUrl();
|
final _sanitizeUrl = SanitizeUrl();
|
||||||
final bool useTooltip;
|
final bool useTooltip;
|
||||||
|
|
||||||
SanitizeTagAInHtmlTransformer({this.useTooltip = false});
|
SanitizeHyperLinkTagInHtmlTransformer({this.useTooltip = false});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> process({
|
Future<void> process({
|
||||||
@@ -12,7 +12,7 @@ import 'package:core/presentation/utils/html_transformer/dom/remove_lazy_loading
|
|||||||
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_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_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/remove_tooltip_link_transformers.dart';
|
||||||
import 'package:core/presentation/utils/html_transformer/dom/sanitize_tag_a_in_html_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/script_transformers.dart';
|
||||||
import 'package:core/presentation/utils/html_transformer/dom/signature_transformers.dart';
|
import 'package:core/presentation/utils/html_transformer/dom/signature_transformers.dart';
|
||||||
import 'package:core/presentation/utils/html_transformer/text/sanitize_autolink_html_transformers.dart';
|
import 'package:core/presentation/utils/html_transformer/text/sanitize_autolink_html_transformers.dart';
|
||||||
@@ -56,7 +56,7 @@ class TransformConfiguration {
|
|||||||
const RemoveScriptTransformer(),
|
const RemoveScriptTransformer(),
|
||||||
const BlockQuotedTransformer(),
|
const BlockQuotedTransformer(),
|
||||||
const BlockCodeTransformer(),
|
const BlockCodeTransformer(),
|
||||||
SanitizeTagAInHtmlTransformer(useTooltip: true),
|
SanitizeHyperLinkTagInHtmlTransformer(useTooltip: true),
|
||||||
const ImageTransformer(),
|
const ImageTransformer(),
|
||||||
const AddLazyLoadingForBackgroundImageTransformer(),
|
const AddLazyLoadingForBackgroundImageTransformer(),
|
||||||
const RemoveCollapsedSignatureButtonTransformer(),
|
const RemoveCollapsedSignatureButtonTransformer(),
|
||||||
@@ -108,7 +108,7 @@ class TransformConfiguration {
|
|||||||
const RemoveScriptTransformer(),
|
const RemoveScriptTransformer(),
|
||||||
const BlockQuotedTransformer(),
|
const BlockQuotedTransformer(),
|
||||||
const BlockCodeTransformer(),
|
const BlockCodeTransformer(),
|
||||||
SanitizeTagAInHtmlTransformer(),
|
SanitizeHyperLinkTagInHtmlTransformer(),
|
||||||
const ImageTransformer(),
|
const ImageTransformer(),
|
||||||
const AddLazyLoadingForBackgroundImageTransformer(),
|
const AddLazyLoadingForBackgroundImageTransformer(),
|
||||||
const RemoveCollapsedSignatureButtonTransformer(),
|
const RemoveCollapsedSignatureButtonTransformer(),
|
||||||
|
|||||||
@@ -145,7 +145,6 @@ class _HtmlContentViewerOnWebState extends State<HtmlContentViewerOnWeb> {
|
|||||||
final webViewActionScripts = '''
|
final webViewActionScripts = '''
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
window.parent.addEventListener('message', handleMessage, false);
|
window.parent.addEventListener('message', handleMessage, false);
|
||||||
window.addEventListener('click', handleOnClickLink, true);
|
|
||||||
window.addEventListener('load', handleOnLoad);
|
window.addEventListener('load', handleOnLoad);
|
||||||
window.addEventListener('pagehide', (event) => {
|
window.addEventListener('pagehide', (event) => {
|
||||||
window.parent.removeEventListener('message', handleMessage, false);
|
window.parent.removeEventListener('message', handleMessage, false);
|
||||||
@@ -174,34 +173,21 @@ class _HtmlContentViewerOnWebState extends State<HtmlContentViewerOnWeb> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleOnClickLink(e) {
|
function handleOnClickEmailLink(e) {
|
||||||
let link = e.target;
|
var href = this.href;
|
||||||
let textContent = e.target.textContent;
|
window.parent.postMessage(JSON.stringify({"view": "$_createdViewId", "type": "toDart: OpenLink", "url": "" + href}), "*");
|
||||||
if (link && isValidMailtoLink(link)) {
|
e.preventDefault();
|
||||||
window.parent.postMessage(JSON.stringify({"view": "$_createdViewId", "type": "toDart: OpenLink", "url": "" + link}), "*");
|
|
||||||
e.preventDefault();
|
|
||||||
} else if (textContent && isValidMailtoLink(textContent)) {
|
|
||||||
window.parent.postMessage(JSON.stringify({"view": "$_createdViewId", "type": "toDart: OpenLink", "url": "" + textContent}), "*");
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function isValidMailtoLink(string) {
|
|
||||||
let url;
|
|
||||||
|
|
||||||
try {
|
|
||||||
url = new URL(string);
|
|
||||||
} catch (_) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return url.protocol === "mailto:";
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleOnLoad() {
|
function handleOnLoad() {
|
||||||
window.parent.postMessage(JSON.stringify({"view": "$_createdViewId", "message": "$iframeOnLoadMessage"}), "*");
|
window.parent.postMessage(JSON.stringify({"view": "$_createdViewId", "message": "$iframeOnLoadMessage"}), "*");
|
||||||
window.parent.postMessage(JSON.stringify({"view": "$_createdViewId", "type": "toIframe: getHeight"}), "*");
|
window.parent.postMessage(JSON.stringify({"view": "$_createdViewId", "type": "toIframe: getHeight"}), "*");
|
||||||
window.parent.postMessage(JSON.stringify({"view": "$_createdViewId", "type": "toIframe: getWidth"}), "*");
|
window.parent.postMessage(JSON.stringify({"view": "$_createdViewId", "type": "toIframe: getWidth"}), "*");
|
||||||
|
|
||||||
|
var emailLinks = document.querySelectorAll('a[href^="mailto:"]');
|
||||||
|
for(var i=0; i < emailLinks.length; i++){
|
||||||
|
emailLinks[i].addEventListener('click', handleOnClickEmailLink);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
''';
|
''';
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'package:core/presentation/utils/html_transformer/dom/block_code_transformers.dart';
|
import 'package:core/presentation/utils/html_transformer/dom/block_code_transformers.dart';
|
||||||
import 'package:core/presentation/utils/html_transformer/dom/block_quoted_transformers.dart';
|
import 'package:core/presentation/utils/html_transformer/dom/block_quoted_transformers.dart';
|
||||||
import 'package:core/presentation/utils/html_transformer/dom/image_transformers.dart';
|
import 'package:core/presentation/utils/html_transformer/dom/image_transformers.dart';
|
||||||
import 'package:core/presentation/utils/html_transformer/dom/sanitize_tag_a_in_html_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/script_transformers.dart';
|
||||||
import 'package:core/presentation/utils/html_transformer/html_transform.dart';
|
import 'package:core/presentation/utils/html_transformer/html_transform.dart';
|
||||||
import 'package:core/presentation/utils/html_transformer/transform_configuration.dart';
|
import 'package:core/presentation/utils/html_transformer/transform_configuration.dart';
|
||||||
@@ -66,7 +66,7 @@ class IdentityDataSourceImpl extends IdentityDataSource {
|
|||||||
const RemoveScriptTransformer(),
|
const RemoveScriptTransformer(),
|
||||||
const BlockQuotedTransformer(),
|
const BlockQuotedTransformer(),
|
||||||
const BlockCodeTransformer(),
|
const BlockCodeTransformer(),
|
||||||
SanitizeTagAInHtmlTransformer(useTooltip: PlatformInfo.isWeb),
|
SanitizeHyperLinkTagInHtmlTransformer(useTooltip: PlatformInfo.isWeb),
|
||||||
const ImageTransformer(),
|
const ImageTransformer(),
|
||||||
]));
|
]));
|
||||||
return signatureUnescape;
|
return signatureUnescape;
|
||||||
|
|||||||
Reference in New Issue
Block a user