2
0

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