-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
84 lines (77 loc) · 2.76 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>ant-design-analysis</title>
<style>
body { margin: 0 auto; padding: 0; width: 80%; }
.ifr { width: 100%; height: 100%; margin-top: 10px; }
.code { color: #C9214B; background-color: #F2DDDD; border-radius: 5px; padding: 2px 5px; }
</style>
</head>
<body>
<h2>ant-design-analysis</h2>
<p>
The size and dependency analysis of
<span class="code">./dist/antd-mobile.min.js</span>
</p>
<select id="versionlist"></select>
<iframe class="ifr" frameborder="0" sandbox="allow-forms allow-scripts allow-same-origin"></iframe>
<script>
var vlist = document.querySelector('#versionlist');
var ifr = document.querySelector('.ifr');
var selectedVersion = '';
// hash match `#antd-mobile/versions/1.4.1`
// e.g. https://ant-design.github.io/ant-design-analysis/#antd-mobile/versions/1.4.1
if (location.hash && location.hash.indexOf('#antd-mobile/versions/') === 0) {
selectedVersion = location.hash.split('/')[2];
}
// render select/option
ajax('./antd-mobile-versions.json', function(res) {
var optsHtml = '';
var hashSel;
var verArr = JSON.parse(res).reverse();
verArr.forEach((ver, index) => {
hashSel = selectedVersion && ver === `${selectedVersion}-stats`;
optsHtml += hashSel ?
`<option value="${ver}" selected="selected">${ver}</option>` :
`<option value="${ver}">${ver}</option>`;
});
vlist.innerHTML = optsHtml;
renderIframe(hashSel ? `${selectedVersion}-stats` : verArr[0]);
});
// bind select event
vlist.addEventListener('change', evt => {
renderIframe(evt.target.value);
});
// change iframe's size
ifr.addEventListener('load', evt => {
var ifrm = evt.target;
var doc = ifrm.contentDocument? ifrm.contentDocument:
ifrm.contentWindow.document;
// In chrome61 `document.body.scrollXxx` is invalid, use `document.scrollingElement.scrollXxx`
const scrollNode = doc.scrollingElement ? doc.scrollingElement : doc.body;
ifrm.style.width = scrollNode.scrollWidth + 'px';
ifrm.style.height = scrollNode.scrollHeight + 'px';
});
function renderIframe(url) {
ifr.src = 'antd-mobile@' + url + '.html';
}
function ajax(url, success) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
if (xhr.status >= 200 && xhr.status < 400) {
// Success!
success(xhr.responseText);
} else {
console.log('XMLHttpRequest error');
}
};
xhr.open("GET", url, true);
xhr.send();
}
</script>
</body>
</html>