index.html 10 KB

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