/
DocumentView.jsx
executable file
·99 lines (95 loc) · 2.9 KB
/
DocumentView.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { AbstractDocumentView } from '@ima/core';
import React from 'react';
export default class DocumentView extends AbstractDocumentView {
static get masterElementId() {
return 'page';
}
render() {
let appCssFile =
this.utils.$Settings.$Env !== 'dev' ? 'app.bundle.min.css' : 'app.css';
appCssFile += `?version=${this.utils.$Settings.$Version}`;
let jsBaseUrl =
this.utils.$Router.getBaseUrl() + this.utils.$Settings.$Static.js;
return (
<html lang={'en'} data-framework="imajs">
<head>
<meta charSet="utf-8" />
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="stylesheet"
href={
this.utils.$Router.getBaseUrl() +
this.utils.$Settings.$Static.css +
'/' +
appCssFile
}
/>
<title>{this.props.metaManager.getTitle()}</title>
</head>
<body>
<div
id="page"
dangerouslySetInnerHTML={{ __html: this.props.page }}
/>
<script
id="revivalSettings"
dangerouslySetInnerHTML={{ __html: this.props.revivalSettings }}
/>
<script
dangerouslySetInnerHTML={{
__html: `
if (!window.fetch) {
document.write('<script src="${jsBaseUrl}/fetch-polyfill.js"></' + 'script>')
}
`
}}
/>
<div
id="scripts"
dangerouslySetInnerHTML={{ __html: this.getAsyncScripts() }}
/>
</body>
</html>
);
}
getAsyncScripts() {
let scriptResources = `<script>
function checkAsyncAwait () {
try {
new Function('(async () => ({}))()');
return true;
} catch (e) {
return false;
}
}
$IMA.Runner = $IMA.Runner || {};
if (Object.values && checkAsyncAwait()) {
$IMA.Runner.scripts = [
${this.utils.$Settings.$Page.$Render.esScripts
.map(script => `'${script}'`)
.join()}
];
} else {
$IMA.Runner.scripts = [
${this.utils.$Settings.$Page.$Render.scripts
.map(script => `'${script}'`)
.join()}
];
}
if (!window.fetch) {
$IMA.Runner.scripts.unshift('${
this.utils.$Settings.$Static.js
}/fetch-polyfill.js');
}
$IMA.Runner.scripts.forEach(function(source) {
var script = document.createElement('script');
script.async = $IMA.$Env !== 'dev';
script.onload = $IMA.Runner.load;
script.src = source;
document.getElementById('scripts').appendChild(script);
});
</script>`;
return scriptResources;
}
}