2
0

index.html 11 KB

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