-
Notifications
You must be signed in to change notification settings - Fork 0
/
terrain-00.html
290 lines (165 loc) · 6.62 KB
/
terrain-00.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<!doctype html>
<html lang=en >
<head>
<title>Jaanga Terrain R2</title>
<meta charset=utf-8 />
<meta name=viewport content='width=device-width,user-scalable=no,minimum-scale=1.0,maximum-scale=1.0' />
</head>
<body>
<script src=http://cdnjs.cloudflare.com/ajax/libs/showdown/0.3.1/showdown.min.js ></script>
<script>
var header, menu, content;
init();
function init() {
var txt = 'lorem ipsum, quia dolor sit, amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt, ut labore et dolore magnam aliquam quaerat voluptatem. ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur?';
var css = document.body.appendChild( document.createElement('style') );
css.innerHTML = 'body { font: 600 12pt monospace; margin: 0; overflow: hidden; }' +
'h1 { margin: 0; }' +
'h1 a, #bars { text-decoration: none; }' +
'h2.close::before { content: "► "; }' +
'h2.open::before { content: "▼ "; }' +
'#bars { color: #ccc; }' +
'';
header = document.body.appendChild( document.createElement( 'div' ) );
header.style.cssText = 'position: absolute; left: 350px; top: 20px; transition: left 1s; ';
header.innerHTML = '<h1><a href=JavaScript:slideMenu(); id=bars >☰</a></h1>';
menu = header.appendChild( document.createElement( 'div' ) );
menu.style.cssText = 'background-color: #eee; height: ' + ( 0.95 * window.innerHeight ) + 'px; left: -350px; opacity: 0.85; overflow: auto; ' +
'padding: 0 15px; position: absolute; top: 0px; width: 300px; ';
loadMarkdownInMenu( 'terrain-menu.md', menu );
// loadMarkdownInIframe( '#readme.md#' );
loadMarkdownInDiv( 'readme.md' );
// loadHTMLInIframe( '#../template-threejs.html#' );
// slideMenu();
window.addEventListener ( 'hashchange', onHashChange, false );
}
function slideMenu(){
header.style.left = header.style.left === '20px' ? '350px' : '20px';
}
function onHashChange() {
hashes = location.hash.split ( '#' );
if ( hashes.length < 1 ) { return; }
var fileName = hashes[ 1 ].toLowerCase();
var fileType = (fileName.substr( fileName.lastIndexOf( '.' )).toLowerCase() );
if ( fileType === '.html' || fileType === '.htm' ) {
loadHTMLInIframe( location.hash );
} else if ( fileType === '.md' ) {
loadMarkdownInDiv( fileName );
}
}
function loadHTMLInIframe( hash, callback ) {
ifr = resetIframe( callback );
ifr.src = hash.substr( 1 );
}
function loadMarkdownInMenu( fileName, panel ) {
var converter = new Showdown.converter();
var xmlHttp = new XMLHttpRequest ();
xmlHttp.open( 'GET', fileName, true );
xmlHttp.onreadystatechange = callback;
xmlHttp.send( null );
function callback() {
if ( xmlHttp.readyState === 4 ) {
text = xmlHttp.responseText;
panel.innerHTML = converter.makeHtml( text );
items = panel.getElementsByTagName( 'h2' );
for ( var i = 0; i < items.length; i++ ) {
items[ i ].style.cssText += 'background-color: #f8f8f8; padding: 0 5px;' ;
items[ i ].id = 't' + i;
if ( items[ i ].innerHTML.indexOf( '(open)' ) === -1 ) {
items[ i ].className += ' close';
item = items[ i ].nextElementSibling;
while ( item && item.tagName !== 'H2' ) {
item.style.display = 'none';
item = item.nextElementSibling;
}
} else {
items[ i ].className += ' open';
items[ i ].innerHTML = items[ i ].innerHTML.replace( '(open)','' );
}
items[ i ].onclick = function() { toggle( this ); };
}
}
}
}
function toggle( element ) {
var element = document.getElementById( element.id );
var content = element.nextElementSibling;
if ( content.style.display === '' ) {
while ( content && content.tagName !== 'H2' ) {
content.style.display = 'none';
content = content.nextElementSibling;
}
element.className = 'toggle close';
} else {
while ( content && content.tagName !== 'H2' ) {
content.style.display = '';
content = content.nextElementSibling;
}
element.className = 'toggle open';
}
}
function loadMarkdownInDiv( fileName ) {
var converter = new Showdown.converter();
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( 'GET', fileName, true );
xmlHttp.onreadystatechange = callbackDiv;
xmlHttp.send( null );
function callbackDiv() {
if ( xmlHttp.readyState === 4 ) {
var text = xmlHttp.responseText;
if ( !content || !content.innerHTML ) {
content = document.body.appendChild( document.createElement( 'div' ) );
content.style.cssText = 'border: 0px solid red; font: bold 12pt monospace; left: 350px; margin: 20px auto; position: absolute; ' +
'right: 0; max-width: 800px; ' +
'';
}
content.innerHTML = converter.makeHtml( text );
}
document.body.style.overflow = 'auto';
}
}
function loadMarkdownInIframe( hash, callback ) {
ifr = resetIframe( callback );
var srcdoc =
"<div id=doc ><\/div>" +
"<script src=http://cdnjs.cloudflare.com/ajax/libs/showdown/0.3.1/showdown.min.js ><\/script>" +
"<script>" +
" doc.style.cssText = 'font: bold 12pt monospace; margin: auto; max-width: 600px';" +
" var xmlHttp;" +
" var converter = new Showdown.converter();" +
" requestFile( '" + hash.substr( 1 ) + "' );" +
" function requestFile( fileName ) {" +
" xmlHttp = new XMLHttpRequest();" +
" xmlHttp.open( 'GET', fileName, true );" +
" xmlHttp.onreadystatechange = callback;" +
" xmlHttp.send( null );" +
" }" +
" function callback() {" +
" var text = xmlHttp.responseText;" +
" text = converter.makeHtml( text );" +
" doc.innerHTML = text;" +
" }" +
"<\/script>" +
"";
ifr.srcdoc = srcdoc;
// slideMenu(); // to hide
// location.hash = '';
};
function resetIframe( callback ) {
if ( content && content.innerHTML ) { content.innerHTML = ''; }
var iframes = document.getElementsByTagName( 'iframe' );
for ( var i = 0, len = iframes.length; i < len; i++ ) {
iframes[0].parentNode.removeChild( iframes[ 0 ] );
}
document.body.style.overflow = 'hidden';
var ifr = document.body.appendChild( document.createElement( 'iframe' ) );
ifr.width = window.innerWidth;
ifr.height = window.innerHeight;
ifr.style.cssText = 'border-width: 0; position: absolute; z-index: -10';
ifr.style.cssText = 'border-width: 0; left: 0; margin: auto; position: absolute; right: 0; z-index: -10';
ifr.onload = callback || function() {};
return ifr;
}
</script>
</body>
</html>