index.html 6.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
		<link rel="shortcut icon" href="../files/favicon.ico" />
		<link rel="stylesheet" type="text/css" href="../files/main.css">
M
Mr.doob 已提交
9
		<style>
M
Mugen87 已提交
10
			#panel #content .link {
M
Mr.doob 已提交
11
				display: block;
M
Mr.doob 已提交
12
			}
M
Mr.doob 已提交
13 14 15
		</style>
	</head>
	<body>
M
Mugen87 已提交
16

17
		<div id="panel">
M
Mr.doob 已提交
18

M
Mr.doob 已提交
19 20
			<div id="header">
				<h1><a href="http://threejs.org">three.js</a></h1>
M
Mr.doob 已提交
21

M
Mr.doob 已提交
22
				<div id="sections">
23
					<a href="../docs/index.html#manual/introduction/Creating-a-scene">docs</a>
Y
Yuin Chien 已提交
24
					<span class="selected">examples</span>
M
Mr.doob 已提交
25
				</div>
M
Mr.doob 已提交
26

27
				<div id="expandButton"></div>
M
Mugen87 已提交
28
			</div>
M
Mr.doob 已提交
29

Y
Yuin Chien 已提交
30 31 32
			<div id="panelScrim"></div>

			<div id="contentWrapper">
33 34 35 36 37

				<div id="inputWrapper">
					<input placeholder="" type="text" id="filter" autocorrect="off" autocapitalize="off" spellcheck="false" />
					<div id="exitSearchButton"></div>
				</div>
Y
Yuin Chien 已提交
38 39 40

				<div id="content"></div>
			</div>
M
Mr.doob 已提交
41

M
Mr.doob 已提交
42
		</div>
M
Mr.doob 已提交
43

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

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

G
gero3 已提交
48
		<script src="files.js"></script>
49

M
Mr.doob 已提交
50 51
		<script>

52
		function extractQuery() {
M
Mugen87 已提交
53

54
			var p = window.location.search.indexOf( '?q=' );
M
Mugen87 已提交
55 56 57

			if ( p !== - 1 ) {

58
				return window.location.search.substr( 3 );
M
Mugen87 已提交
59

M
Mr.doob 已提交
60
			}
M
Mugen87 已提交
61 62 63

			return '';

64 65
		}

M
Mr.doob 已提交
66
		var panel = document.getElementById( 'panel' );
M
Mr.doob 已提交
67
		var content = document.getElementById( 'content' );
M
Mr.doob 已提交
68
		var viewer = document.getElementById( 'viewer' );
M
Mr.doob 已提交
69

M
Mr.doob 已提交
70
		var filterInput = document.getElementById( 'filter' );
Y
Yuin Chien 已提交
71
		var exitSearchButton = document.getElementById( 'exitSearchButton' );
M
Mugen87 已提交
72

M
Mr.doob 已提交
73 74
		var expandButton = document.getElementById( 'expandButton' );
		expandButton.addEventListener( 'click', function ( event ) {
M
Mugen87 已提交
75

M
Mr.doob 已提交
76
			event.preventDefault();
77
			panel.classList.toggle( 'open' );
M
Mugen87 已提交
78

M
Mr.doob 已提交
79 80
		} );

Y
Yuin Chien 已提交
81 82 83 84
		var panelScrim = document.getElementById( 'panelScrim' );
		panelScrim.onclick = function ( event ) {

			event.preventDefault();
85
			panel.classList.toggle( 'open' );
Y
Yuin Chien 已提交
86 87 88

		};

89
		// iOS iframe auto-resize workaround
M
Mr.doob 已提交
90

91 92
		if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {

93 94
			viewer.style.width = getComputedStyle( viewer ).width;
			viewer.style.height = getComputedStyle( viewer ).height;
95
			viewer.setAttribute( 'scrolling', 'no' );
96 97 98

		}

M
Mr.doob 已提交
99
		var container = document.createElement( 'div' );
M
Mr.doob 已提交
100
		content.appendChild( container );
M
Mr.doob 已提交
101

102
		var viewSrcButton = document.getElementById( 'button' );
103
		viewSrcButton.style.display = 'none';
104

105
		var links = {};
106
		var selected = null;
M
Mr.doob 已提交
107

M
Mr.doob 已提交
108 109 110 111 112 113 114 115 116
		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 ) {

M
Mr.doob 已提交
117
				if ( event.button !== 0 || event.ctrlKey || event.altKey || event.metaKey ) return;
M
Mr.doob 已提交
118

M
Mr.doob 已提交
119
				selectFile( file );
M
Mr.doob 已提交
120 121 122 123 124 125 126

			} );

			return link;

		}

