index.html 8.6 KB
Newer Older
M
Mr.doob 已提交
1 2 3
<!DOCTYPE html>
<html lang="en">
	<head>
M
Mr.doob 已提交
4
		<title>three.js / examples</title>
M
Mr.doob 已提交
5
		<meta charset="utf-8">
M
Mr.doob 已提交
6
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
M
Mr.doob 已提交
7 8 9 10 11 12 13 14 15
		<style>

			@font-face {
				font-family: 'inconsolata';
				src: url('files/inconsolata.woff') format('woff');
				font-weight: normal;
				font-style: normal;
			}

M
Mr.doob 已提交
16
			* {
M
Mr.doob 已提交
17 18 19
				box-sizing: border-box;
			}

M
Mr.doob 已提交
20 21 22 23
			html {
				height: 100%;
			}

M
Mr.doob 已提交
24 25 26
			body {
				background-color: #ffffff;
				margin: 0px;
M
Mr.doob 已提交
27 28
				height: 100%;
				color: #555;
M
Mr.doob 已提交
29 30
				font-family: 'inconsolata';
				font-size: 15px;
M
Mr.doob 已提交
31
				line-height: 18px;
M
Mr.doob 已提交
32
				overflow: hidden;
33
			}
M
Mr.doob 已提交
34

M
Mr.doob 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47
			h1 {
				margin-top: 30px;
				margin-bottom: 40px;
				margin-left: 20px;
				font-size: 25px;
				font-weight: normal;
			}

			h2 {
				font-size: 20px;
				font-weight: normal;
			}

48 49 50
			a {
				color: #2194CE;
				text-decoration: none;
M
Mr.doob 已提交
51 52 53
			}

			#panel {
M
Mr.doob 已提交
54 55
				position: fixed;
				left: 0px;
M
Mr.doob 已提交
56
				width: 310px;
M
Mr.doob 已提交
57
				height: 100%;
M
Mr.doob 已提交
58
				overflow: auto;
M
Mr.doob 已提交
59
				background: #fafafa;
M
Mr.doob 已提交
60 61
			}

M
Mugen87 已提交
62 63 64
			#panel #content {
				padding: 0px 20px 20px 20px;
			}
M
Mr.doob 已提交
65

M
Mugen87 已提交
66 67 68 69 70 71
			#panel #content .link {
				color: #2194CE;
				text-decoration: none;
				cursor: pointer;
				display: block;
			}
M
Mr.doob 已提交
72

M
Mugen87 已提交
73 74 75
			#panel #content .selected {
				color: #ff0000;
			}
M
Mr.doob 已提交
76

M
Mugen87 已提交
77 78 79
			#panel #content .link:hover {
				text-decoration: underline;
			}
M
Mr.doob 已提交
80

M
Mr.doob 已提交
81 82
			#viewer {
				position: absolute;
M
Mr.doob 已提交
83
				border: 0px;
M
Mr.doob 已提交
84 85
				left: 310px;
				width: calc(100% - 310px);
M
Mr.doob 已提交
86
				height: 100%;
M
Mr.doob 已提交
87
				overflow: auto;
M
Mr.doob 已提交
88 89
			}

M
Mr.doob 已提交
90 91 92 93
			#button {
				position: fixed;
				bottom: 20px;
				right: 20px;
94 95 96 97 98
				padding: 8px;
				color: #fff;
				background-color: #555;
				opacity: 0.7;
			}
M
Mr.doob 已提交
99 100

			#button:hover {
M
Mugen87 已提交
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
				cursor: pointer;
				opacity: 1;
			}

			.filterBlock{
				margin: 20px;
				position: relative;
			}

			.filterBlock p {
				margin: 0;
			}

			#filterInput {
				width: 100%;
				padding: 5px;
				font-family: inherit;
				font-size: 15px;
				outline: none;
				border: 1px solid #dedede;
			}

			#filterInput:focus{
				border: 1px solid #2194CE;
			}

			#clearFilterButton {
				position: absolute;
				right: 6px;
				top: 50%;
				margin-top: -8px;
				width: 16px;
				height: 16px;
				font-size: 14px;
				color: grey;
				text-align: center;
				line-height: 0;
				padding-top: 7px;
				opacity: .5;
			}

			#clearFilterButton:hover {
				opacity: 1;
			}

			.filtered {
				display: none !important;
			}

			#panel li b {
				font-weight: bold;
			}
153

M
Mr.doob 已提交
154 155 156 157 158 159 160 161 162 163 164
			/* mobile */

			#expandButton {
				display: none;
				position: absolute;
				right: 20px;
				top: 12px;
				width: 32px;
				height: 32px;
			}

