index.html 7.5 KB
Newer Older
M
Mr.doob 已提交
1 2 3
<!DOCTYPE html>
<html lang="en">
	<head>
M
Mr.doob 已提交
4
		<meta charset="utf-8">
5
		<title>three.js examples</title>
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
		<link rel="shortcut icon" href="../files/favicon.ico" />
		<link rel="stylesheet" type="text/css" href="../files/main.css">
	</head>
	<body>
M
Mugen87 已提交
11

12
		<div id="panel">
M
Mr.doob 已提交
13

M
Mr.doob 已提交
14
			<div id="header">
M
Mugen87 已提交
15
				<h1><a href="https://threejs.org">three.js</a></h1>
M
Mr.doob 已提交
16

M
Mr.doob 已提交
17
				<div id="sections">
18
					<a href="../docs/index.html#manual/introduction/Creating-a-scene">docs</a>
Y
Yuin Chien 已提交
19
					<span class="selected">examples</span>
M
Mr.doob 已提交
20
				</div>
M
Mr.doob 已提交
21

22
				<div id="expandButton"></div>
M
Mugen87 已提交
23
			</div>
M
Mr.doob 已提交
24

Y
Yuin Chien 已提交
25 26 27
			<div id="panelScrim"></div>

			<div id="contentWrapper">
28 29

				<div id="inputWrapper">
M
munrocket@pm.me 已提交
30
					<input placeholder="" type="text" id="filterInput" autocorrect="off" autocapitalize="off" spellcheck="false" />
31 32
					<div id="exitSearchButton"></div>
				</div>
Y
Yuin Chien 已提交
33

34 35
				<div id="content">
					<img id="previewsToggler" src="./files/thumbnails.svg" width="20" height="20" />
36 37
				</div>
			</div>
M
Mr.doob 已提交
38

M
Mr.doob 已提交
39
		</div>
M
Mr.doob 已提交
40

41
		<iframe id="viewer" name="viewer" allowfullscreen allowvr onmousewheel=""></iframe>
M
Mr.doob 已提交
42

43 44
		<a id="button" target="_blank"><img src="../files/ic_code_black_24dp.svg"></a>

G
gero3 已提交
45
		<script src="files.js"></script>
46

M
Mr.doob 已提交
47 48
		<script>

M
munrocket@pm.me 已提交
49 50 51 52 53 54 55 56
		var panel = document.getElementById( 'panel' );
		var content = document.getElementById( 'content' );
		var viewer = document.getElementById( 'viewer' );
		var filterInput = document.getElementById( 'filterInput' );
		var exitSearchButton = document.getElementById( 'exitSearchButton' );
		var expandButton = document.getElementById( 'expandButton' );
		var viewSrcButton = document.getElementById( 'button' );
		var panelScrim = document.getElementById( 'panelScrim' );
57 58 59

		var previewsToggler = document.getElementById( 'previewsToggler' );
		var previewsVisible = true;
M
Mugen87 已提交
60

M
munrocket@pm.me 已提交
61 62 63
		var links = {};
		var selected = null;
		var container = document.createElement( 'div' );
M
Mugen87 已提交
64

M
munrocket@pm.me 已提交
65
		init();
M
Mugen87 已提交
66

M
munrocket@pm.me 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
		function init() {

			content.appendChild( container );

			viewSrcButton.style.display = 'none';

			for ( var key in files ) {

				var section = files[ key ];

				var header = document.createElement( 'h2' );
				header.textContent = key;
				header.setAttribute( 'data-category', key );
				container.appendChild( header );

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

					var file = section[ i ];

					var link = createLink( file );
					container.appendChild( link );

					links[ file ] = link;

				}
M
Mugen87 已提交
92

M
Mr.doob 已提交
93
			}
M
Mugen87 已提交
94

M
munrocket@pm.me 已提交
95
			if ( window.location.hash !== '' && links[ window.location.hash.substring( 1 ) ] ) {
M
Mugen87 已提交
96

M
munrocket@pm.me 已提交
97
				loadFile( window.location.hash.substring( 1 ) );
98

M
munrocket@pm.me 已提交
99
			}
M
Mr.doob 已提交
100

M
munrocket@pm.me 已提交
101
			filterInput.value = extractQuery();
M
Mugen87 已提交
102

M
munrocket@pm.me 已提交
103
			if ( filterInput.value !== '' ) {
M
Mugen87 已提交
104

M
munrocket@pm.me 已提交
105
				panel.classList.add( 'searchFocused' );
M
Mugen87 已提交
106

M
munrocket@pm.me 已提交
107
			}
