|
@@ -25,22 +25,24 @@ const inlineBodyStyle = `
|
25
|
25
|
}
|
26
|
26
|
`;
|
27
|
27
|
|
28
|
|
-
|
29
|
|
-//https://medium.com/@elhardoum/opening-external-links-in-browser-in-react-native-webview-18fe6a66312a
|
|
28
|
+// https://medium.com/@elhardoum/opening-external-links-in-browser-in-react-native-webview-18fe6a66312a
|
30
|
29
|
const autoDetectLinkScript = `
|
31
|
|
-(function(){
|
32
|
|
- function isUrl(str){
|
33
|
|
- return str.startsWith('http');
|
|
30
|
+(function() {
|
|
31
|
+ var links = document.querySelectorAll('a[href]');
|
|
32
|
+ if (links) {
|
|
33
|
+ for (var index = 0; index < links.length; index++) {
|
|
34
|
+ links[index].addEventListener('click', function(event) {
|
|
35
|
+ event.preventDefault();
|
|
36
|
+ window.ReactNativeWebView.postMessage(JSON.stringify({ url: this.href }));
|
|
37
|
+ });
|
|
38
|
+ }
|
34
|
39
|
}
|
35
|
|
- var e=function(e,n,t){if(n=n.replace(/^on/g,""),"addEventListener"in window)e.addEventListener(n,t,!1);else if("attachEvent"in window)e.attachEvent("on"+n,t);else{var o=e["on"+n];e["on"+n]=o?function(e){o(e),t(e)}:t}return e},n=document.querySelectorAll("a[href]");if(n)for(var t in n)n.hasOwnProperty(t)&&e(n[t],"onclick",function(e){!isUrl(this.href)||(e.preventDefault(),window.postMessage(JSON.stringify({url:this.href})))})
|
36
|
|
-}());
|
|
40
|
+})();
|
37
|
41
|
`;
|
38
|
42
|
|
39
|
43
|
const autoHeightScript = `
|
40
|
44
|
var styleElement = document.createElement('style');
|
41
|
|
-styleElement.innerHTML = '${style1
|
42
|
|
- .replace(/\'/g, "\\'")
|
43
|
|
- .replace(/\n/g, '\\n')}';
|
|
45
|
+styleElement.innerHTML = '${style1.replace(/\'/g, "\\'").replace(/\n/g, '\\n')}';
|
44
|
46
|
document.head.appendChild(styleElement);
|
45
|
47
|
document.body.style.background = 'cornflowerblue';
|
46
|
48
|
`;
|
|
@@ -50,7 +52,7 @@ const autoWidthHtml0 = `
|
50
|
52
|
<head>
|
51
|
53
|
<meta name="viewport" content="target-densitydpi=device-dpi, initial-scale=1.0, user-scalable=no" />
|
52
|
54
|
</head>
|
53
|
|
-<p class="localStyle" style="display: inline;background-color: transparent !important;background-image: linear-gradient(to bottom, rgba(146, 249, 190, 1), rgba(146, 249, 190, 1));font-style: normal;zoom:1;font-size: 21px;line-height: 1.58;letter-spacing: -.003em;padding-top:0;padding-bottom:0;">hey</p>
|
|
55
|
+<p class="localStyle" style="display: inline;background-color: transparent !important;background-image: linear-gradient(to bottom, rgba(146, 249, 190, 1), rgba(146, 249, 190, 1));font-style: normal;font-size: 21px;line-height: 1.58;letter-spacing: -.003em;padding-top:0;padding-bottom:0;">hey</p>
|
54
|
56
|
</html>
|
55
|
57
|
`;
|
56
|
58
|
|
|
@@ -60,9 +62,7 @@ const autoWidthHtml1 = `
|
60
|
62
|
|
61
|
63
|
const autoWidthScript = `
|
62
|
64
|
var styleElement = document.createElement('style');
|
63
|
|
-styleElement.innerHTML = '${style1
|
64
|
|
- .replace(/\'/g, "\\'")
|
65
|
|
- .replace(/\n/g, '\\n')}';
|
|
65
|
+styleElement.innerHTML = '${style1.replace(/\'/g, "\\'").replace(/\n/g, '\\n')}';
|
66
|
66
|
document.head.appendChild(styleElement);
|
67
|
67
|
`;
|
68
|
68
|
|
|
@@ -76,4 +76,4 @@ export {
|
76
|
76
|
autoWidthScript,
|
77
|
77
|
inlineBodyStyle,
|
78
|
78
|
autoDetectLinkScript
|
79
|
|
-};
|
|
79
|
+};
|