index.html 13 KB

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