-
-
Notifications
You must be signed in to change notification settings - Fork 178
/
MenubarExamples.js
61 lines (40 loc) · 1.19 KB
/
MenubarExamples.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* @author mrdoob / http://mrdoob.com/
*/
import { UIPanel, UIRow } from './libs/ui.js';
function MenubarExamples( editor ) {
var container = new UIPanel();
container.setClass( 'menu' );
var title = new UIPanel();
title.setClass( 'title' );
title.setTextContent( 'Examples' );
container.add( title );
var options = new UIPanel();
options.setClass( 'options' );
container.add( options );
// Examples
var items = [
{ title: 'HTML Colors', file: 'html_colors.json' },
{ title: 'HTML Loop', file: 'html_loop.json' },
{ title: 'Three.js Cube', file: 'threejs_cube.json' },
{ title: 'Three.js Shaders', file: 'threejs_shaders.json' }
];
for ( var i = 0; i < items.length; i ++ ) {
( function ( i ) {
var item = items[ i ];
var option = new UIRow();
option.setClass( 'option' );
option.setTextContent( item.title );
option.onClick( async function () {
if ( confirm( 'Any unsaved data will be lost. Are you sure?' ) ) {
editor.clear();
const response = await fetch( './examples/' + item.file );
await editor.fromJSON( await response.json() );
}
} );
options.add( option );
} )( i )
}
return container;
}
export { MenubarExamples };