index.html 12 KB

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