index.html 8.7 KB

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