index.html 9.0 KB

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