index.html 7.7 KB

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