index.html 7.3 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
Mugen87 已提交
49 50 51 52 53 54 55 56
		const panel = document.getElementById( 'panel' );
		const content = document.getElementById( 'content' );
		const viewer = document.getElementById( 'viewer' );
		const filterInput = document.getElementById( 'filterInput' );
		const exitSearchButton = document.getElementById( 'exitSearchButton' );
		const expandButton = document.getElementById( 'expandButton' );
		const viewSrcButton = document.getElementById( 'button' );
		const panelScrim = document.getElementById( 'panelScrim' );
57

M
Mugen87 已提交
58
		const previewsToggler = document.getElementById( 'previewsToggler' );
M
Mugen87 已提交
59

M
Mugen87 已提交
60 61 62 63
		const links = {};
		const container = document.createElement( 'div' );

		let selected = null;
M
Mugen87 已提交
64

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

M
munrocket@pm.me 已提交
67 68 69 70 71 72
		function init() {

			content.appendChild( container );

			viewSrcButton.style.display = 'none';

M
Mugen87 已提交
73
			for ( const key in files ) {
M
munrocket@pm.me 已提交
74

M
Mugen87 已提交
75
				const section = files[ key ];
M
munrocket@pm.me 已提交
76

M
Mugen87 已提交
77
				const header = document.createElement( 'h2' );
M
munrocket@pm.me 已提交
78 79 80 81
				header.textContent = key;
				header.setAttribute( 'data-category', key );
				container.appendChild( header );

M
Mugen87 已提交
82
				for ( let i = 0; i < section.length; i ++ ) {
M
munrocket@pm.me 已提交
83

M
Mugen87 已提交
84
					const file = section[ i ];
M
munrocket@pm.me 已提交
85

M
Mugen87 已提交
86
					const link = createLink( file );
M
munrocket@pm.me 已提交
87 88 89 90 91
					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

				event.preventDefault();
161
				content.classList.toggle( 'minimal' );
162 163 164

			};

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

M
munrocket@pm.me 已提交
167 168 169 170 171
			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 已提交
172 173

			}
M
Mr.doob 已提交
174 175 176

		}

M
munrocket@pm.me 已提交
177 178
		function createLink( file ) {

M
Mugen87 已提交
179
			const template = [
180 181 182
				'<div class="card">',
				'	<a href="' + file + '.html" target="viewer">',
				'		<div class="cover">',
M
munrocket@pm.me 已提交
183
				'			<img src="screenshots/' + file + '.jpg" loading="lazy" width="400" />',
184 185 186 187 188 189
				'		</div>',
				'		<div class="title">' + getName( file ) + '</div>',
				'	</a>',
				'</div>'
			].join( "\n" );

M
Mugen87 已提交
190
			const link = createElementFromHTML( template );
191 192

			link.querySelector( 'a[target="viewer"]' ).addEventListener( 'click', function ( event ) {
M
munrocket@pm.me 已提交
193 194 195 196 197 198 199 200 201 202 203

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

				selectFile( file );

			} );

			return link;

		}

M
Mr.doob 已提交
204
		function loadFile( file ) {
M
Mr.doob 已提交
205

206 207 208
			selectFile( file );
			viewer.src = file + '.html';

M
Mr.doob 已提交
209
		}
210

M
Mr.doob 已提交
211
		function selectFile( file ) {
212

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

215
			links[ file ].classList.add( 'selected' );
M
Mr.doob 已提交
216 217

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

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

M
Mr.doob 已提交
222 223
			selected = file;

224 225 226
			// 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 已提交
227
			viewSrcButton.title = 'View source code for ' + getName( selected ) + ' on GitHub';
228

229
		}
M
Mr.doob 已提交
230