M
Mugen87 已提交
165 166 167 168 169 170 171 172
			#expandButton span {
				height: 2px;
				background-color: #2194CE;
				width: 16px;
				position: absolute;
				left: 8px;
				top: 10px;
			}
M
Mr.doob 已提交
173

M
Mugen87 已提交
174 175 176
			#expandButton span:nth-child(1) {
				top: 16px;
			}
M
Mr.doob 已提交
177

M
Mugen87 已提交
178 179 180
			#expandButton span:nth-child(2) {
				top: 22px;
			}
M
Mr.doob 已提交
181 182

			@media all and ( max-width: 640px ) {
M
Mr.doob 已提交
183 184 185 186
				h1{
					margin-top: 20px;
					margin-bottom: 20px;
				}
M
Mr.doob 已提交
187 188 189 190 191 192 193 194 195 196 197 198 199 200
				#panel{
					position: absolute;
					left: 0;
					top: 0;
					height: 480px;
					width: 100%;
					right: 0;
					z-index: 100;
					overflow: hidden;
					border-bottom: 1px solid #dedede;
				}
				#content{
					position: absolute;
					left: 0;
M
Mugen87 已提交
201
					top: 90px;
M
Mr.doob 已提交
202 203
					right: 0;
					bottom: 0;
M
Mr.doob 已提交
204 205 206
					font-size: 17px;
					line-height: 22px;
					overflow: auto;
M
Mr.doob 已提交
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
				}
				#viewer{
					position: absolute;
					left: 0;
					top: 56px;
					width: 100%;
					height: calc(100% - 56px);
				}
				#expandButton{
					display: block;
				}
				#panel.collapsed{
					height: 56px;
				}
			}

M
Mr.doob 已提交
223 224 225 226
		</style>
	</head>
	<body>

M
Mr.doob 已提交
227 228
		<div id="panel" class="collapsed">
			<h1><a href="http://threejs.org">three.js</a> / examples</h1>
M
Mr.doob 已提交
229
			<a id="expandButton" href="#">
M
Mr.doob 已提交
230 231 232 233
				<span></span>
				<span></span>
				<span></span>
			</a>
M
Mugen87 已提交
234
			<div class="filterBlock" >
235
				<input type="text" id="filterInput" placeholder="Type to filter"/>
M
Mugen87 已提交
236 237
				<a href="#" id="clearFilterButton" >x</a>
			</div>
M
Mr.doob 已提交
238
			<div id="content"></div>
M
Mr.doob 已提交
239
		</div>
240
		<iframe id="viewer" name="viewer" allowfullscreen allowvr onmousewheel=""></iframe>
M
Mr.doob 已提交
241

G
gero3 已提交
242
		<script src="files.js"></script>
243

M
Mr.doob 已提交
244 245
		<script>

246
		function extractQuery() {
247
			var p = window.location.search.indexOf( '?q=' );
248 249
			if( p !== -1 ) {
				return window.location.search.substr( 3 );
M
Mr.doob 已提交
250
			}
251 252 253
			return ''
		}

M
Mr.doob 已提交
254
		var panel = document.getElementById( 'panel' );
M
Mr.doob 已提交
255
		var content = document.getElementById( 'content' );
M
Mr.doob 已提交
256
		var viewer = document.getElementById( 'viewer' );
M
Mr.doob 已提交
257

M
Mugen87 已提交
258 259 260
		var filterInput = document.getElementById( 'filterInput' );
		var clearFilterButton = document.getElementById( 'clearFilterButton' );

M
Mr.doob 已提交
261 262 263 264 265 266
		var expandButton = document.getElementById( 'expandButton' );
		expandButton.addEventListener( 'click', function ( event ) {
			panel.classList.toggle( 'collapsed' );
			event.preventDefault();
		} );

267
		// iOS iframe auto-resize workaround
M
Mr.doob 已提交
268

269 270
		if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {

271 272
			viewer.style.width = getComputedStyle( viewer ).width;
			viewer.style.height = getComputedStyle( viewer ).height;
273
			viewer.setAttribute( 'scrolling', 'no' );
274 275 276

		}

M
Mr.doob 已提交
277
		var container = document.createElement( 'div' );
M
Mr.doob 已提交
278
		content.appendChild( container );
M
Mr.doob 已提交
279

280 281
		var button = document.createElement( 'div' );
		button.id = 'button';
M
Mr.doob 已提交
282
		button.textContent = 'View source';
283
		button.addEventListener( 'click', function ( event ) {
M
Mr.doob 已提交
284

M
Mr.doob 已提交
285
			window.open( 'https://github.com/mrdoob/three.js/blob/master/examples/' + selected + '.html' );
M
Mr.doob 已提交
286

287 288
		}, false );
		button.style.display = 'none';
289
		document.body.appendChild( button );
290

291
		var links = {};
292
		var selected = null;
M
Mr.doob 已提交
293

