2
0

index.html 11 KB

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