-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
130 lines (86 loc) · 3.16 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!doctype html>
<html lang=en >
<head>
<meta charset=utf-8 >
<title>Moving Manuals R1</title>
<meta name=viewport content='width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,minimal-ui' >
<meta name=description content='Moving Manual home page' >
<meta name=keywords content='HTML,CSS,JavaScript,GitHub,FOSS' >
<meta name=date content='2016-03-11' >
</head>
<body>
<script src=https://cdnjs.cloudflare.com/ajax/libs/showdown/1.3.0/showdown.min.js ></script>
<script>
var iframes = [];
var renderers = [];
var renderersLimit = 3;
init();
animate();
function init() {
css = document.head.appendChild( document.createElement( 'style' ) );
css.innerHTML =
'body { font: 12pt monospace; left: 0; margin: 0 auto; max-width: 800px; right: 0; }' +
'a { font-weight: 600; text-decoration: none; }' +
'h2 { margin: 0; }' +
'hr { margin-top: 150px; }' +
'iframe { border: 2px solid green; height: 500px; width: ' + ( window.innerWidth - 25 ) + 'px; }' +
'button, input[type=button] { background-color: #eee; border: 2px #eee solid; color: #888; }' +
'';
contents = document.body.appendChild( document.createElement( 'div' ) );
contents.id = 'contents';
// menu.innerHTML =
// '<div id=contents ></div>' +
// '';
var converter = new showdown.Converter( { strikethrough: true, literalMidWordUnderscores: true, simplifiedAutoLink: true, tables: true });
var fileName = location.hash ? location.hash.substr( 1 ) : 'index.md';
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( 'get', fileName, true );
xmlHttp.onreadystatechange = function() {
if ( xmlHttp.readyState !== 4 ) { return; }
contents.innerHTML = converter.makeHtml( xmlHttp.responseText );
iframes = document.getElementsByTagName( 'iframe' );
// if ( iframes !== undefined ) {
for ( var i = 0; i < iframes.length; i++ ) {
ifrm = iframes[ i ];
ifrm.style.margin = '100px 0 0' + ( -0.5 * ( window.innerWidth - document.body.clientWidth ) + 10 ) + 'px';
// ifrm.style.width = ( window.innerWidth - 25 ) + 'px';
// ifrm.style.height = '500px';
ifrm.data = ifrm.src;
ifrm.id = 'ifr' + i ;
ifrm.src = '';
ifrm.onload = function() {
// this.contentWindow.audioContext.close()
if ( this.contentWindow.controls ) {
this.contentWindow.controls.enableZoom = false;
this.contentWindow.controls.autoRotate = true;
}
};
}
// }
};
xmlHttp.send( null );
}
function updateView( ifram ) {
iframesActive = document.getElementsByClassName( 'ifr' );
if ( iframesActive.length > renderersLimit ) {
var iframeDiscard = renderers.shift();
iframeDiscard.src = iframeDiscard.className = '';
}
if ( ifram.src === window.location.href ) {
ifram.src = iframes[ ifram.id.slice( 3 ) ].data;
ifram.className = 'ifr';
renderers.push( ifram );
}
}
function animate() {
requestAnimationFrame( animate );
for ( var i = 0; i < iframes.length; i++ ) {
var iframe = iframes[ i ];
var rect = iframe.getBoundingClientRect();
if ( rect.bottom < 0 || rect.top > window.innerHeight ) { continue; }
updateView( iframe );
}
}
</script>
</body>
</html>