index.html 9.9 KB

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