2
0

index.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>three.js docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <link rel="shortcut icon" href="../files/favicon_white.ico" media="(prefers-color-scheme: dark)"/>
  8. <link rel="shortcut icon" href="../files/favicon.ico" media="(prefers-color-scheme: light)" />
  9. <link rel="stylesheet" type="text/css" href="../files/main.css">
  10. <!-- console sandbox -->
  11. <script src="../build/three.min.js" async defer></script>
  12. </head>
  13. <body>
  14. <div id="panel">
  15. <div id="header">
  16. <h1><a href="https://threejs.org">three.js</a></h1>
  17. <div id="sections">
  18. <span class="selected">docs</span>
  19. <a href="../examples/#webgl_animation_keyframes">examples</a>
  20. </div>
  21. <div id="expandButton"></div>
  22. </div>
  23. <div id="panelScrim"></div>
  24. <div id="contentWrapper">
  25. <div id="inputWrapper">
  26. <input placeholder="" type="text" id="filterInput" autocorrect="off" autocapitalize="off" spellcheck="false" />
  27. <div id="exitSearchButton"></div>
  28. <select id="language">
  29. <option value="en">en</option>
  30. <option value="ar">ar</option>
  31. <option value="ko">한국어</option>
  32. <option value="zh">中文</option>
  33. <option value="ja">日本語</option>
  34. <option value="it">it</option>
  35. <option value="pt-br">pt-br</option>
  36. <option value="fr">fr</option>
  37. </select>
  38. </div>
  39. <div id="content"></div>
  40. </div>
  41. </div>
  42. <iframe name="viewer"></iframe>
  43. <script>
  44. const panel = document.getElementById( 'panel' );
  45. const content = document.getElementById( 'content' );
  46. const expandButton = document.getElementById( 'expandButton' );
  47. const exitSearchButton = document.getElementById( 'exitSearchButton' );
  48. const panelScrim = document.getElementById( 'panelScrim' );
  49. const filterInput = document.getElementById( 'filterInput' );
  50. let iframe = document.querySelector( 'iframe' );
  51. const sectionLink = document.querySelector( '#sections > a' );
  52. const sectionDefaultHref = sectionLink.href;
  53. const pageProperties = {};
  54. const titles = {};
  55. const categoryElements = [];
  56. let navigation;
  57. init();
  58. async function init() {
  59. const list = await ( await fetch( 'list.json' ) ).json();
  60. // *BufferGeometry to *Geometry
  61. if ( /Instanced/.exec( window.location.hash ) === null && /([\w]+)BufferGeometry$/.exec( window.location.hash ) ) {
  62. window.location.hash = window.location.hash.replace( 'BufferGeometry', 'Geometry' );
  63. }
  64. const hash = window.location.hash.substring( 1 );
  65. // Localisation
  66. let language = 'en';
  67. if ( /^(api|manual|examples)/.test( hash ) ) {
  68. const hashLanguage = /^(api|manual|examples)\/(en|ar|ko|zh|ja|it|pt-br|fr)\//.exec( hash );
  69. if ( hashLanguage === null ) {
  70. // Route old non-localised api links
  71. window.location.hash = hash.replace( /^(api|manual|examples)/, '$1/en' );
  72. } else {
  73. language = hashLanguage[ 2 ];
  74. }
  75. }
  76. const languageSelect = document.getElementById( 'language' );
  77. languageSelect.value = language;
  78. languageSelect.addEventListener( 'change', function () {
  79. setLanguage( this.value );
  80. } );
  81. function setLanguage( value ) {
  82. language = value;
  83. createNavigation( list, language );
  84. updateFilter();
  85. autoChangeUrlLanguage( language );
  86. }
  87. // Functionality for hamburger button (on small devices)
  88. expandButton.onclick = function ( event ) {
  89. event.preventDefault();
  90. panel.classList.toggle( 'open' );
  91. };
  92. panelScrim.onclick = function ( event ) {
  93. event.preventDefault();
  94. panel.classList.toggle( 'open' );
  95. };
  96. // Functionality for search/filter input field
  97. filterInput.onfocus = function () {
  98. panel.classList.add( 'searchFocused' );
  99. };
  100. filterInput.onblur = function () {
  101. if ( filterInput.value === '' ) {
  102. panel.classList.remove( 'searchFocused' );
  103. }
  104. };
  105. filterInput.oninput = function () {
  106. updateFilter();
  107. };
  108. exitSearchButton.onclick = function () {
  109. filterInput.value = '';
  110. updateFilter();
  111. panel.classList.remove( 'searchFocused' );
  112. };
  113. // Activate content and title change on browser navigation
  114. window.onpopstate = createNewIframe;
  115. // Create the navigation panel and configure the iframe
  116. createNavigation( list, language );
  117. createNewIframe();
  118. // Handle search query
  119. filterInput.value = extractQuery();
  120. if ( filterInput.value !== '' ) {
  121. panel.classList.add( 'searchFocused' );
  122. updateFilter();
  123. } else {
  124. updateLink( '' );
  125. }
  126. }
  127. // Navigation Panel
  128. function createLink( pageName, pageURL ) {
  129. const link = document.createElement( 'a' );
  130. link.href = pageURL + '.html';
  131. link.textContent = pageName;
  132. link.setAttribute( 'target', 'viewer' );
  133. link.addEventListener( 'click', function ( event ) {
  134. if ( event.button !== 0 || event.ctrlKey || event.altKey || event.metaKey ) return;
  135. window.location.hash = pageURL;
  136. panel.classList.remove( 'open' );
  137. content.querySelectorAll( 'a' ).forEach( function ( item ) {
  138. item.classList.remove( 'selected' );
  139. } );
  140. link.classList.add( 'selected' );
  141. } );
  142. return link;
  143. }
  144. function createNavigation( list, language ) {
  145. if ( navigation !== undefined ) {
  146. content.removeChild( navigation );
  147. }
  148. // Create the navigation panel using data from list.js
  149. navigation = document.createElement( 'div' );
  150. content.appendChild( navigation );
  151. if ( language === 'ar' ) {
  152. navigation.style.direction = 'rtl';
  153. }
  154. const localList = list[ language ];
  155. const selectedPage = window.location.hash.substring( 1 );
  156. for ( const section in localList ) {
  157. // Create sections
  158. const categories = localList[ section ];
  159. const sectionHead = document.createElement( 'h2' );
  160. sectionHead.textContent = section;
  161. navigation.appendChild( sectionHead );
  162. for ( const category in categories ) {
  163. // Create categories
  164. const pages = categories[ category ];
  165. const categoryContainer = document.createElement( 'div' );
  166. navigation.appendChild( categoryContainer );
  167. const categoryHead = document.createElement( 'h3' );
  168. categoryHead.textContent = category;
  169. categoryContainer.appendChild( categoryHead );
  170. const categoryContent = document.createElement( 'ul' );
  171. categoryContainer.appendChild( categoryContent );
  172. for ( const pageName in pages ) {
  173. // Create page links
  174. const pageURL = pages[ pageName ];
  175. // Localisation
  176. const listElement = document.createElement( 'li' );
  177. categoryContent.appendChild( listElement );
  178. const linkElement = createLink( pageName, pageURL );
  179. listElement.appendChild( linkElement );
  180. // select current page
  181. if ( pageURL === selectedPage ) {
  182. linkElement.classList.add( 'selected' );
  183. }
  184. // Gather the main properties for the current subpage
  185. pageProperties[ pageName ] = {
  186. section: section,
  187. category: category,
  188. pageURL: pageURL,
  189. linkElement: linkElement
  190. };
  191. // Gather the document titles (used for easy access on browser navigation)
  192. titles[ pageURL ] = pageName;
  193. }
  194. // Gather the category elements for easy access on filtering
  195. categoryElements.push( categoryContent );
  196. }
  197. }
  198. }
  199. // 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
  200. function autoChangeUrlLanguage( language ) {
  201. const hash = location.hash;
  202. if ( hash === '' ) return;
  203. const docType = hash.slice( 0, hash.indexOf( '/' ) + 1 );
  204. let docLink = hash.slice( hash.indexOf( '/' ) + 1 );
  205. docLink = docLink.slice( docLink.indexOf( '/' ) );
  206. location.href = docType + language + docLink;
  207. }
  208. // Filtering
  209. function extractQuery() {
  210. const search = window.location.search;
  211. if ( search.indexOf( '?q=' ) !== - 1 ) {
  212. return decodeURI( search.slice( 3 ) );
  213. }
  214. return '';
  215. }
  216. function escapeRegExp( string ) {
  217. return string.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' ); // https://stackoverflow.com/a/6969486/5250847
  218. }
  219. function updateFilter() {
  220. let v = filterInput.value.trim();
  221. v = v.replace( /\s+/gi, ' ' ); // replace multiple whitespaces with a single one
  222. if ( v !== '' ) {
  223. window.history.replaceState( {}, '', '?q=' + v + window.location.hash );
  224. } else {
  225. window.history.replaceState( {}, '', window.location.pathname + window.location.hash );
  226. }
  227. //
  228. const regExp = new RegExp( escapeRegExp( v ), 'gi' );
  229. for ( let pageName in pageProperties ) {
  230. const linkElement = pageProperties[ pageName ].linkElement;
  231. const categoryClassList = linkElement.parentElement.classList;
  232. const filterResults = pageName.match( regExp );
  233. if ( filterResults !== null && filterResults.length > 0 ) {
  234. pageName = pageName.replaceAll( regExp, '<b>$&</b>' );
  235. categoryClassList.remove( 'hidden' );
  236. linkElement.innerHTML = pageName;
  237. } else {
  238. // Hide all non-matching page names
  239. categoryClassList.add( 'hidden' );
  240. }
  241. }
  242. displayFilteredPanel();
  243. updateLink( v );
  244. }
  245. function updateLink( search ) {
  246. // update examples link
  247. if ( search ) {
  248. const link = sectionLink.href.split( /[?#]/ )[ 0 ];
  249. sectionLink.href = `${link}?q=${search}`;
  250. } else {
  251. sectionLink.href = sectionDefaultHref;
  252. }
  253. }
  254. function displayFilteredPanel() {
  255. // Show/hide categories depending on their content
  256. // First check if at least one page in this category is not hidden
  257. categoryElements.forEach( function ( category ) {
  258. const pages = category.children;
  259. const pagesLength = pages.length;
  260. const sectionClassList = category.parentElement.classList;
  261. let hideCategory = true;
  262. for ( let i = 0; i < pagesLength; i ++ ) {
  263. const pageClassList = pages[ i ].classList;
  264. if ( ! pageClassList.contains( 'hidden' ) ) {
  265. hideCategory = false;
  266. }
  267. }
  268. // If and only if all page names are hidden, hide the whole category
  269. if ( hideCategory ) {
  270. sectionClassList.add( 'hidden' );
  271. } else {
  272. sectionClassList.remove( 'hidden' );
  273. }
  274. } );
  275. }
  276. // Routing
  277. function setUrlFragment( pageName ) { // eslint-disable-line no-unused-vars
  278. // Handle navigation from the subpages (iframes):
  279. // First separate the member (if existing) from the page name,
  280. // then identify the subpage's URL and set it as URL fragment (re-adding the member)
  281. const splitPageName = decomposePageName( pageName, '.', '.' );
  282. const currentProperties = pageProperties[ splitPageName[ 0 ] ];
  283. if ( currentProperties ) {
  284. window.location.hash = currentProperties.pageURL + splitPageName[ 1 ];
  285. createNewIframe();
  286. }
  287. }
  288. function createNewIframe() {
  289. // Change the content displayed in the iframe
  290. // First separate the member part of the fragment (if existing)
  291. const hash = window.location.hash.substring( 1 );
  292. const splitHash = decomposePageName( hash, '.', '#' );
  293. // Creating a new Iframe instead of assigning a new src is
  294. // a cross-browser solution to allow normal browser navigation;
  295. // - only assigning a new src would result in two history states each time.
  296. // Note: iframe.contentWindow.location.replace(hash) should work, too,
  297. // but it doesn't work in Edge with links from the subpages!
  298. let subtitle;
  299. const oldIframe = iframe;
  300. iframe = oldIframe.cloneNode();
  301. if ( hash && titles[ splitHash[ 0 ] ] ) {
  302. iframe.src = splitHash[ 0 ] + '.html' + splitHash[ 1 ];
  303. subtitle = titles[ splitHash[ 0 ] ] + splitHash[ 1 ] + ' – ';
  304. iframe.style.display = 'unset';
  305. } else {
  306. iframe.src = '';
  307. subtitle = '';
  308. iframe.style.display = 'none';
  309. }
  310. document.body.replaceChild( iframe, oldIframe );
  311. document.title = subtitle + 'three.js docs';
  312. }
  313. function decomposePageName( pageName, oldDelimiter, newDelimiter ) {
  314. // Helper function for separating the member (if existing) from the pageName
  315. // For example: 'Geometry.morphTarget' can be converted to
  316. // ['Geometry', '.morphTarget'] or ['Geometry', '#morphTarget']
  317. // Note: According RFC 3986 no '#' allowed inside of an URL fragment!
  318. let parts = [];
  319. const dotIndex = pageName.indexOf( oldDelimiter );
  320. if ( dotIndex !== - 1 ) {
  321. parts = pageName.split( oldDelimiter );
  322. parts[ 1 ] = newDelimiter + parts[ 1 ];
  323. } else {
  324. parts[ 0 ] = pageName;
  325. parts[ 1 ] = '';
  326. }
  327. return parts;
  328. }
  329. //
  330. console.log( [
  331. ' __ __',
  332. ' __/ __\\ / __\\__ ____ _____ _____',
  333. '/ __/ /\\/ / /___\\/ ____\\/ _____\\/ _____\\',
  334. '\\/_ __/ / _ / / __/ / __ / / __ /_ __ _____',
  335. '/ / / / / / / / / / / / ___/ / ___/\\ _\\/ __\\/ _____\\',
  336. '\\/__/ \\/__/\\/__/\\/__/ \\/_____/\\/_____/\\/__/ / / / ___/',
  337. ' / __/ / \\__ \\',
  338. ' \\/____/\\/_____/'
  339. ].join( '\n' ) );
  340. </script>
  341. </body>
  342. </html>