index.html 10 KB

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