Menubar.Examples.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. Menubar.Examples = function ( editor ) {
  5. var container = new UI.Panel();
  6. container.setClass( 'menu' );
  7. var title = new UI.Panel();
  8. title.setClass( 'title' );
  9. title.setTextContent( 'Examples' );
  10. container.add( title );
  11. var options = new UI.Panel();
  12. options.setClass( 'options' );
  13. container.add( options );
  14. // Examples
  15. var items = [
  16. { title: 'Camera', file: 'camera.app.json' },
  17. { title: 'Particles', file: 'particles.app.json' },
  18. { title: 'Pong', file: 'pong.app.json' }
  19. ];
  20. var loader = new THREE.XHRLoader();
  21. for ( var i = 0; i < items.length; i ++ ) {
  22. ( function ( i ) {
  23. var item = items[ i ];
  24. var option = new UI.Panel();
  25. option.setClass( 'option' );
  26. option.setTextContent( item.title );
  27. option.onClick( function () {
  28. if ( confirm( 'Any unsaved data will be lost. Are you sure?' ) ) {
  29. loader.load( 'examples/' + item.file, function ( text ) {
  30. editor.clear();
  31. editor.fromJSON( JSON.parse( text ) );
  32. } );
  33. }
  34. } );
  35. options.add( option );
  36. } )( i )
  37. }
  38. return container;
  39. };