index.html 6.5 KB
Newer Older
M
Mr.doob 已提交
1 2 3
<!DOCTYPE html>
<html lang="en">
	<head>
M
Mr.doob 已提交
4
		<meta charset="utf-8">
M
Mr.doob 已提交
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
			}
13
			#button {
M
Mr.doob 已提交
14
				position: fixed;
Y
Yuin Chien 已提交
15 16
				bottom: 12px;
				right: 12px;
17

18
				padding: 8px;
19 20 21 22 23
				border-radius: 50%;
				margin-bottom: 0px; /* TODO div sets it to 20px */

				background-color: #E5E5E5;
				opacity: .9;
24
			}
M
Mr.doob 已提交
25

26
			#button:hover {
M
Mugen87 已提交
27 28 29
				cursor: pointer;
				opacity: 1;
			}
30 31 32

			#button img {
				display: block;
Y
Yuin Chien 已提交
33
				width: 20px;
34
			}
M
Mr.doob 已提交
35 36 37
		</style>
	</head>
	<body>
M
Mugen87 已提交
38

39
		<div id="panel">
M
Mr.doob 已提交
40

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

M
Mr.doob 已提交
44
				<div id="sections">
Y
Yuin Chien 已提交
45 46
					<a href="../docs/">docs</a>
					<span class="selected">examples</span>
M
Mr.doob 已提交
47
				</div>
M
Mr.doob 已提交
48

Y
Yuin Chien 已提交
49
				<img id="expandButton" src="../files/ic_menu_black_24dp.svg">
M
Mugen87 已提交
50
			</div>
M
Mr.doob 已提交
51

Y
Yuin Chien 已提交
52 53 54 55
			<div id="panelScrim"></div>

			<div id="contentWrapper">
				<input placeholder="Search" type="text" id="filter" autocorrect="off" autocapitalize="off" spellcheck="false" />
Y
Yuin Chien 已提交
56
				<div id="exitSearchButton"></div>
Y
Yuin Chien 已提交
57 58 59

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

M
Mr.doob 已提交
61
		</div>
M
Mr.doob 已提交
62

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

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

G
gero3 已提交
67
		<script src="files.js"></script>
68

M
Mr.doob 已提交
69 70
		<script>

71
		function extractQuery() {
72
			var p = window.location.search.indexOf( '?q=' );
73 74
			if( p !== -1 ) {
				return window.location.search.substr( 3 );
M
Mr.doob 已提交
75
			}
76 77 78
			return ''
		}

M
Mr.doob 已提交
79
		var panel = document.getElementById( 'panel' );
M
Mr.doob 已提交
80
		var content = document.getElementById( 'content' );
M
Mr.doob 已提交
81
		var viewer = document.getElementById( 'viewer' );
M
Mr.doob 已提交
82

M
Mr.doob 已提交
83
		var filterInput = document.getElementById( 'filter' );
Y
Yuin Chien 已提交
84
		var exitSearchButton = document.getElementById( 'exitSearchButton' );
M
Mugen87 已提交
85

M
Mr.doob 已提交
86 87 88
		var expandButton = document.getElementById( 'expandButton' );
		expandButton.addEventListener( 'click', function ( event ) {
			event.preventDefault();
89
			panel.classList.toggle( 'open' );
M
Mr.doob 已提交
90 91
		} );

Y
Yuin Chien 已提交
92 93 94 95
		var panelScrim = document.getElementById( 'panelScrim' );
		panelScrim.onclick = function ( event ) {

			event.preventDefault();
96
			panel.classList.toggle( 'open' );
Y
Yuin Chien 已提交
97 98 99

		};

100
		// iOS iframe auto-resize workaround
M
Mr.doob 已提交
101

102 103
		if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {

104 105
			viewer.style.width = getComputedStyle( viewer ).width;
			viewer.style.height = getComputedStyle( viewer ).height;
106
			viewer.setAttribute( 'scrolling', 'no' );
107 108 109

		}

M
Mr.doob 已提交
110
		var container = document.createElement( 'div' );
M
Mr.doob 已提交
111
		content.appendChild( container );
