2
0

index.html 8.5 KB

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