index.html 8.5 KB

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