index.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  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 he click "zh", the document he read will auto change into Chinese version
  207. function autoChangeUrlLanguage( language ) {
  208. const hash = location.hash;
  209. if ( hash === '' ) return;
  210. const docType = hash.substr( 0, hash.indexOf( '/' ) + 1 );
  211. let docLink = hash.substr( hash.indexOf( '/' ) + 1 );
  212. docLink = docLink.substr( 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.substr( 3 ) );
  220. }
  221. return '';
  222. }
  223. function updateFilter() {
  224. let v = filterInput.value.trim();
  225. v = v.replace( /\s+/gi, ' ' ); // replace multiple whitespaces with a single one
  226. if ( v !== '' ) {
  227. window.history.replaceState( {}, '', '?q=' + v + window.location.hash );
  228. } else {
  229. window.history.replaceState( {}, '', window.location.pathname + window.location.hash );
  230. }
  231. //
  232. const regExp = new RegExp( filterInput.value, 'gi' );
  233. for ( let pageName in pageProperties ) {
  234. const linkElement = pageProperties[ pageName ].linkElement;
  235. const categoryClassList = linkElement.parentElement.classList;
  236. const filterResults = pageName.match( regExp );
  237. if ( filterResults !== null && filterResults.length > 0 ) {
  238. pageName = pageName.replaceAll( regExp, '<b>$&</b>' );
  239. categoryClassList.remove( 'hidden' );
  240. linkElement.innerHTML = pageName;
  241. } else {
  242. // Hide all non-matching page names
  243. categoryClassList.add( 'hidden' );
  244. }
  245. }
  246. displayFilteredPanel();
  247. updateLink( v );
  248. }
  249. function updateLink( search ) {
  250. // update examples link
  251. if ( search ) {
  252. let link = sectionLink.href.split( /[?#]/ )[ 0 ];
  253. sectionLink.href = `${link}?q=${search}`;
  254. } else {
  255. sectionLink.href = sectionDefaultHref;
  256. }
  257. }
  258. function displayFilteredPanel() {
  259. // Show/hide categories depending on their content
  260. // First check if at least one page in this category is not hidden
  261. categoryElements.forEach( function ( category ) {
  262. const pages = category.children;
  263. const pagesLength = pages.length;
  264. const sectionClassList = category.parentElement.classList;
  265. let hideCategory = true;
  266. for ( let i = 0; i < pagesLength; i ++ ) {
  267. const pageClassList = pages[ i ].classList;
  268. if ( ! pageClassList.contains( 'hidden' ) ) {
  269. hideCategory = false;
  270. }
  271. }
  272. // If and only if all page names are hidden, hide the whole category
  273. if ( hideCategory ) {
  274. sectionClassList.add( 'hidden' );
  275. } else {
  276. sectionClassList.remove( 'hidden' );
  277. }
  278. } );
  279. }
  280. // Routing
  281. function setUrlFragment( pageName ) { // eslint-disable-line no-undef
  282. // Handle navigation from the subpages (iframes):
  283. // First separate the member (if existing) from the page name,
  284. // then identify the subpage's URL and set it as URL fragment (re-adding the member)
  285. const splitPageName = decomposePageName( pageName, '.', '.' );
  286. const currentProperties = pageProperties[ splitPageName[ 0 ] ];
  287. if ( currentProperties ) {
  288. window.location.hash = currentProperties.pageURL + splitPageName[ 1 ];
  289. createNewIframe();
  290. }
  291. }
  292. function createNewIframe() {
  293. // Change the content displayed in the iframe
  294. // First separate the member part of the fragment (if existing)
  295. const hash = window.location.hash.substring( 1 );
  296. const splitHash = decomposePageName( hash, '.', '#' );
  297. // Creating a new Iframe instead of assigning a new src is
  298. // a cross-browser solution to allow normal browser navigation;
  299. // - only assigning a new src would result in two history states each time.
  300. // Note: iframe.contentWindow.location.replace(hash) should work, too,
  301. // but it doesn't work in Edge with links from the subpages!
  302. let subtitle;
  303. const oldIframe = iframe;
  304. iframe = oldIframe.cloneNode();
  305. if ( hash ) {
  306. iframe.src = splitHash[ 0 ] + '.html' + splitHash[ 1 ];
  307. subtitle = titles[ splitHash[ 0 ] ] + splitHash[ 1 ] + ' – ';
  308. iframe.style.display = 'unset';
  309. } else {
  310. iframe.src = '';
  311. subtitle = '';
  312. iframe.style.display = 'none';
  313. }
  314. document.body.replaceChild( iframe, oldIframe );
  315. document.title = subtitle + 'three.js docs';
  316. }
  317. function decomposePageName( pageName, oldDelimiter, newDelimiter ) {
  318. // Helper function for separating the member (if existing) from the pageName
  319. // For example: 'Geometry.morphTarget' can be converted to
  320. // ['Geometry', '.morphTarget'] or ['Geometry', '#morphTarget']
  321. // Note: According RFC 3986 no '#' allowed inside of an URL fragment!
  322. let parts = [];
  323. const dotIndex = pageName.indexOf( oldDelimiter );
  324. if ( dotIndex !== - 1 ) {
  325. parts = pageName.split( oldDelimiter );
  326. parts[ 1 ] = newDelimiter + parts[ 1 ];
  327. } else {
  328. parts[ 0 ] = pageName;
  329. parts[ 1 ] = '';
  330. }
  331. return parts;
  332. }
  333. //
  334. console.log( [
  335. ' __ __',
  336. ' __/ __\\ / __\\__ ____ _____ _____',
  337. '/ __/ /\\/ / /___\\/ ____\\/ _____\\/ _____\\',
  338. '\\/_ __/ / _ / / __/ / __ / / __ /_ __ _____',
  339. '/ / / / / / / / / / / / ___/ / ___/\\ _\\/ __\\/ _____\\',
  340. '\\/__/ \\/__/\\/__/\\/__/ \\/_____/\\/_____/\\/__/ / / / ___/',
  341. ' / __/ / \\__ \\',
  342. ' \\/____/\\/_____/'
  343. ].join( '\n' ) );
  344. </script>
  345. </body>
  346. </html>