index.html 9.5 KB

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