index.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>three.js examples</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. <style>
  10. #panel #content .link {
  11. display: block;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <div id="panel">
  17. <div id="header">
  18. <h1><a href="https://threejs.org">three.js</a></h1>
  19. <div id="sections">
  20. <a href="../docs/index.html#manual/introduction/Creating-a-scene">docs</a>
  21. <span class="selected">examples</span>
  22. </div>
  23. <div id="expandButton"></div>
  24. </div>
  25. <div id="panelScrim"></div>
  26. <div id="contentWrapper">
  27. <div id="inputWrapper">
  28. <input placeholder="" type="text" id="filter" autocorrect="off" autocapitalize="off" spellcheck="false" />
  29. <div id="exitSearchButton"></div>
  30. </div>
  31. <div id="content"></div>
  32. </div>
  33. </div>
  34. <iframe id="viewer" name="viewer" allowfullscreen allowvr onmousewheel=""></iframe>
  35. <a id="button" target="_blank"><img src="../files/ic_code_black_24dp.svg"></a>
  36. <script src="files.js"></script>
  37. <script>
  38. function extractQuery() {
  39. var p = window.location.search.indexOf( '?q=' );
  40. if ( p !== - 1 ) {
  41. return window.location.search.substr( 3 );
  42. }
  43. return '';
  44. }
  45. var panel = document.getElementById( 'panel' );
  46. var content = document.getElementById( 'content' );
  47. var viewer = document.getElementById( 'viewer' );
  48. var filterInput = document.getElementById( 'filter' );
  49. var exitSearchButton = document.getElementById( 'exitSearchButton' );
  50. var expandButton = document.getElementById( 'expandButton' );
  51. expandButton.addEventListener( 'click', function ( event ) {
  52. event.preventDefault();
  53. panel.classList.toggle( 'open' );
  54. } );
  55. var panelScrim = document.getElementById( 'panelScrim' );
  56. panelScrim.onclick = function ( event ) {
  57. event.preventDefault();
  58. panel.classList.toggle( 'open' );
  59. };
  60. // iOS iframe auto-resize workaround
  61. if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {
  62. viewer.style.width = getComputedStyle( viewer ).width;
  63. viewer.style.height = getComputedStyle( viewer ).height;
  64. viewer.setAttribute( 'scrolling', 'no' );
  65. }
  66. var container = document.createElement( 'div' );
  67. content.appendChild( container );
  68. var viewSrcButton = document.getElementById( 'button' );
  69. viewSrcButton.style.display = 'none';
  70. var links = {};
  71. var selected = null;
  72. function createLink( file ) {
  73. var link = document.createElement( 'a' );
  74. link.className = 'link';
  75. link.href = file + '.html';
  76. link.textContent = getName( file );
  77. link.setAttribute( 'target', 'viewer' );
  78. link.addEventListener( 'click', function ( event ) {
  79. if ( event.button !== 0 || event.ctrlKey || event.altKey || event.metaKey ) return;
  80. selectFile( file );
  81. } );
  82. return link;
  83. }
  84. for ( var key in files ) {
  85. var section = files[ key ];
  86. var header = document.createElement( 'h2' );
  87. header.textContent = key;
  88. header.setAttribute( 'data-category', key );
  89. container.appendChild( header );
  90. for ( var i = 0; i < section.length; i ++ ) {
  91. var file = section[ i ];
  92. var link = createLink( file );
  93. container.appendChild( link );
  94. links[ file ] = link;
  95. }
  96. }
  97. function loadFile( file ) {
  98. selectFile( file );
  99. viewer.src = file + '.html';
  100. }
  101. function selectFile( file ) {
  102. if ( selected !== null ) links[ selected ].classList.remove( 'selected' );
  103. links[ file ].classList.add( 'selected' );
  104. window.location.hash = file;
  105. viewer.focus();
  106. panel.classList.remove( 'open' );
  107. selected = file;
  108. // Reveal "View source" button and set attributes to this example
  109. viewSrcButton.style.display = '';
  110. viewSrcButton.href = 'https://github.com/mrdoob/three.js/blob/master/examples/' + selected + '.html';
  111. viewSrcButton.title = 'View source code for ' + getName( selected ) + ' on GitHub';
  112. }
  113. if ( window.location.hash !== '' && links[ window.location.hash.substring( 1 ) ] ) {
  114. loadFile( window.location.hash.substring( 1 ) );
  115. }
  116. // filter
  117. filterInput.onfocus = function ( event ) {
  118. panel.classList.add( 'searchFocused' );
  119. };
  120. filterInput.onblur = function ( event ) {
  121. if ( filterInput.value === '' ) {
  122. panel.classList.remove( 'searchFocused' );
  123. }
  124. };
  125. exitSearchButton.onclick = function ( event ) {
  126. filterInput.value = '';
  127. updateFilter();
  128. panel.classList.remove( 'searchFocused' );
  129. };
  130. filterInput.addEventListener( 'input', function () {
  131. updateFilter();
  132. } );
  133. function updateFilter() {
  134. var v = filterInput.value;
  135. if ( v !== '' ) {
  136. window.history.replaceState( {}, '', '?q=' + v + window.location.hash );
  137. } else {
  138. window.history.replaceState( {}, '', window.location.pathname + window.location.hash );
  139. }
  140. var exp = new RegExp( v, 'gi' );
  141. for ( var key in files ) {
  142. var section = files[ key ];
  143. for ( var i = 0; i < section.length; i ++ ) {
  144. filterExample( section[ i ], exp );
  145. }
  146. }
  147. layoutList();
  148. }
  149. function filterExample( file, exp ) {
  150. var link = links[ file ];
  151. var name = getName( file );
  152. var res = file.match( exp );
  153. var text;
  154. if ( res && res.length > 0 ) {
  155. link.classList.remove( 'hidden' );
  156. for ( var i = 0; i < res.length; i ++ ) {
  157. text = name.replace( res[ i ], '<b>' + res[ i ] + '</b>' );
  158. }
  159. link.innerHTML = text;
  160. } else {
  161. link.classList.add( 'hidden' );
  162. link.innerHTML = name;
  163. }
  164. }
  165. function getName( file ) {
  166. var name = file.split( '_' );
  167. name.shift();
  168. return name.join( ' / ' );
  169. }
  170. function layoutList() {
  171. for ( var key in files ) {
  172. var collapsed = true;
  173. var section = files[ key ];
  174. for ( var i = 0; i < section.length; i ++ ) {
  175. var file = section[ i ];
  176. if ( links[ file ].classList.contains( 'hidden' ) === false ) {
  177. collapsed = false;
  178. break;
  179. }
  180. }
  181. var element = document.querySelector( 'h2[data-category="' + key + '"]' );
  182. if ( collapsed ) {
  183. element.classList.add( 'hidden' );
  184. } else {
  185. element.classList.remove( 'hidden' );
  186. }
  187. }
  188. }
  189. filterInput.value = extractQuery();
  190. if ( filterInput.value !== '' ) {
  191. panel.classList.add( 'searchFocused' );
  192. }
  193. updateFilter();
  194. </script>
  195. </body>
  196. </html>