index.html 13 KB

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