index.html 12 KB

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