index.html 8.7 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 235 236 237
			<div class="filterBlock" >
				<input type="text" id="filterInput" placeholder="Type to filter"/>
				<a href="#" id="clearFilterButton" >x</a>
			</div>
M
Mr.doob 已提交
238
			<div id="content"></div>
M
Mr.doob 已提交
239
		</div>
J
Jaume Sanchez 已提交
240
		<iframe id="viewer" name="viewer" allowfullscreen onmousewheel=""></iframe>
M
Mr.doob 已提交
241

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

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

246 247 248 249 250 251 252 253
		function extractQuery() {
			var p = window.location.search.indexOf( '?q=' )
			if( p !== -1 ) {
				return window.location.search.substr( 3 );
			} 
			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 267 268
		var expandButton = document.getElementById( 'expandButton' );
		expandButton.addEventListener( 'click', function ( event ) {
			panel.classList.toggle( 'collapsed' );
			event.preventDefault();
		} );

		// iOS8 workaround

269 270 271 272 273 274 275 276 277 278 279
		if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {

			viewer.addEventListener( 'load', function ( event ) {

				viewer.contentWindow.innerWidth -= 10;
				viewer.contentWindow.innerHeight -= 2;

			} );

		}

M
Mr.doob 已提交
280
		var container = document.createElement( 'div' );
M
Mr.doob 已提交
281
		content.appendChild( container );
M
Mr.doob 已提交
282

283 284
		var button = document.createElement( 'div' );
		button.id = 'button';
M
Mr.doob 已提交
285
		button.textContent = 'View source';
286
		button.addEventListener( 'click', function ( event ) {
V
verteAzur 已提交
287 288 289 290 291 292 293 294
			try{
				var array = location.href.split('/');
				array.pop();
				window.open( 'view-source:'+ array.join('/')+ '/' + selected + '.html' );
			}catch(err){
				window.open( 'https://github.com/mrdoob/three.js/blob/master/examples/' + selected + '.html' );
				console.log(err);
			}
295 296
		}, false );
		button.style.display = 'none';
297
		document.body.appendChild( button );
298

299
		var links = {};
300
		var selected = null;
M
Mr.doob 已提交
301

M
Mr.doob 已提交
302
		for ( var key in files ) {
M
Mr.doob 已提交
303

M
Mr.doob 已提交
304
			var section = files[ key ];
M
Mr.doob 已提交
305

M
Mugen87 已提交
306 307 308 309
			var header = document.createElement( 'h2' );
			header.textContent = key;
			header.setAttribute( 'data-category', key );
			container.appendChild( header );
M
Mr.doob 已提交
310

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

M
Mr.doob 已提交
313
				( function ( file ) {
M
Mr.doob 已提交
314

M
Mugen87 已提交
315
					var name = getName( file );
M
Mr.doob 已提交
316

317 318 319
					var link = document.createElement( 'a' );
					link.className = 'link';
					link.textContent = name;
320
					link.href = file + '.html';
J
Jaume Sanchez 已提交
321
					link.setAttribute( 'target', 'viewer' );
M
Mr.doob 已提交
322
					link.addEventListener( 'click', function ( event ) {
323

M
Mr.doob 已提交
324
						if ( event.button === 0 ) {
325

326
							selectFile( file );
M
Mr.doob 已提交
327

328
						}
M
Mr.doob 已提交
329 330

					} );
331
					container.appendChild( link );
M
Mr.doob 已提交
332

333
					links[ file ] = link;
M
Mr.doob 已提交
334 335 336 337

				} )( section[ i ] );

			}
M
Mr.doob 已提交
338 339 340

		}

M
Mr.doob 已提交
341
		function loadFile( file ) {
M
Mr.doob 已提交
342

343 344 345
			selectFile( file );
			viewer.src = file + '.html';

M
Mr.doob 已提交
346
		}
347

M
Mr.doob 已提交
348
		function selectFile( file ) {
349

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

352
			links[ file ].classList.add( 'selected' );
M
Mr.doob 已提交
353 354

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

357
			button.style.display = '';
358
			panel.classList.toggle( 'collapsed' );
M
Mr.doob 已提交
359

M
Mr.doob 已提交
360 361
			selected = file;

362
		}
M
Mr.doob 已提交
363

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

M
Mr.doob 已提交
366
			loadFile( window.location.hash.substring( 1 ) );
M
Mr.doob 已提交
367 368 369

		}

M
Mugen87 已提交
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
		// filter

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

			updateFilter();

		} );

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

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

		} );

		function updateFilter() {

388 389 390 391 392 393 394 395 396
			var v = filterInput.value;
			if( v !== '' ) {
				window.history.replaceState( {} , '', '?q=' + v );
			} else {
				window.history.replaceState( {} , '', window.location.pathname );
			}
			if( selected ) window.location.hash = selected

			var exp = new RegExp( v, 'gi' );
M
Mugen87 已提交
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 479 480 481 482 483

			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' );

				}

			}

		}

484 485 486
		filterInput.value = extractQuery()
		updateFilter( )

M
Mr.doob 已提交
487 488 489
		</script>

	</body>
490
</html>