index.html 9.4 KB

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