index.html 13 KB

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