M
Mr.doob 已提交
127
		for ( var key in files ) {
M
Mr.doob 已提交
128

M
Mr.doob 已提交
129
			var section = files[ key ];
M
Mr.doob 已提交
130

M
Mugen87 已提交
131 132 133 134
			var header = document.createElement( 'h2' );
			header.textContent = key;
			header.setAttribute( 'data-category', key );
			container.appendChild( header );
M
Mr.doob 已提交
135

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

M
Mr.doob 已提交
138
				var file = section[ i ];
M
Mr.doob 已提交
139

M
Mr.doob 已提交
140 141
				var link = createLink( file );
				container.appendChild( link );
M
Mr.doob 已提交
142

M
Mr.doob 已提交
143
				links[ file ] = link;
M
Mr.doob 已提交
144 145

			}
M
Mr.doob 已提交
146 147 148

		}

M
Mr.doob 已提交
149
		function loadFile( file ) {
M
Mr.doob 已提交
150

151 152 153
			selectFile( file );
			viewer.src = file + '.html';

M
Mr.doob 已提交
154
		}
155

M
Mr.doob 已提交
156
		function selectFile( file ) {
157

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

160
			links[ file ].classList.add( 'selected' );
M
Mr.doob 已提交
161 162

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

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

M
Mr.doob 已提交
167 168
			selected = file;

169 170 171
			// 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 已提交
172
			viewSrcButton.title = 'View source code for ' + getName( selected ) + ' on GitHub';
173

174
		}
M
Mr.doob 已提交
175

176
		if ( window.location.hash !== '' && links[ window.location.hash.substring( 1 ) ] ) {
M
Mr.doob 已提交
177

M
Mr.doob 已提交
178
			loadFile( window.location.hash.substring( 1 ) );
M
Mr.doob 已提交
179 180 181

		}

M
Mugen87 已提交
182
		// filter
Y
Yuin Chien 已提交
183 184
		filterInput.onfocus = function ( event ) {

M
Mugen87 已提交
185
			panel.classList.add( 'searchFocused' );
Y
Yuin Chien 已提交
186

M
Mugen87 已提交
187
		};
Y
Yuin Chien 已提交
188

189 190
		filterInput.onblur = function ( event ) {

M
Mugen87 已提交
191 192 193 194
			if ( filterInput.value === '' ) {

				panel.classList.remove( 'searchFocused' );

195 196
			}

M
Mugen87 已提交
197
		};
198

M
Mugen87 已提交
199
		exitSearchButton.onclick = function ( event ) {
Y
Yuin Chien 已提交
200 201 202

			filterInput.value = '';
			updateFilter();
M
Mugen87 已提交
203
			panel.classList.remove( 'searchFocused' );
Y
Yuin Chien 已提交
204

M
Mugen87 已提交
205
		};
M
Mugen87 已提交
206

M
Mugen87 已提交
207
		filterInput.addEventListener( 'input', function () {
M
Mugen87 已提交
208 209 210 211 212 213 214

			updateFilter();

		} );

		function updateFilter() {

215
			var v = filterInput.value;
M
Mugen87 已提交
216 217 218 219 220

			if ( v !== '' ) {

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

221
			} else {
M
Mugen87 已提交
222 223 224

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

225 226 227
			}

			var exp = new RegExp( v, 'gi' );
M
Mugen87 已提交
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244

			for ( var key in files ) {

				var section = files[ key ];

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

					filterExample( section[ i ], exp );

				}

			}

			layoutList();

		}

M
Mugen87 已提交
245
		function filterExample( file, exp ) {
M
Mugen87 已提交
246 247 248 249 250 251 252 253

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

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

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

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

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

M
Mugen87 已提交
260 261 262 263 264 265
				}

				link.innerHTML = text;

			} else {

M
Mr.doob 已提交
266
				link.classList.add( 'hidden' );
M
Mugen87 已提交
267 268 269
				link.innerHTML = name;

			}
M
Mugen87 已提交
270

M
Mugen87 已提交
271 272 273 274 275 276
		}

		function getName( file ) {

			var name = file.split( '_' );
			name.shift();
M
Mugen87 已提交
277
			return name.join( ' / ' );
M
Mugen87 已提交
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292

		}

		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 已提交
293
					if ( links[ file ].classList.contains( 'hidden' ) === false ) {
M
Mugen87 已提交
294 295 296 297 298 299 300 301 302 303

						collapsed = false;
						break;

					}

				}

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

M
Mr.doob 已提交
304
				if ( collapsed ) {
M
Mugen87 已提交
305

M
Mr.doob 已提交
306
					element.classList.add( 'hidden' );
M
Mugen87 已提交
307 308 309

				} else {

M
Mr.doob 已提交
310
					element.classList.remove( 'hidden' );
M
Mugen87 已提交
311 312 313 314 315 316 317

				}

			}

		}

318
		filterInput.value = extractQuery();
M
Mr.doob 已提交
319
		updateFilter();
320

M
Mr.doob 已提交
321 322 323
		</script>

	</body>
324
</html>