index.html 6.2 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
Mugen87 已提交
12 13
				text-decoration: none;
				cursor: pointer;
M
Mr.doob 已提交
14 15
			}

16
			#viewSrcButton {
M
Mr.doob 已提交
17 18 19
				position: fixed;
				bottom: 20px;
				right: 20px;
20 21 22 23 24
				padding: 8px;
				color: #fff;
				background-color: #555;
				opacity: 0.7;
			}
M
Mr.doob 已提交
25

26
			#viewSrcButton:hover {
M
Mugen87 已提交
27 28 29
				cursor: pointer;
				opacity: 1;
			}
M
Mr.doob 已提交
30 31 32
		</style>
	</head>
	<body>
M
Mugen87 已提交
33

Y
Yuin Chien 已提交
34
		<div id="panel" class="collapsed">
M
Mr.doob 已提交
35

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

M
Mr.doob 已提交
39
				<div id="sections">
Y
Yuin Chien 已提交
40 41
					<a href="../docs/">docs</a>
					<span class="selected">examples</span>
M
Mr.doob 已提交
42
				</div>
M
Mr.doob 已提交
43

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

Y
Yuin Chien 已提交
47 48 49 50 51 52 53 54 55 56 57 58
			<div id="panelScrim"></div>

			<div id="contentWrapper">
				<input placeholder="Search" type="text" id="filter" autocorrect="off" autocapitalize="off" spellcheck="false" />

				<select id="language">
					<option value="en">en</option>
					<option value="zh">zh</option>
				</select>

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

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

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

G
gero3 已提交
64
		<script src="files.js"></script>
65

M
Mr.doob 已提交
66 67
		<script>

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

M
Mr.doob 已提交
76
		var panel = document.getElementById( 'panel' );
M
Mr.doob 已提交
77
		var content = document.getElementById( 'content' );
M
Mr.doob 已提交
78
		var viewer = document.getElementById( 'viewer' );
M
Mr.doob 已提交
79

M
Mr.doob 已提交
80
		var filterInput = document.getElementById( 'filter' );
M
Mugen87 已提交
81

M
Mr.doob 已提交
82 83 84
		var expandButton = document.getElementById( 'expandButton' );
		expandButton.addEventListener( 'click', function ( event ) {
			event.preventDefault();
M
Mr.doob 已提交
85
			panel.classList.toggle( 'collapsed' );
M
Mr.doob 已提交
86 87
		} );

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

			event.preventDefault();
			panel.classList.toggle( 'collapsed' );

		};

96
		// iOS iframe auto-resize workaround
M
Mr.doob 已提交
97

98 99
		if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {

100 101
			viewer.style.width = getComputedStyle( viewer ).width;
			viewer.style.height = getComputedStyle( viewer ).height;
102
			viewer.setAttribute( 'scrolling', 'no' );
103 104 105

		}

M
Mr.doob 已提交
106
		var container = document.createElement( 'div' );
M
Mr.doob 已提交
107
		content.appendChild( container );
M
Mr.doob 已提交
108

109 110 111 112 113 114
		var viewSrcButton = document.createElement( 'a' );
		viewSrcButton.id = 'viewSrcButton';
		viewSrcButton.target = '_blank';
		viewSrcButton.textContent = 'View source';
		viewSrcButton.style.display = 'none';
		document.body.appendChild( viewSrcButton );
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

176
			panel.classList.add( 'collapsed' );
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 194 195 196 197 198 199 200 201 202
		// filter

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

			updateFilter();

		} );

		function updateFilter() {

203 204
			var v = filterInput.value;
			if( v !== '' ) {
205
				window.history.replaceState( {} , '', '?q=' + v + window.location.hash );
206
			} else {
207
				window.history.replaceState( {} , '', window.location.pathname + window.location.hash );
208 209 210
			}

			var exp = new RegExp( v, 'gi' );
M
Mugen87 已提交
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236

			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 已提交
237
				link.classList.remove( 'hidden' );
M
Mugen87 已提交
238 239 240 241 242 243 244 245 246

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

				link.innerHTML = text;

			} else {

M
Mr.doob 已提交
247
				link.classList.add( 'hidden' );
M
Mugen87 已提交
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
				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 已提交
273
					if ( links[ file ].classList.contains( 'hidden' ) === false ){
M
Mugen87 已提交
274 275 276 277 278 279 280 281 282 283

						collapsed = false;
						break;

					}

				}

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

M
Mr.doob 已提交
284
				if ( collapsed ) {
M
Mugen87 已提交
285

M
Mr.doob 已提交
286
					element.classList.add( 'hidden' );
M
Mugen87 已提交
287 288 289

				} else {

M
Mr.doob 已提交
290
					element.classList.remove( 'hidden' );
M
Mugen87 已提交
291 292 293 294 295 296 297

				}

			}

		}

298
		filterInput.value = extractQuery();
M
Mr.doob 已提交
299
		updateFilter();
300

M
Mr.doob 已提交
301 302 303
		</script>

	</body>
304
</html>