index.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  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 ( /([\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. for ( const section in localList ) {
  148. // Create sections
  149. const categories = localList[ section ];
  150. const sectionHead = document.createElement( 'h2' );
  151. sectionHead.textContent = section;
  152. navigation.appendChild( sectionHead );
  153. for ( const category in categories ) {
  154. // Create categories
  155. const pages = categories[ category ];
  156. const categoryContainer = document.createElement( 'div' );
  157. navigation.appendChild( categoryContainer );
  158. const categoryHead = document.createElement( 'h3' );
  159. categoryHead.textContent = category;
  160. categoryContainer.appendChild( categoryHead );
  161. const categoryContent = document.createElement( 'ul' );
  162. categoryContainer.appendChild( categoryContent );
  163. for ( const pageName in pages ) {
  164. // Create page links
  165. const pageURL = pages[ pageName ];
  166. // Localisation
  167. const listElement = document.createElement( 'li' );
  168. categoryContent.appendChild( listElement );
  169. const linkElement = createLink( pageName, pageURL );
  170. listElement.appendChild( linkElement );
  171. // Gather the main properties for the current subpage
  172. pageProperties[ pageName ] = {
  173. section: section,
  174. category: category,
  175. pageURL: pageURL,
  176. linkElement: linkElement
  177. };
  178. // Gather the document titles (used for easy access on browser navigation)
  179. titles[ pageURL ] = pageName;
  180. }
  181. // Gather the category elements for easy access on filtering
  182. categoryElements.push( categoryContent );
  183. }
  184. }
  185. }
  186. // 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
  187. function autoChangeUrlLanguage( language ) {
  188. const hash = location.hash;
  189. if ( hash === '' ) return;
  190. const docType = hash.substr( 0, hash.indexOf( '/' ) + 1 );
  191. let docLink = hash.substr( hash.indexOf( '/' ) + 1 );
  192. docLink = docLink.substr( docLink.indexOf( '/' ) );
  193. location.href = docType + language + docLink;
  194. }
  195. // Filtering
  196. function extractQuery() {
  197. const search = window.location.search;
  198. if ( search.indexOf( '?q=' ) !== - 1 ) {
  199. return decodeURI( search.substr( 3 ) );
  200. }
  201. return '';
  202. }
  203. function updateFilter() {
  204. let v = filterInput.value.trim();
  205. v = v.replace( /\s+/gi, ' ' ); // replace multiple whitespaces with a single one
  206. if ( v !== '' ) {
  207. window.history.replaceState( {}, '', '?q=' + v + window.location.hash );
  208. } else {
  209. window.history.replaceState( {}, '', window.location.pathname + window.location.hash );
  210. }
  211. //
  212. const regExp = new RegExp( filterInput.value, 'gi' );
  213. for ( let pageName in pageProperties ) {
  214. const linkElement = pageProperties[ pageName ].linkElement;
  215. const categoryClassList = linkElement.parentElement.classList;
  216. const filterResults = pageName.match( regExp );
  217. if ( filterResults && filterResults.length > 0 ) {
  218. // Accentuate matching characters
  219. for ( let i = 0; i < filterResults.length; i ++ ) {
  220. const result = filterResults[ i ];
  221. if ( result !== '' ) {
  222. pageName = pageName.replace( result, '<b>' + result + '</b>' );
  223. }
  224. }
  225. categoryClassList.remove( 'hidden' );
  226. linkElement.innerHTML = pageName;
  227. } else {
  228. // Hide all non-matching page names
  229. categoryClassList.add( 'hidden' );
  230. }
  231. }
  232. displayFilteredPanel();
  233. }
  234. function displayFilteredPanel() {
  235. // Show/hide categories depending on their content
  236. // First check if at least one page in this category is not hidden
  237. categoryElements.forEach( function ( category ) {
  238. const pages = category.children;
  239. const pagesLength = pages.length;
  240. const sectionClassList = category.parentElement.classList;
  241. let hideCategory = true;
  242. for ( let i = 0; i < pagesLength; i ++ ) {
  243. const pageClassList = pages[ i ].classList;
  244. if ( ! pageClassList.contains( 'hidden' ) ) {
  245. hideCategory = false;
  246. }
  247. }
  248. // If and only if all page names are hidden, hide the whole category
  249. if ( hideCategory ) {
  250. sectionClassList.add( 'hidden' );
  251. } else {
  252. sectionClassList.remove( 'hidden' );
  253. }
  254. } );
  255. }
  256. // Routing
  257. function setUrlFragment( pageName ) { // eslint-disable-line no-undef
  258. // Handle navigation from the subpages (iframes):
  259. // First separate the memeber (if existing) from the page name,
  260. // then identify the subpage's URL and set it as URL fragment (re-adding the member)
  261. const splitPageName = decomposePageName( pageName, '.', '.' );
  262. const currentProperties = pageProperties[ splitPageName[ 0 ] ];
  263. if ( currentProperties ) {
  264. window.location.hash = currentProperties.pageURL + splitPageName[ 1 ];
  265. createNewIframe();
  266. }
  267. }
  268. function createNewIframe() {
  269. // Change the content displayed in the iframe
  270. // First separate the member part of the fragment (if existing)
  271. const hash = window.location.hash.substring( 1 );
  272. const splitHash = decomposePageName( hash, '.', '#' );
  273. // Creating a new Iframe instead of assigning a new src is
  274. // a cross-browser solution to allow normal browser navigation;
  275. // - only assigning a new src would result in two history states each time.
  276. // Note: iframe.contentWindow.location.replace(hash) should work, too,
  277. // but it doesn't work in Edge with links from the subpages!
  278. let subtitle;
  279. const oldIframe = iframe;
  280. iframe = oldIframe.cloneNode();
  281. if ( hash ) {
  282. iframe.src = splitHash[ 0 ] + '.html' + splitHash[ 1 ];
  283. subtitle = titles[ splitHash[ 0 ] ] + splitHash[ 1 ] + ' – ';
  284. } else {
  285. iframe.src = '';
  286. subtitle = '';
  287. }
  288. document.body.replaceChild( iframe, oldIframe );
  289. document.title = subtitle + 'three.js docs';
  290. }
  291. function decomposePageName( pageName, oldDelimiter, newDelimiter ) {
  292. // Helper function for separating the member (if existing) from the pageName
  293. // For example: 'Geometry.morphTarget' can be converted to
  294. // ['Geometry', '.morphTarget'] or ['Geometry', '#morphTarget']
  295. // Note: According RFC 3986 no '#' allowed inside of an URL fragment!
  296. let parts = [];
  297. const dotIndex = pageName.indexOf( oldDelimiter );
  298. if ( dotIndex !== - 1 ) {
  299. parts = pageName.split( oldDelimiter );
  300. parts[ 1 ] = newDelimiter + parts[ 1 ];
  301. } else {
  302. parts[ 0 ] = pageName;
  303. parts[ 1 ] = '';
  304. }
  305. return parts;
  306. }
  307. //
  308. console.log( [
  309. ' __ __',
  310. ' __/ __\\ / __\\__ ____ _____ _____',
  311. '/ __/ /\\/ / /___\\/ ____\\/ _____\\/ _____\\',
  312. '\\/_ __/ / _ / / __/ / __ / / __ /_ __ _____',
  313. '/ / / / / / / / / / / / ___/ / ___/\\ _\\/ __\\/ _____\\',
  314. '\\/__/ \\/__/\\/__/\\/__/ \\/_____/\\/_____/\\/__/ / / / ___/',
  315. ' / __/ / \\__ \\',
  316. ' \\/____/\\/_____/'
  317. ].join( '\n' ) );
  318. </script>
  319. </body>
  320. </html>