index.html 12 KB

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