M
Mr.doob 已提交
112

113
		var viewSrcButton = document.getElementById( 'button' );
114
		viewSrcButton.style.display = 'none';
115

116
		var links = {};
117
		var selected = null;
M
Mr.doob 已提交
118

M
Mr.doob 已提交
119 120 121 122 123 124 125 126 127
		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 已提交
128
				if ( event.button !== 0 || event.ctrlKey || event.altKey || event.metaKey ) return;
M
Mr.doob 已提交
129

M
Mr.doob 已提交
130
				selectFile( file );
M
Mr.doob 已提交
131 132 133 134 135 136 137

			} );

			return link;

		}

M
Mr.doob 已提交
138
		for ( var key in files ) {
M
Mr.doob 已提交
139

M
Mr.doob 已提交
140
			var section = files[ key ];
M
Mr.doob 已提交
141

M
Mugen87 已提交
142 143 144 145
			var header = document.createElement( 'h2' );
			header.textContent = key;
			header.setAttribute( 'data-category', key );
			container.appendChild( header );
M
Mr.doob 已提交
146

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

M
Mr.doob 已提交
149
				var file = section[ i ];
M
Mr.doob 已提交
150

M
Mr.doob 已提交
151 152
				var link = createLink( file );
				container.appendChild( link );
M
Mr.doob 已提交
153

M
Mr.doob 已提交
154
				links[ file ] = link;
M
Mr.doob 已提交
155 156

			}
M
Mr.doob 已提交
157 158 159

		}

M
Mr.doob 已提交
160
		function loadFile( file ) {
M
Mr.doob 已提交
161

162 163 164
			selectFile( file );
			viewer.src = file + '.html';

M
Mr.doob 已提交
165
		}
166

M
Mr.doob 已提交
167
		function selectFile( file ) {
168

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

171
			links[ file ].classList.add( 'selected' );
M
Mr.doob 已提交
172 173

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

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

M
Mr.doob 已提交
178 179
			selected = file;

180 181 182
			// 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 已提交
183
			viewSrcButton.title = 'View source code for ' + getName( selected ) + ' on GitHub';
184

185
		}
M
Mr.doob 已提交
186

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

M
Mr.doob 已提交
189
			loadFile( window.location.hash.substring( 1 ) );
M
Mr.doob 已提交
190 191 192

		}

M
Mugen87 已提交
193
		// filter
Y
Yuin Chien 已提交
194 195 196 197 198 199
		filterInput.onfocus = function ( event ) {

			panel.classList.add('searchFocused');

		}

200 201 202 203 204 205 206 207
		filterInput.onblur = function ( event ) {

			if(filterInput.value === '') {
				panel.classList.remove('searchFocused');
			}

		}

Y
Yuin Chien 已提交
208 209 210 211 212 213 214
		exitSearchButton.onclick = function( event ) {

			filterInput.value = '';
			updateFilter();
			panel.classList.remove('searchFocused');

		}
M
Mugen87 已提交
215 216 217 218 219 220 221 222 223

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

			updateFilter();

		} );

		function updateFilter() {

224 225
			var v = filterInput.value;
			if( v !== '' ) {
226
				window.history.replaceState( {} , '', '?q=' + v + window.location.hash );
227
			} else {
228
				window.history.replaceState( {} , '', window.location.pathname + window.location.hash );
229 230 231
			}

			var exp = new RegExp( v, 'gi' );
M
Mugen87 已提交
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257

			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 ) {

M
Mr.doob 已提交
258
				link.classList.remove( 'hidden' );
M
Mugen87 已提交
259 260 261 262 263 264 265 266 267

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

				link.innerHTML = text;

			} else {

M
Mr.doob 已提交
268
				link.classList.add( 'hidden' );
M
Mugen87 已提交
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
				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 ];

M
Mr.doob 已提交
294
					if ( links[ file ].classList.contains( 'hidden' ) === false ){
M
Mugen87 已提交
295 296 297 298 299 300 301 302 303 304

						collapsed = false;
						break;

					}

				}

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

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

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

				} else {

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

				}

			}

		}

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

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

	</body>
325
</html>