index.html 13 KB

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