index.html 10 KB

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