index.html 7.3 KB

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