M
Mugen87 已提交
231 232
		function updateFilter() {

M
Mugen87 已提交
233
			let v = filterInput.value.trim();
M
Mugen87 已提交
234
			v = v.replace( /\s+/gi, ' ' ); // replace multiple whitespaces with a single one
M
Mugen87 已提交
235 236 237 238 239

			if ( v !== '' ) {

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

240
			} else {
M
Mugen87 已提交
241 242 243

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

244 245
			}

M
Mugen87 已提交
246
			const exp = new RegExp( v, 'gi' );
M
Mugen87 已提交
247

M
Mugen87 已提交
248
			for ( const key in files ) {
M
Mugen87 已提交
249

M
Mugen87 已提交
250
				const section = files[ key ];
M
Mugen87 已提交
251

M
Mugen87 已提交
252
				for ( let i = 0; i < section.length; i ++ ) {
M
Mugen87 已提交
253 254 255 256 257 258 259 260 261 262 263

					filterExample( section[ i ], exp );

				}

			}

			layoutList();

		}

M
Mugen87 已提交
264
		function filterExample( file, exp ) {
M
Mugen87 已提交
265

M
Mugen87 已提交
266 267
			const link = links[ file ];
			const name = getName( file );
M
Mugen87 已提交
268
			if ( file in tags ) file += ' ' + tags[ file ].join( ' ' );
M
Mugen87 已提交
269 270
			const res = file.match( exp );
			let text;
M
Mugen87 已提交
271 272 273

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

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

M
Mugen87 已提交
276
				for ( let i = 0; i < res.length; i ++ ) {
M
Mugen87 已提交
277

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

M
Mugen87 已提交
280 281
				}

282
				link.querySelector( '.title' ).innerHTML = text;
M
Mugen87 已提交
283 284 285

			} else {

M
Mr.doob 已提交
286
				link.classList.add( 'hidden' );
287
				link.querySelector( '.title' ).innerHTML = name;
M
Mugen87 已提交
288 289

			}
M
Mugen87 已提交
290

M
Mugen87 已提交
291 292 293 294
		}

		function getName( file ) {

M
Mugen87 已提交
295
			const name = file.split( '_' );
M
Mugen87 已提交
296
			name.shift();
M
Mugen87 已提交
297
			return name.join( ' / ' );
M
Mugen87 已提交
298 299 300 301 302

		}

		function layoutList() {

M
Mugen87 已提交
303
			for ( const key in files ) {
M
Mugen87 已提交
304

M
Mugen87 已提交
305
				let collapsed = true;
M
Mugen87 已提交
306

M
Mugen87 已提交
307
				const section = files[ key ];
M
Mugen87 已提交
308

M
Mugen87 已提交
309
				for ( let i = 0; i < section.length; i ++ ) {
M
Mugen87 已提交
310

M
Mugen87 已提交
311
					const file = section[ i ];
M
Mugen87 已提交
312

M
Mugen87 已提交
313
					if ( links[ file ].classList.contains( 'hidden' ) === false ) {
M
Mugen87 已提交
314 315 316 317 318 319 320 321

						collapsed = false;
						break;

					}

				}

M
Mugen87 已提交
322
				const element = document.querySelector( 'h2[data-category="' + key + '"]' );
M
Mugen87 已提交
323

M
Mr.doob 已提交
324
				if ( collapsed ) {
M
Mugen87 已提交
325

M
Mr.doob 已提交
326
					element.classList.add( 'hidden' );
M
Mugen87 已提交
327 328 329

				} else {

M
Mr.doob 已提交
330
					element.classList.remove( 'hidden' );
M
Mugen87 已提交
331 332 333 334 335 336 337

				}

			}

		}

M
munrocket@pm.me 已提交
338 339
		function extractQuery() {

M
Mugen87 已提交
340
			const p = window.location.search.indexOf( '?q=' );
M
munrocket@pm.me 已提交
341 342

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

M
Mugen87 已提交
344
				return decodeURI( window.location.search.substr( 3 ) );
M
Mr.doob 已提交
345

M
munrocket@pm.me 已提交
346
			}
M
Mr.doob 已提交
347

M
munrocket@pm.me 已提交
348
			return '';
M
Mr.doob 已提交
349

M
munrocket@pm.me 已提交
350
		}
351

352 353 354

		function createElementFromHTML( htmlString ) {

M
Mugen87 已提交
355
			const div = document.createElement( 'div' );
356 357 358 359 360
			div.innerHTML = htmlString.trim();
			return div.firstChild;

		}

M
Mr.doob 已提交
361 362 363
		</script>

	</body>
364
</html>