index.html 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js / examples</title>
  5. <meta charset="utf-8">
  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="../favicon.ico" />
  8. <style>
  9. @font-face {
  10. font-family: 'inconsolata';
  11. src: url('files/inconsolata.woff') format('woff');
  12. font-weight: normal;
  13. font-style: normal;
  14. }
  15. * {
  16. box-sizing: border-box;
  17. }
  18. html {
  19. height: 100%;
  20. }
  21. body {
  22. background-color: #ffffff;
  23. margin: 0px;
  24. height: 100%;
  25. color: #555;
  26. font-family: 'inconsolata';
  27. font-size: 15px;
  28. line-height: 18px;
  29. overflow: hidden;
  30. }
  31. h1 {
  32. margin-top: 30px;
  33. margin-bottom: 40px;
  34. margin-left: 20px;
  35. font-size: 25px;
  36. font-weight: normal;
  37. }
  38. h2 {
  39. font-size: 20px;
  40. font-weight: normal;
  41. }
  42. a {
  43. color: #2194CE;
  44. text-decoration: none;
  45. }
  46. #panel {
  47. position: fixed;
  48. left: 0px;
  49. width: 310px;
  50. height: 100%;
  51. overflow: auto;
  52. background: #fafafa;
  53. }
  54. #panel #content {
  55. padding: 0px 20px 20px 20px;
  56. }
  57. #panel #content .link {
  58. color: #2194CE;
  59. text-decoration: none;
  60. cursor: pointer;
  61. display: block;
  62. }
  63. #panel #content .selected {
  64. color: #ff0000;
  65. }
  66. #panel #content .link:hover {
  67. text-decoration: underline;
  68. }
  69. #viewer {
  70. position: absolute;
  71. border: 0px;
  72. left: 310px;
  73. width: calc(100% - 310px);
  74. height: 100%;
  75. overflow: auto;
  76. }
  77. #viewSrcButton {
  78. position: fixed;
  79. bottom: 20px;
  80. right: 20px;
  81. padding: 8px;
  82. color: #fff;
  83. background-color: #555;
  84. opacity: 0.7;
  85. }
  86. #viewSrcButton:hover {
  87. cursor: pointer;
  88. opacity: 1;
  89. }
  90. .filterBlock{
  91. margin: 20px;
  92. position: relative;
  93. }
  94. .filterBlock p {
  95. margin: 0;
  96. }
  97. #filterInput {
  98. width: 100%;
  99. padding: 5px;
  100. font-family: inherit;
  101. font-size: 15px;
  102. outline: none;
  103. border: 1px solid #dedede;
  104. }
  105. #filterInput:focus{
  106. border: 1px solid #2194CE;
  107. }
  108. #clearFilterButton {
  109. position: absolute;
  110. right: 6px;
  111. top: 50%;
  112. margin-top: -8px;
  113. width: 16px;
  114. height: 16px;
  115. font-size: 14px;
  116. color: grey;
  117. text-align: center;
  118. line-height: 0;
  119. padding-top: 7px;
  120. opacity: .5;
  121. }
  122. #clearFilterButton:hover {
  123. opacity: 1;
  124. }
  125. .filtered {
  126. display: none !important;
  127. }
  128. #panel li b {
  129. font-weight: bold;
  130. }
  131. /* mobile */
  132. #expandButton {
  133. display: none;
  134. position: absolute;
  135. right: 20px;
  136. top: 12px;
  137. width: 32px;
  138. height: 32px;
  139. }
  140. #expandButton span {
  141. height: 2px;
  142. background-color: #2194CE;
  143. width: 16px;
  144. position: absolute;
  145. left: 8px;
  146. top: 10px;
  147. }
  148. #expandButton span:nth-child(1) {
  149. top: 16px;
  150. }
  151. #expandButton span:nth-child(2) {
  152. top: 22px;
  153. }
  154. @media all and ( max-width: 640px ) {
  155. h1{
  156. margin-top: 20px;
  157. margin-bottom: 20px;
  158. }
  159. #panel{
  160. position: absolute;
  161. left: 0;
  162. top: 0;
  163. height: 480px;
  164. width: 100%;
  165. right: 0;
  166. z-index: 100;
  167. overflow: hidden;
  168. border-bottom: 1px solid #dedede;
  169. }
  170. #content{
  171. position: absolute;
  172. left: 0;
  173. top: 90px;
  174. right: 0;
  175. bottom: 0;
  176. font-size: 17px;
  177. line-height: 22px;
  178. overflow: auto;
  179. }
  180. #viewer{
  181. position: absolute;
  182. left: 0;
  183. top: 56px;
  184. width: 100%;
  185. height: calc(100% - 56px);
  186. }
  187. #expandButton{
  188. display: block;
  189. }
  190. #panel.collapsed{
  191. height: 56px;
  192. }
  193. }
  194. </style>
  195. </head>
  196. <body>
  197. <div id="panel">
  198. <h1><a href="http://threejs.org">three.js</a> / examples</h1>
  199. <a id="expandButton" href="#">
  200. <span></span>
  201. <span></span>
  202. <span></span>
  203. </a>
  204. <div class="filterBlock" >
  205. <input type="text" id="filterInput" placeholder="Type to filter" autocorrect="off" autocapitalize="off" spellcheck="false"/>
  206. <a href="#" id="clearFilterButton" >x</a>
  207. </div>
  208. <div id="content"></div>
  209. </div>
  210. <iframe id="viewer" name="viewer" allowfullscreen allowvr onmousewheel=""></iframe>
  211. <script src="files.js"></script>
  212. <script>
  213. function extractQuery() {
  214. var p = window.location.search.indexOf( '?q=' );
  215. if( p !== -1 ) {
  216. return window.location.search.substr( 3 );
  217. }
  218. return ''
  219. }
  220. var panel = document.getElementById( 'panel' );
  221. var content = document.getElementById( 'content' );
  222. var viewer = document.getElementById( 'viewer' );
  223. var filterInput = document.getElementById( 'filterInput' );
  224. var clearFilterButton = document.getElementById( 'clearFilterButton' );
  225. var expandButton = document.getElementById( 'expandButton' );
  226. expandButton.addEventListener( 'click', function ( event ) {
  227. event.preventDefault();
  228. panel.classList.toggle( 'collapsed' );
  229. } );
  230. // iOS iframe auto-resize workaround
  231. if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {
  232. viewer.style.width = getComputedStyle( viewer ).width;
  233. viewer.style.height = getComputedStyle( viewer ).height;
  234. viewer.setAttribute( 'scrolling', 'no' );
  235. }
  236. var container = document.createElement( 'div' );
  237. content.appendChild( container );
  238. var viewSrcButton = document.createElement( 'a' );
  239. viewSrcButton.id = 'viewSrcButton';
  240. viewSrcButton.target = '_blank';
  241. viewSrcButton.textContent = 'View source';
  242. viewSrcButton.style.display = 'none';
  243. document.body.appendChild( viewSrcButton );
  244. var links = {};
  245. var selected = null;
  246. function createLink( file ) {
  247. var link = document.createElement( 'a' );
  248. link.className = 'link';
  249. link.href = file + '.html';
  250. link.textContent = getName( file );
  251. link.setAttribute( 'target', 'viewer' );
  252. link.addEventListener( 'click', function ( event ) {
  253. if ( event.button !== 0 || event.ctrlKey || event.altKey || event.metaKey ) return;
  254. selectFile( file );
  255. } );
  256. return link;
  257. }
  258. for ( var key in files ) {
  259. var section = files[ key ];
  260. var header = document.createElement( 'h2' );
  261. header.textContent = key;
  262. header.setAttribute( 'data-category', key );
  263. container.appendChild( header );
  264. for ( var i = 0; i < section.length; i ++ ) {
  265. var file = section[ i ];
  266. var link = createLink( file );
  267. container.appendChild( link );
  268. links[ file ] = link;
  269. }
  270. }
  271. function loadFile( file ) {
  272. selectFile( file );
  273. viewer.src = file + '.html';
  274. }
  275. function selectFile( file ) {
  276. if ( selected !== null ) links[ selected ].classList.remove( 'selected' );
  277. links[ file ].classList.add( 'selected' );
  278. window.location.hash = file;
  279. viewer.focus();
  280. panel.classList.add( 'collapsed' );
  281. selected = file;
  282. // Reveal "View source" button and set attributes to this example
  283. viewSrcButton.style.display = '';
  284. viewSrcButton.href = 'https://github.com/mrdoob/three.js/blob/master/examples/' + selected + '.html';
  285. viewSrcButton.title = 'View source code for ' + getName(selected) + ' on GitHub';
  286. }
  287. if ( window.location.hash !== '' ) {
  288. loadFile( window.location.hash.substring( 1 ) );
  289. }
  290. // filter
  291. filterInput.addEventListener( 'input', function( e ) {
  292. updateFilter();
  293. } );
  294. clearFilterButton.addEventListener( 'click', function( e ) {
  295. filterInput.value = '';
  296. updateFilter();
  297. e.preventDefault();
  298. } );
  299. function updateFilter() {
  300. var v = filterInput.value;
  301. if( v !== '' ) {
  302. window.history.replaceState( {} , '', '?q=' + v + window.location.hash );
  303. } else {
  304. window.history.replaceState( {} , '', window.location.pathname + window.location.hash );
  305. }
  306. var exp = new RegExp( v, 'gi' );
  307. for ( var key in files ) {
  308. var section = files[ key ];
  309. for ( var i = 0; i < section.length; i ++ ) {
  310. filterExample( section[ i ], exp );
  311. }
  312. }
  313. layoutList();
  314. }
  315. function filterExample( file, exp ){
  316. var link = links[ file ];
  317. var name = getName( file );
  318. var res = file.match( exp );
  319. var text;
  320. if ( res && res.length > 0 ) {
  321. link.classList.remove( 'filtered' );
  322. for( var i = 0; i < res.length; i++ ) {
  323. text = name.replace( res[ i ], '<b>' + res[ i ] + '</b>' );
  324. }
  325. link.innerHTML = text;
  326. } else {
  327. link.classList.add( 'filtered' );
  328. link.innerHTML = name;
  329. }
  330. }
  331. function getName( file ) {
  332. var name = file.split( '_' );
  333. name.shift();
  334. return name.join( ' / ' );
  335. }
  336. function layoutList() {
  337. for ( var key in files ) {
  338. var collapsed = true;
  339. var section = files[ key ];
  340. for ( var i = 0; i < section.length; i ++ ) {
  341. var file = section[ i ];
  342. if( !links[ file ].classList.contains( 'filtered' ) ){
  343. collapsed = false;
  344. break;
  345. }
  346. }
  347. var element = document.querySelector( 'h2[data-category="' + key + '"]' );
  348. if( collapsed ){
  349. element.classList.add( 'filtered' );
  350. } else {
  351. element.classList.remove( 'filtered' );
  352. }
  353. }
  354. }
  355. filterInput.value = extractQuery();
  356. updateFilter();
  357. </script>
  358. </body>
  359. </html>