index.html 13 KB

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