index.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>three.js docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <link rel="shortcut icon" href="../files/favicon.ico" />
  8. <link rel="stylesheet" type="text/css" href="../files/main.css">
  9. <!-- console sandbox -->
  10. <script src="../build/three.min.js" async defer></script>
  11. </head>
  12. <body>
  13. <div id="panel" class="">
  14. <div id="header">
  15. <h1><a href="http://threejs.org">three.js</a></h1>
  16. <div id="sections">
  17. <span class="selected">docs</span>
  18. <a href="../examples/#webgl_animation_cloth">examples</a>
  19. </div>
  20. <div id="expandButton"></div>
  21. </div>
  22. <div id="panelScrim"></div>
  23. <div id="contentWrapper">
  24. <div id="inputWrapper">
  25. <input placeholder="" type="text" id="filter" autocorrect="off" autocapitalize="off" spellcheck="false" />
  26. <div id="exitSearchButton"></div>
  27. <select id="language">
  28. <option value="en">en</option>
  29. <option value="zh">zh</option>
  30. </select>
  31. </div>
  32. <div id="content"></div>
  33. </div>
  34. </div>
  35. <iframe name="viewer"></iframe>
  36. <script src="list.js"></script>
  37. <script>
  38. var hash = window.location.hash.substring( 1 );
  39. // Localisation
  40. var language = 'en';
  41. if ( /^(api|manual|examples)/.test( hash ) ) {
  42. var hashLanguage = /^(api|manual|examples)\/(en|zh)\//.exec( hash );
  43. if ( hashLanguage === null ) {
  44. // Route old non-localised api links
  45. window.location.hash = hash.replace( /^(api|manual|examples)/, '$1/en' );
  46. } else {
  47. language = hashLanguage[ 2 ];
  48. }
  49. }
  50. //
  51. var languageSelect = document.getElementById( 'language' );
  52. languageSelect.value = language;
  53. languageSelect.addEventListener( 'change', function ( event ) {
  54. setLanguage( this.value );
  55. } );
  56. function setLanguage( value ) {
  57. language = value;
  58. createNavigation();
  59. updateFilter();
  60. autoChangeUrlLanguage( language );
  61. }
  62. var panel = document.getElementById( 'panel' );
  63. var content = document.getElementById( 'content' );
  64. var expandButton = document.getElementById( 'expandButton' );
  65. var exitSearchButton = document.getElementById( 'exitSearchButton' );
  66. var panelScrim = document.getElementById( 'panelScrim' );
  67. var filterInput = document.getElementById( 'filter' );
  68. var iframe = document.querySelector( 'iframe' );
  69. var pageProperties = {};
  70. var titles = {};
  71. var categoryElements = [];
  72. var navigation;
  73. // Functionality for hamburger button (on small devices)
  74. expandButton.onclick = function ( event ) {
  75. event.preventDefault();
  76. panel.classList.toggle( 'open' );
  77. };
  78. panelScrim.onclick = function ( event ) {
  79. event.preventDefault();
  80. panel.classList.toggle( 'open' );
  81. };
  82. // Functionality for search/filter input field
  83. filterInput.onfocus = function ( event ) {
  84. panel.classList.add('searchFocused');
  85. }
  86. filterInput.onblur = function ( event ) {
  87. if(filterInput.value === '') {
  88. panel.classList.remove('searchFocused');
  89. }
  90. }
  91. exitSearchButton.onclick = function( event ) {
  92. filterInput.value = '';
  93. updateFilter();
  94. panel.classList.remove('searchFocused');
  95. }
  96. filterInput.oninput = function ( event ) {
  97. updateFilter();
  98. };
  99. // Activate content and title change on browser navigation
  100. window.onpopstate = createNewIframe;
  101. // Create the navigation panel and configure the iframe
  102. createNavigation();
  103. createNewIframe();
  104. // Navigation Panel
  105. function createLink( pageName, pageURL ) {
  106. var link = document.createElement( 'a' );
  107. link.href = pageURL + '.html';
  108. link.textContent = pageName;
  109. link.setAttribute( 'target', 'viewer' );
  110. link.addEventListener( 'click', function ( event ) {
  111. if ( event.button !== 0 || event.ctrlKey || event.altKey || event.metaKey ) return;
  112. window.location.hash = pageURL;
  113. panel.classList.remove( 'open' );
  114. content.querySelectorAll( 'a' ).forEach( function ( item ) {
  115. item.classList.remove( 'selected' );
  116. } );
  117. link.classList.add('selected');
  118. } );
  119. return link;
  120. }
  121. function createNavigation() {
  122. if ( navigation !== undefined ) {
  123. content.removeChild( navigation );
  124. }
  125. // Create the navigation panel using data from list.js
  126. navigation = document.createElement( 'div' );
  127. content.appendChild( navigation );
  128. var localList = list[ language ];
  129. for ( var section in localList ) {
  130. // Create sections
  131. var categories = localList[ section ];
  132. var sectionHead = document.createElement( 'h2' );
  133. sectionHead.textContent = section;
  134. navigation.appendChild( sectionHead );
  135. for ( var category in categories ) {
  136. // Create categories
  137. var pages = categories[ category ];
  138. var categoryContainer = document.createElement( 'div' );
  139. navigation.appendChild( categoryContainer );
  140. var categoryHead = document.createElement( 'h3' );
  141. categoryHead.textContent = category;
  142. categoryContainer.appendChild( categoryHead );
  143. var categoryContent = document.createElement( 'ul' );
  144. categoryContainer.appendChild( categoryContent );
  145. for ( var pageName in pages ) {
  146. // Create page links
  147. var pageURL = pages[ pageName ];
  148. // Localisation
  149. var listElement = document.createElement( 'li' );
  150. categoryContent.appendChild( listElement );
  151. var linkElement = createLink( pageName, pageURL )
  152. listElement.appendChild( linkElement );
  153. // Gather the main properties for the current subpage
  154. pageProperties[ pageName ] = {
  155. section: section,
  156. category: category,
  157. pageURL: pageURL,
  158. linkElement: linkElement
  159. };
  160. // Gather the document titles (used for easy access on browser navigation)
  161. titles[ pageURL ] = pageName;
  162. }
  163. // Gather the category elements for easy access on filtering
  164. categoryElements.push( categoryContent );
  165. }
  166. }
  167. }
  168. // Auto change language url. If a reader open a document in English, when he click "zh", the document he read will auto change into Chinese version
  169. function autoChangeUrlLanguage( language ) {
  170. var hash = location.hash;
  171. if ( hash === '' ) return;
  172. var docType = hash.substr( 0, hash.indexOf( '/' ) + 1 );
  173. var docLink = hash.substr( hash.indexOf( '/' ) + 1 );
  174. docLink = docLink.substr( docLink.indexOf( '/' ) );
  175. location.href = docType + language + docLink;
  176. }
  177. // Filtering
  178. function updateFilter() {
  179. // (uncomment the following line and the "Query strings" section, if you want query strings):
  180. // updateQueryString();
  181. var regExp = new RegExp( filterInput.value, 'gi' );
  182. for ( var pageName in pageProperties ) {
  183. var linkElement = pageProperties[ pageName ].linkElement;
  184. var categoryClassList = linkElement.parentElement.classList;
  185. var filterResults = pageName.match( regExp );
  186. if ( filterResults && filterResults.length > 0 ) {
  187. // Accentuate matching characters
  188. for ( var i = 0; i < filterResults.length; i++ ) {
  189. var result = filterResults[ i ];
  190. if ( result !== '' ) {
  191. pageName = pageName.replace( result, '<b>' + result + '</b>' );
  192. }
  193. }
  194. categoryClassList.remove( 'hidden' );
  195. linkElement.innerHTML = pageName;
  196. } else {
  197. // Hide all non-matching page names
  198. categoryClassList.add( 'hidden' );
  199. }
  200. }
  201. displayFilteredPanel();
  202. }
  203. function displayFilteredPanel() {
  204. // Show/hide categories depending on their content
  205. // First check if at least one page in this category is not hidden
  206. categoryElements.forEach( function ( category ) {
  207. var pages = category.children;
  208. var pagesLength = pages.length;
  209. var sectionClassList = category.parentElement.classList;
  210. var hideCategory = true;
  211. for ( var i = 0; i < pagesLength; i ++ ) {
  212. var pageClassList = pages[ i ].classList;
  213. if ( ! pageClassList.contains( 'hidden' ) ) {
  214. hideCategory = false;
  215. }
  216. }
  217. // If and only if all page names are hidden, hide the whole category
  218. if ( hideCategory ) {
  219. sectionClassList.add( 'hidden' );
  220. } else {
  221. sectionClassList.remove( 'hidden' );
  222. }
  223. } );
  224. }
  225. // Routing
  226. function setUrlFragment( pageName ) {
  227. // Handle navigation from the subpages (iframes):
  228. // First separate the memeber (if existing) from the page name,
  229. // then identify the subpage's URL and set it as URL fragment (re-adding the member)
  230. var splitPageName = decomposePageName( pageName, '.', '.' );
  231. var currentProperties = pageProperties[ splitPageName[ 0 ] ];
  232. if ( currentProperties ) {
  233. window.location.hash = currentProperties.pageURL + splitPageName[ 1 ];
  234. createNewIframe();
  235. }
  236. }
  237. function createNewIframe() {
  238. // Change the content displayed in the iframe
  239. // First separate the member part of the fragment (if existing)
  240. var hash = window.location.hash.substring( 1 );
  241. var splitHash = decomposePageName( hash, '.', '#' );
  242. // Creating a new Iframe instead of assigning a new src is
  243. // a cross-browser solution to allow normal browser navigation;
  244. // - only assigning a new src would result in two history states each time.
  245. // Note: iframe.contentWindow.location.replace(hash) should work, too,
  246. // but it doesn't work in Edge with links from the subpages!
  247. var oldIframe;
  248. var subtitle;
  249. oldIframe = iframe;
  250. iframe = oldIframe.cloneNode();
  251. if(hash) {
  252. iframe.src = splitHash[ 0 ] + '.html' + splitHash[ 1 ];
  253. subtitle = titles[ splitHash[ 0 ] ] + splitHash[ 1 ] + ' – ';
  254. } else {
  255. iframe.src = '';
  256. subtitle = '';
  257. }
  258. document.body.replaceChild( iframe, oldIframe );
  259. document.title = subtitle + 'three.js docs';
  260. }
  261. function decomposePageName( pageName, oldDelimiter, newDelimiter ) {
  262. // Helper function for separating the member (if existing) from the pageName
  263. // For example: 'Geometry.morphTarget' can be converted to
  264. // ['Geometry', '.morphTarget'] or ['Geometry', '#morphTarget']
  265. // Note: According RFC 3986 no '#' allowed inside of an URL fragment!
  266. var parts = [];
  267. var dotIndex = pageName.indexOf( oldDelimiter );
  268. if ( dotIndex !== -1 ) {
  269. parts = pageName.split( oldDelimiter );
  270. parts[ 1 ] = newDelimiter + parts[ 1 ];
  271. } else {
  272. parts[ 0 ] = pageName;
  273. parts[ 1 ] = '';
  274. }
  275. return parts;
  276. }
  277. //
  278. console.log([
  279. ' __ __',
  280. ' __/ __\\ / __\\__ ____ _____ _____',
  281. '/ __/ /\\/ / /___\\/ ____\\/ _____\\/ _____\\',
  282. '\\/_ __/ / _ / / __/ / __ / / __ /_ __ _____',
  283. '/ / / / / / / / / / / / ___/ / ___/\\ _\\/ __\\/ _____\\',
  284. '\\/__/ \\/__/\\/__/\\/__/ \\/_____/\\/_____/\\/__/ / / / ___/',
  285. ' / __/ / \\__ \\',
  286. ' \\/____/\\/_____/'
  287. ].join('\n'));
  288. </script>
  289. </body>
  290. </html>