M
Mr.doob 已提交
108

M
munrocket@pm.me 已提交
109
			updateFilter();
Y
Yuin Chien 已提交
110

M
munrocket@pm.me 已提交
111
			// Events
Y
Yuin Chien 已提交
112

113
			filterInput.onfocus = function ( ) {
Y
Yuin Chien 已提交
114

M
munrocket@pm.me 已提交
115
				panel.classList.add( 'searchFocused' );
M
Mr.doob 已提交
116

M
munrocket@pm.me 已提交
117
			};
118

119
			filterInput.onblur = function ( ) {
120

M
munrocket@pm.me 已提交
121
				if ( filterInput.value === '' ) {
122

M
munrocket@pm.me 已提交
123
					panel.classList.remove( 'searchFocused' );
M
Mr.doob 已提交
124

M
munrocket@pm.me 已提交
125
				}
126

M
munrocket@pm.me 已提交
127
			};
M
Mr.doob 已提交
128

129
			exitSearchButton.onclick = function ( ) {
M
Mr.doob 已提交
130

M
munrocket@pm.me 已提交
131 132 133
				filterInput.value = '';
				updateFilter();
				panel.classList.remove( 'searchFocused' );
M
Mr.doob 已提交
134

M
munrocket@pm.me 已提交
135
			};
M
Mr.doob 已提交
136

M
munrocket@pm.me 已提交
137 138 139
			filterInput.addEventListener( 'input', function () {

				updateFilter();
M
Mr.doob 已提交
140 141 142 143

			} );


M
munrocket@pm.me 已提交
144
			expandButton.addEventListener( 'click', function ( event ) {
M
Mr.doob 已提交
145

M
munrocket@pm.me 已提交
146 147
				event.preventDefault();
				panel.classList.toggle( 'open' );
M
Mr.doob 已提交
148

M
munrocket@pm.me 已提交
149
			} );
M
Mr.doob 已提交
150

M
munrocket@pm.me 已提交
151
			panelScrim.onclick = function ( event ) {
M
Mr.doob 已提交
152

M
munrocket@pm.me 已提交
153 154
				event.preventDefault();
				panel.classList.toggle( 'open' );
M
Mr.doob 已提交
155

M
munrocket@pm.me 已提交
156
			};
M
Mr.doob 已提交
157

158
			previewsToggler.onclick = function ( event ) {
159 160 161

				event.preventDefault();

162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
				var styles = document.styleSheets[ 0 ];

				if ( previewsVisible ) {

					styles.insertRule( '.cover { display: none } ', 0 );

					previewsToggler.style.opacity = 1;
					previewsVisible = false;

				} else {

					styles.deleteRule( 0 );

					previewsToggler.style.opacity = 0.25;
					previewsVisible = true;
177 178 179 180 181

				}

			};

M
munrocket@pm.me 已提交
182
			// iOS iframe auto-resize workaround
M
Mr.doob 已提交
183

M
munrocket@pm.me 已提交
184 185 186 187 188
			if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {

				viewer.style.width = getComputedStyle( viewer ).width;
				viewer.style.height = getComputedStyle( viewer ).height;
				viewer.setAttribute( 'scrolling', 'no' );
M
Mr.doob 已提交
189 190

			}
M
Mr.doob 已提交
191 192 193

		}

M
munrocket@pm.me 已提交
194 195
		function createLink( file ) {

196 197 198 199 200

			var template = [
				'<div class="card">',
				'	<a href="' + file + '.html" target="viewer">',
				'		<div class="cover">',
M
munrocket@pm.me 已提交
201
				'			<img src="screenshots/' + file + '.jpg" loading="lazy" width="400" />',
202 203 204 205 206 207 208 209 210
				'		</div>',
				'		<div class="title">' + getName( file ) + '</div>',
				'	</a>',
				'</div>'
			].join( "\n" );

			var link = createElementFromHTML( template );

			link.querySelector( 'a[target="viewer"]' ).addEventListener( 'click', function ( event ) {
M
munrocket@pm.me 已提交
211 212 213 214 215 216 217 218 219 220 221

				if ( event.button !== 0 || event.ctrlKey || event.altKey || event.metaKey ) return;

				selectFile( file );

			} );

			return link;

		}

M
Mr.doob 已提交
222
		function loadFile( file ) {
M
Mr.doob 已提交
223

224 225 226
			selectFile( file );
			viewer.src = file + '.html';

M
Mr.doob 已提交
227
		}
