-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
/
Copy pathindex.html
601 lines (357 loc) · 13.3 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
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>three.js docs</title>
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link rel="shortcut icon" href="../files/favicon_white.ico" media="(prefers-color-scheme: dark)"/>
<link rel="shortcut icon" href="../files/favicon.ico" media="(prefers-color-scheme: light)" />
<link rel="stylesheet" type="text/css" href="../files/main.css">
<!-- console sandbox -->
<script type="module">
import * as THREE from '../build/three.module.js';
window.THREE = THREE;
</script>
</head>
<body>
<div id="panel">
<div id="header">
<h1><a href="https://threejs.org">three.js</a></h1>
<div id="sections">
<span class="selected">docs</span>
<a href="../examples/#webgl_animation_keyframes">examples</a>
</div>
<div id="expandButton"></div>
</div>
<div id="panelScrim"></div>
<div id="contentWrapper">
<div id="inputWrapper">
<input placeholder="" type="text" id="filterInput" autocorrect="off" autocapitalize="off" spellcheck="false" />
<div id="clearSearchButton"></div>
<select id="language">
<option value="en">en</option>
<option value="ar">ar</option>
<option value="ko">한국어</option>
<option value="zh">中文</option>
<option value="ja">日本語</option>
<option value="it">it</option>
<option value="pt-br">pt-br</option>
<option value="fr">fr</option>
<option value="ru">ru</option>
</select>
</div>
<div id="content"></div>
</div>
</div>
<iframe name="viewer"></iframe>
<script>
const panel = document.getElementById( 'panel' );
const content = document.getElementById( 'content' );
const expandButton = document.getElementById( 'expandButton' );
const clearSearchButton = document.getElementById( 'clearSearchButton' );
const panelScrim = document.getElementById( 'panelScrim' );
const filterInput = document.getElementById( 'filterInput' );
let iframe = document.querySelector( 'iframe' );
const sectionLink = document.querySelector( '#sections > a' );
const sectionDefaultHref = sectionLink.href;
const pageProperties = {};
const titles = {};
const categoryElements = [];
let navigation;
init();
async function init() {
const list = await ( await fetch( 'list.json' ) ).json();
// *BufferGeometry to *Geometry
if ( /Instanced/.exec( window.location.hash ) === null && /([\w]+)BufferGeometry$/.exec( window.location.hash ) ) {
window.location.hash = window.location.hash.replace( 'BufferGeometry', 'Geometry' );
}
const hash = window.location.hash.substring( 1 );
// Localisation
let language = 'en';
if ( /^(api|manual|examples)/.test( hash ) ) {
const hashLanguage = /^(api|manual|examples)\/(en|ar|ko|zh|ja|it|pt-br|fr|ru)\//.exec( hash );
if ( hashLanguage === null ) {
// Route old non-localised api links
window.location.hash = hash.replace( /^(api|manual|examples)/, '$1/en' );
} else {
language = hashLanguage[ 2 ];
}
}
const languageSelect = document.getElementById( 'language' );
languageSelect.value = language;
languageSelect.addEventListener( 'change', function () {
setLanguage( this.value );
} );
function setLanguage( value ) {
language = value;
createNavigation( list, language );
updateFilter();
autoChangeUrlLanguage( language );
}
// Functionality for hamburger button (on small devices)
expandButton.onclick = function ( event ) {
event.preventDefault();
panel.classList.toggle( 'open' );
};
panelScrim.onclick = function ( event ) {
event.preventDefault();
panel.classList.toggle( 'open' );
};
// Functionality for search/filter input field
filterInput.onfocus = function () {
panel.classList.add( 'searchFocused' );
};
filterInput.onblur = function () {
if ( filterInput.value === '' ) {
panel.classList.remove( 'searchFocused' );
}
};
filterInput.oninput = function () {
updateFilter();
};
clearSearchButton.onclick = function () {
filterInput.value = '';
updateFilter();
filterInput.focus();
};
// Activate content and title change on browser navigation
window.onpopstate = createNewIframe;
// Create the navigation panel and configure the iframe
createNavigation( list, language );
createNewIframe();
// Handle search query
filterInput.value = extractQuery();
if ( filterInput.value !== '' ) {
panel.classList.add( 'searchFocused' );
updateFilter();
} else {
updateLink( '' );
}
}
// Navigation Panel
function createLink( pageName, pageURL ) {
const link = document.createElement( 'a' );
link.href = pageURL + '.html';
link.textContent = pageName;
link.setAttribute( 'target', 'viewer' );
link.addEventListener( 'click', function ( event ) {
if ( event.button !== 0 || event.ctrlKey || event.altKey || event.metaKey ) return;
window.location.hash = pageURL;
panel.classList.remove( 'open' );
content.querySelectorAll( 'a' ).forEach( function ( item ) {
item.classList.remove( 'selected' );
} );
link.classList.add( 'selected' );
} );
return link;
}
function createNavigation( list, language ) {
if ( navigation !== undefined ) {
content.removeChild( navigation );
}
// Create the navigation panel using data from list.js
navigation = document.createElement( 'div' );
content.appendChild( navigation );
if ( language === 'ar' ) {
navigation.style.direction = 'rtl';
}
const localList = list[ language ];
const selectedPage = window.location.hash.substring( 1 );
for ( const section in localList ) {
// Create sections
const categories = localList[ section ];
const sectionHead = document.createElement( 'h2' );
sectionHead.textContent = section;
navigation.appendChild( sectionHead );
for ( const category in categories ) {
// Create categories
const pages = categories[ category ];
const categoryContainer = document.createElement( 'div' );
navigation.appendChild( categoryContainer );
const categoryHead = document.createElement( 'h3' );
categoryHead.textContent = category;
categoryContainer.appendChild( categoryHead );
const categoryContent = document.createElement( 'ul' );
categoryContainer.appendChild( categoryContent );
for ( const pageName in pages ) {
// Create page links
const pageURL = pages[ pageName ];
// Localisation
const listElement = document.createElement( 'li' );
categoryContent.appendChild( listElement );
const linkElement = createLink( pageName, pageURL );
listElement.appendChild( linkElement );
// select current page
if ( pageURL === selectedPage ) {
linkElement.classList.add( 'selected' );
}
// Gather the main properties for the current subpage
pageProperties[ pageName ] = {
section: section,
category: category,
pageURL: pageURL,
linkElement: linkElement
};
// Gather the document titles (used for easy access on browser navigation)
titles[ pageURL ] = pageName;
}
// Gather the category elements for easy access on filtering
categoryElements.push( categoryContent );
}
}
}
// Auto change language url. If a reader open a document in English, when they click "zh", the document they read will auto change into Chinese version
function autoChangeUrlLanguage( language ) {
const hash = location.hash;
if ( hash === '' ) return;
const docType = hash.slice( 0, hash.indexOf( '/' ) + 1 );
let docLink = hash.slice( hash.indexOf( '/' ) + 1 );
docLink = docLink.slice( docLink.indexOf( '/' ) );
location.href = docType + language + docLink;
}
// Filtering
function extractQuery() {
const search = window.location.search;
if ( search.indexOf( '?q=' ) !== - 1 ) {
return decodeURI( search.slice( 3 ) );
}
return '';
}
function escapeRegExp( string ) {
string = string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ); // https://stackoverflow.com/a/6969486/5250847
return '(?=.*' + string.split( ' ' ).join( ')(?=.*' ) + ')'; // match all words, in any order
}
function updateFilter() {
let v = filterInput.value.trim();
v = v.replace( /\s+/gi, ' ' ); // replace multiple whitespaces with a single one
if ( v !== '' ) {
window.history.replaceState( {}, '', '?q=' + v + window.location.hash );
} else {
window.history.replaceState( {}, '', window.location.pathname + window.location.hash );
}
//
const regExp = new RegExp( escapeRegExp( v ), 'gi' );
for ( let pageName in pageProperties ) {
const linkElement = pageProperties[ pageName ].linkElement;
const categoryClassList = linkElement.parentElement.classList;
const filterResults = pageName.match( regExp );
if ( filterResults !== null && filterResults.length > 0 ) {
pageName = pageName.replaceAll( regExp, '<b>$&</b>' );
categoryClassList.remove( 'hidden' );
linkElement.innerHTML = pageName;
} else {
// Hide all non-matching page names
categoryClassList.add( 'hidden' );
}
}
displayFilteredPanel();
updateLink( v );
}
function updateLink( search ) {
// update examples link
if ( search ) {
const link = sectionLink.href.split( /[?#]/ )[ 0 ];
sectionLink.href = `${link}?q=${search}`;
} else {
sectionLink.href = sectionDefaultHref;
}
}
function displayFilteredPanel() {
// Show/hide categories depending on their content
// First check if at least one page in this category is not hidden
categoryElements.forEach( function ( category ) {
const pages = category.children;
const pagesLength = pages.length;
const sectionClassList = category.parentElement.classList;
let hideCategory = true;
for ( let i = 0; i < pagesLength; i ++ ) {
const pageClassList = pages[ i ].classList;
if ( ! pageClassList.contains( 'hidden' ) ) {
hideCategory = false;
}
}
// If and only if all page names are hidden, hide the whole category
if ( hideCategory ) {
sectionClassList.add( 'hidden' );
} else {
sectionClassList.remove( 'hidden' );
}
} );
}
// Routing
function setUrlFragment( pageName ) { // eslint-disable-line no-unused-vars
// Handle navigation from the subpages (iframes):
// First separate the member (if existing) from the page name,
// then identify the subpage's URL and set it as URL fragment (re-adding the member)
const pageURL = getPageURL( pageName );
if ( pageURL ) {
window.location.hash = pageURL;
createNewIframe();
}
}
function getPageURL( pageName ) {
const splitPageName = decomposePageName( pageName, '.', '.' );
const currentProperties = pageProperties[ splitPageName[ 0 ] ];
if ( currentProperties ) {
return currentProperties.pageURL + splitPageName[ 1 ];
} else {
return null;
}
}
function createNewIframe() {
// Change the content displayed in the iframe
// First separate the member part of the fragment (if existing)
const hash = window.location.hash.substring( 1 );
const splitHash = decomposePageName( hash, '.', '#' );
// Creating a new Iframe instead of assigning a new src is
// a cross-browser solution to allow normal browser navigation;
// - only assigning a new src would result in two history states each time.
// Note: iframe.contentWindow.location.replace(hash) should work, too,
// but it doesn't work in Edge with links from the subpages!
let subtitle;
const oldIframe = iframe;
iframe = oldIframe.cloneNode();
iframe.style.display = 'none';
if ( hash && titles[ splitHash[ 0 ] ] ) {
iframe.onload = function () {
iframe.style.display = 'unset';
};
iframe.src = splitHash[ 0 ] + '.html' + splitHash[ 1 ];
subtitle = titles[ splitHash[ 0 ] ] + splitHash[ 1 ] + ' – ';
} else {
iframe.src = '';
subtitle = '';
}
document.body.replaceChild( iframe, oldIframe );
document.title = subtitle + 'three.js docs';
}
function decomposePageName( pageName, oldDelimiter, newDelimiter ) {
// Helper function for separating the member (if existing) from the pageName
// For example: 'Geometry.morphTarget' can be converted to
// ['Geometry', '.morphTarget'] or ['Geometry', '#morphTarget']
// Note: According RFC 3986 no '#' allowed inside of an URL fragment!
let parts = [];
const dotIndex = pageName.indexOf( oldDelimiter );
if ( dotIndex !== - 1 ) {
parts = pageName.split( oldDelimiter );
parts[ 1 ] = newDelimiter + parts[ 1 ];
} else {
parts[ 0 ] = pageName;
parts[ 1 ] = '';
}
return parts;
}
//
console.log( [
' __ __',
' __/ __\\ / __\\__ ____ _____ _____',
'/ __/ /\\/ / /___\\/ ____\\/ _____\\/ _____\\',
'\\/_ __/ / _ / / __/ / __ / / __ /_ __ _____',
'/ / / / / / / / / / / / ___/ / ___/\\ _\\/ __\\/ _____\\',
'\\/__/ \\/__/\\/__/\\/__/ \\/_____/\\/_____/\\/__/ / / / ___/',
' / __/ / \\__ \\',
' \\/____/\\/_____/'
].join( '\n' ) );
</script>
</body>
</html>