Menubar.Examples.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. import {
  5. FileLoader
  6. } from '../../build/three.module.js';
  7. import { UIPanel, UIRow } from './libs/ui.js';
  8. var MenubarExamples = function ( editor ) {
  9. var strings = editor.strings;
  10. var container = new UIPanel();
  11. container.setClass( 'menu' );
  12. var title = new UIPanel();
  13. title.setClass( 'title' );
  14. title.setTextContent( strings.getKey( 'menubar/examples' ) );
  15. container.add( title );
  16. var options = new UIPanel();
  17. options.setClass( 'options' );
  18. container.add( options );
  19. // Examples
  20. var items = [
  21. { title: 'menubar/examples/Arkanoid', file: 'arkanoid.app.json' },
  22. { title: 'menubar/examples/Camera', file: 'camera.app.json' },
  23. { title: 'menubar/examples/Particles', file: 'particles.app.json' },
  24. { title: 'menubar/examples/Pong', file: 'pong.app.json' },
  25. { title: 'menubar/examples/Shaders', file: 'shaders.app.json' }
  26. ];
  27. var loader = new FileLoader();
  28. for ( var i = 0; i < items.length; i ++ ) {
  29. ( function ( i ) {
  30. var item = items[ i ];
  31. var option = new UIRow();
  32. option.setClass( 'option' );
  33. option.setTextContent( strings.getKey( item.title ) );
  34. option.onClick( function () {
  35. if ( confirm( 'Any unsaved data will be lost. Are you sure?' ) ) {
  36. loader.load( 'examples/' + item.file, function ( text ) {
  37. editor.clear();
  38. editor.fromJSON( JSON.parse( text ) );
  39. } );
  40. }
  41. } );
  42. options.add( option );
  43. } )( i );
  44. }
  45. return container;
  46. };
  47. export { MenubarExamples };