提交 b23a10f2 编写于 作者: M Mugen87

Examples: Clean up.

上级 efb13f9a
var files = { const files = {
"webgl": [ "webgl": [
"webgl_animation_cloth", "webgl_animation_cloth",
"webgl_animation_keyframes", "webgl_animation_keyframes",
...@@ -404,7 +404,7 @@ var files = { ...@@ -404,7 +404,7 @@ var files = {
] ]
}; };
var tags = { const tags = {
"webgl_animation_cloth": [ "physics", "integration" ], "webgl_animation_cloth": [ "physics", "integration" ],
"webgl_clipping": [ "solid" ], "webgl_clipping": [ "solid" ],
"webgl_clipping_advanced": [ "solid" ], "webgl_clipping_advanced": [ "solid" ],
......
...@@ -46,20 +46,21 @@ ...@@ -46,20 +46,21 @@
<script> <script>
var panel = document.getElementById( 'panel' ); const panel = document.getElementById( 'panel' );
var content = document.getElementById( 'content' ); const content = document.getElementById( 'content' );
var viewer = document.getElementById( 'viewer' ); const viewer = document.getElementById( 'viewer' );
var filterInput = document.getElementById( 'filterInput' ); const filterInput = document.getElementById( 'filterInput' );
var exitSearchButton = document.getElementById( 'exitSearchButton' ); const exitSearchButton = document.getElementById( 'exitSearchButton' );
var expandButton = document.getElementById( 'expandButton' ); const expandButton = document.getElementById( 'expandButton' );
var viewSrcButton = document.getElementById( 'button' ); const viewSrcButton = document.getElementById( 'button' );
var panelScrim = document.getElementById( 'panelScrim' ); const panelScrim = document.getElementById( 'panelScrim' );
var previewsToggler = document.getElementById( 'previewsToggler' ); const previewsToggler = document.getElementById( 'previewsToggler' );
var links = {}; const links = {};
var selected = null; const container = document.createElement( 'div' );
var container = document.createElement( 'div' );
let selected = null;
init(); init();
...@@ -69,20 +70,20 @@ ...@@ -69,20 +70,20 @@
viewSrcButton.style.display = 'none'; viewSrcButton.style.display = 'none';
for ( var key in files ) { for ( const key in files ) {
var section = files[ key ]; const section = files[ key ];
var header = document.createElement( 'h2' ); const header = document.createElement( 'h2' );
header.textContent = key; header.textContent = key;
header.setAttribute( 'data-category', key ); header.setAttribute( 'data-category', key );
container.appendChild( header ); container.appendChild( header );
for ( var i = 0; i < section.length; i ++ ) { for ( let i = 0; i < section.length; i ++ ) {
var file = section[ i ]; const file = section[ i ];
var link = createLink( file ); const link = createLink( file );
container.appendChild( link ); container.appendChild( link );
links[ file ] = link; links[ file ] = link;
...@@ -175,8 +176,7 @@ ...@@ -175,8 +176,7 @@
function createLink( file ) { function createLink( file ) {
const template = [
var template = [
'<div class="card">', '<div class="card">',
' <a href="' + file + '.html" target="viewer">', ' <a href="' + file + '.html" target="viewer">',
' <div class="cover">', ' <div class="cover">',
...@@ -187,7 +187,7 @@ ...@@ -187,7 +187,7 @@
'</div>' '</div>'
].join( "\n" ); ].join( "\n" );
var link = createElementFromHTML( template ); const link = createElementFromHTML( template );
link.querySelector( 'a[target="viewer"]' ).addEventListener( 'click', function ( event ) { link.querySelector( 'a[target="viewer"]' ).addEventListener( 'click', function ( event ) {
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
function updateFilter() { function updateFilter() {
var v = filterInput.value.trim(); let v = filterInput.value.trim();
v = v.replace( /\s+/gi, ' ' ); // replace multiple whitespaces with a single one v = v.replace( /\s+/gi, ' ' ); // replace multiple whitespaces with a single one
if ( v !== '' ) { if ( v !== '' ) {
...@@ -243,13 +243,13 @@ ...@@ -243,13 +243,13 @@
} }
var exp = new RegExp( v, 'gi' ); const exp = new RegExp( v, 'gi' );
for ( var key in files ) { for ( const key in files ) {
var section = files[ key ]; const section = files[ key ];
for ( var i = 0; i < section.length; i ++ ) { for ( let i = 0; i < section.length; i ++ ) {
filterExample( section[ i ], exp ); filterExample( section[ i ], exp );
...@@ -263,17 +263,17 @@ ...@@ -263,17 +263,17 @@
function filterExample( file, exp ) { function filterExample( file, exp ) {
var link = links[ file ]; const link = links[ file ];
var name = getName( file ); const name = getName( file );
if ( file in tags ) file += ' ' + tags[ file ].join( ' ' ); if ( file in tags ) file += ' ' + tags[ file ].join( ' ' );
var res = file.match( exp ); const res = file.match( exp );
var text; let text;
if ( res && res.length > 0 ) { if ( res && res.length > 0 ) {
link.classList.remove( 'hidden' ); link.classList.remove( 'hidden' );
for ( var i = 0; i < res.length; i ++ ) { for ( let i = 0; i < res.length; i ++ ) {
text = name.replace( res[ i ], '<b>' + res[ i ] + '</b>' ); text = name.replace( res[ i ], '<b>' + res[ i ] + '</b>' );
...@@ -292,7 +292,7 @@ ...@@ -292,7 +292,7 @@
function getName( file ) { function getName( file ) {
var name = file.split( '_' ); const name = file.split( '_' );
name.shift(); name.shift();
return name.join( ' / ' ); return name.join( ' / ' );
...@@ -300,15 +300,15 @@ ...@@ -300,15 +300,15 @@
function layoutList() { function layoutList() {
for ( var key in files ) { for ( const key in files ) {
var collapsed = true; let collapsed = true;
var section = files[ key ]; const section = files[ key ];
for ( var i = 0; i < section.length; i ++ ) { for ( let i = 0; i < section.length; i ++ ) {
var file = section[ i ]; const file = section[ i ];
if ( links[ file ].classList.contains( 'hidden' ) === false ) { if ( links[ file ].classList.contains( 'hidden' ) === false ) {
...@@ -319,7 +319,7 @@ ...@@ -319,7 +319,7 @@
} }
var element = document.querySelector( 'h2[data-category="' + key + '"]' ); const element = document.querySelector( 'h2[data-category="' + key + '"]' );
if ( collapsed ) { if ( collapsed ) {
...@@ -337,7 +337,7 @@ ...@@ -337,7 +337,7 @@
function extractQuery() { function extractQuery() {
var p = window.location.search.indexOf( '?q=' ); const p = window.location.search.indexOf( '?q=' );
if ( p !== - 1 ) { if ( p !== - 1 ) {
...@@ -352,7 +352,7 @@ ...@@ -352,7 +352,7 @@
function createElementFromHTML( htmlString ) { function createElementFromHTML( htmlString ) {
var div = document.createElement( 'div' ); const div = document.createElement( 'div' );
div.innerHTML = htmlString.trim(); div.innerHTML = htmlString.trim();
return div.firstChild; return div.firstChild;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册