index.html 12 KB

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