index.html 12 KB

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