228

M
Mr.doob 已提交
229
		function selectFile( file ) {
230

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

233
			links[ file ].classList.add( 'selected' );
M
Mr.doob 已提交
234 235

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

Y
Yuin Chien 已提交
238
			panel.classList.remove( 'open' );
M
Mr.doob 已提交
239

M
Mr.doob 已提交
240 241
			selected = file;

242 243 244
			// Reveal "View source" button and set attributes to this example
			viewSrcButton.style.display = '';
			viewSrcButton.href = 'https://github.com/mrdoob/three.js/blob/master/examples/' + selected + '.html';
M
Mr.doob 已提交
245
			viewSrcButton.title = 'View source code for ' + getName( selected ) + ' on GitHub';
246

247
		}
M
Mr.doob 已提交
248

M
Mugen87 已提交
249 250
		function updateFilter() {

251
			var v = filterInput.value;
M
Mugen87 已提交
252 253 254 255 256

			if ( v !== '' ) {

				window.history.replaceState( {}, '', '?q=' + v + window.location.hash );

257
			} else {
M
Mugen87 已提交
258 259 260

				window.history.replaceState( {}, '', window.location.pathname + window.location.hash );

261 262 263
			}

			var exp = new RegExp( v, 'gi' );
M
Mugen87 已提交
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280

			for ( var key in files ) {

				var section = files[ key ];

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

					filterExample( section[ i ], exp );

				}

			}

			layoutList();

		}

M
Mugen87 已提交
281
		function filterExample( file, exp ) {
M
Mugen87 已提交
282 283 284

			var link = links[ file ];
			var name = getName( file );
M
Mr.doob 已提交
285 286
			if ( file in tags ) file += tags[ file ].join( ' ' );
			var res = file.match( exp );
M
Mugen87 已提交
287 288 289 290
			var text;

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

M
Mr.doob 已提交
291
				link.classList.remove( 'hidden' );
M
Mugen87 已提交
292

M
Mugen87 已提交
293 294
				for ( var i = 0; i < res.length; i ++ ) {

M
Mugen87 已提交
295
					text = name.replace( res[ i ], '<b>' + res[ i ] + '</b>' );
M
Mugen87 已提交
296

M
Mugen87 已提交
297 298
				}

299
				link.querySelector( '.title' ).innerHTML = text;
M
Mugen87 已提交
300 301 302

			} else {

M
Mr.doob 已提交
303
				link.classList.add( 'hidden' );
304
				link.querySelector( '.title' ).innerHTML = name;
M
Mugen87 已提交
305 306

			}
M
Mugen87 已提交
307

M
Mugen87 已提交
308 309 310 311 312 313
		}

		function getName( file ) {

			var name = file.split( '_' );
			name.shift();
M
Mugen87 已提交
314
			return name.join( ' / ' );
M
Mugen87 已提交
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329

		}

		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 ];

M
Mugen87 已提交
330
					if ( links[ file ].classList.contains( 'hidden' ) === false ) {
M
Mugen87 已提交
331 332 333 334 335 336 337 338 339 340

						collapsed = false;
						break;

					}

				}

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

M
Mr.doob 已提交
341
				if ( collapsed ) {
M
Mugen87 已提交
342

M
Mr.doob 已提交
343
					element.classList.add( 'hidden' );
M
Mugen87 已提交
344 345 346

				} else {

M
Mr.doob 已提交
347
					element.classList.remove( 'hidden' );
M
Mugen87 已提交
348 349 350 351 352 353 354

				}

			}

		}

M
munrocket@pm.me 已提交
355 356 357 358 359
		function extractQuery() {

			var p = window.location.search.indexOf( '?q=' );

			if ( p !== - 1 ) {
M
Mr.doob 已提交
360

M
munrocket@pm.me 已提交
361
				return window.location.search.substr( 3 );
M
Mr.doob 已提交
362

M
munrocket@pm.me 已提交
363
			}
M
Mr.doob 已提交
364

M
munrocket@pm.me 已提交
365
			return '';
M
Mr.doob 已提交
366

M
munrocket@pm.me 已提交
367
		}
368

369 370 371 372 373 374 375 376 377

		function createElementFromHTML( htmlString ) {

			var div = document.createElement( 'div' );
			div.innerHTML = htmlString.trim();
			return div.firstChild;

		}

M
Mr.doob 已提交
378 379 380
		</script>

	</body>
381
</html>