M
Mr.doob 已提交
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
		function createLink( file ) {

			var link = document.createElement( 'a' );
			link.className = 'link';
			link.href = file + '.html';
			link.textContent = getName( file );
			link.setAttribute( 'target', 'viewer' );
			link.addEventListener( 'click', function ( event ) {

				if ( event.button === 0 ) {

					selectFile( file );

				}

			} );

			return link;

		}

M
Mr.doob 已提交
315
		for ( var key in files ) {
M
Mr.doob 已提交
316

M
Mr.doob 已提交
317
			var section = files[ key ];
M
Mr.doob 已提交
318

M
Mugen87 已提交
319 320 321 322
			var header = document.createElement( 'h2' );
			header.textContent = key;
			header.setAttribute( 'data-category', key );
			container.appendChild( header );
M
Mr.doob 已提交
323

M
Mr.doob 已提交
324
			for ( var i = 0; i < section.length; i ++ ) {
M
Mr.doob 已提交
325

M
Mr.doob 已提交
326
				var file = section[ i ];
M
Mr.doob 已提交
327

M
Mr.doob 已提交
328 329
				var link = createLink( file );
				container.appendChild( link );
M
Mr.doob 已提交
330

M
Mr.doob 已提交
331
				links[ file ] = link;
M
Mr.doob 已提交
332 333

			}
M
Mr.doob 已提交
334 335 336

		}

M
Mr.doob 已提交
337
		function loadFile( file ) {
M
Mr.doob 已提交
338

339 340 341
			selectFile( file );
			viewer.src = file + '.html';

M
Mr.doob 已提交
342
		}
343

M
Mr.doob 已提交
344
		function selectFile( file ) {
345

346
			if ( selected !== null ) links[ selected ].classList.remove( 'selected' );
M
Mr.doob 已提交
347

348
			links[ file ].classList.add( 'selected' );
M
Mr.doob 已提交
349 350

			window.location.hash = file;
J
Jaume Sanchez 已提交
351
			viewer.focus();
M
Mr.doob 已提交
352

353
			button.style.display = '';
354
			panel.classList.toggle( 'collapsed' );
M
Mr.doob 已提交
355

M
Mr.doob 已提交
356 357
			selected = file;

358
		}
M
Mr.doob 已提交
359

M
Mr.doob 已提交
360
		if ( window.location.hash !== '' ) {
M
Mr.doob 已提交
361

M
Mr.doob 已提交
362
			loadFile( window.location.hash.substring( 1 ) );
M
Mr.doob 已提交
363 364 365

		}

M
Mugen87 已提交
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
		// filter

		filterInput.addEventListener( 'input', function( e ) {

			updateFilter();

		} );

		clearFilterButton.addEventListener( 'click', function( e ) {

			filterInput.value = '';
			updateFilter();
			e.preventDefault();

		} );

		function updateFilter() {

384 385
			var v = filterInput.value;
			if( v !== '' ) {
386
				window.history.replaceState( {} , '', '?q=' + v + window.location.hash );
387
			} else {
388
				window.history.replaceState( {} , '', window.location.pathname + window.location.hash );
389 390 391
			}

			var exp = new RegExp( v, 'gi' );
M
Mugen87 已提交
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478

			for ( var key in files ) {

				var section = files[ key ];

				for ( var i = 0; i < section.length; i ++ ) {

					filterExample( section[ i ], exp );

				}

			}

			layoutList();

		}

		function filterExample( file, exp ){

			var link = links[ file ];
			var name = getName( file );
			var res = file.match( exp );
			var text;

			if ( res && res.length > 0 ) {

				link.classList.remove( 'filtered' );

				for( var i = 0; i < res.length; i++ ) {
					text = name.replace( res[ i ], '<b>' + res[ i ] + '</b>' );
				}

				link.innerHTML = text;

			} else {

				link.classList.add( 'filtered' );
				link.innerHTML = name;

			}
		}

		function getName( file ) {

			var name = file.split( '_' );
			name.shift();
			return name.join( ' / ' );

		}

		function layoutList() {

			for ( var key in files ) {

				var collapsed = true;

				var section = files[ key ];

				for ( var i = 0; i < section.length; i ++ ) {

					var file = section[ i ];

					if( !links[ file ].classList.contains( 'filtered' ) ){

						collapsed = false;
						break;

					}

				}

				var element = document.querySelector( 'h2[data-category="' + key + '"]' );

				if( collapsed ){

					element.classList.add( 'filtered' );

				} else {

					element.classList.remove( 'filtered' );

				}

			}

		}

479
		filterInput.value = extractQuery();
M
Mr.doob 已提交
480
		updateFilter();
481

M
Mr.doob 已提交
482 483 484
		</script>

	</body>
485
</html>