index.html 11 KB

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