Menubar.Examples.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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: 'Arkanoid', file: 'arkanoid.app.json' },
  17. { title: 'Camera', file: 'camera.app.json' },
  18. { title: 'Particles', file: 'particles.app.json' },
  19. { title: 'Pong', file: 'pong.app.json' }
  20. ];
  21. var loader = new THREE.XHRLoader();
  22. for ( var i = 0; i < items.length; i ++ ) {
  23. ( function ( i ) {
  24. var item = items[ i ];
  25. var option = new UI.Row();
  26. option.setClass( 'option' );
  27. option.setTextContent( item.title );
  28. option.onClick( function () {
  29. if ( confirm( 'Any unsaved data will be lost. Are you sure?' ) ) {
  30. loader.load( 'examples/' + item.file, function ( text ) {
  31. editor.clear();
  32. editor.fromJSON( JSON.parse( text ) );
  33. } );
  34. }
  35. } );
  36. options.add( option );
  37. } )( i )
  38. }
  39. return container;
  40. };