Menubar.View.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { UIPanel, UIRow } from './libs/ui.js';
  2. function MenubarView( editor ) {
  3. const strings = editor.strings;
  4. const container = new UIPanel();
  5. container.setClass( 'menu' );
  6. const title = new UIPanel();
  7. title.setClass( 'title' );
  8. title.setTextContent( strings.getKey( 'menubar/view' ) );
  9. container.add( title );
  10. const options = new UIPanel();
  11. options.setClass( 'options' );
  12. container.add( options );
  13. // Fullscreen
  14. const option = new UIRow();
  15. option.setClass( 'option' );
  16. option.setTextContent( strings.getKey( 'menubar/view/fullscreen' ) );
  17. option.onClick( function () {
  18. if ( document.fullscreenElement === null ) {
  19. document.documentElement.requestFullscreen();
  20. } else if ( document.exitFullscreen ) {
  21. document.exitFullscreen();
  22. }
  23. // Safari
  24. if ( document.webkitFullscreenElement === null ) {
  25. document.documentElement.webkitRequestFullscreen();
  26. } else if ( document.webkitExitFullscreen ) {
  27. document.webkitExitFullscreen();
  28. }
  29. } );
  30. options.add( option );
  31. // VR (Work in progress)
  32. if ( 'xr' in navigator ) {
  33. navigator.xr.isSessionSupported( 'immersive-ar' )
  34. .then( function ( supported ) {
  35. if ( supported ) {
  36. const option = new UIRow();
  37. option.setClass( 'option' );
  38. option.setTextContent( 'AR' );
  39. option.onClick( function () {
  40. editor.signals.enterXR.dispatch( 'immersive-ar' );
  41. } );
  42. options.add( option );
  43. } else {
  44. navigator.xr.isSessionSupported( 'immersive-vr' )
  45. .then( function ( supported ) {
  46. if ( supported ) {
  47. const option = new UIRow();
  48. option.setClass( 'option' );
  49. option.setTextContent( 'VR' );
  50. option.onClick( function () {
  51. editor.signals.enterXR.dispatch( 'immersive-vr' );
  52. } );
  53. options.add( option );
  54. }
  55. } );
  56. }
  57. } );
  58. }
  59. return container;
  60. }
  61. export { MenubarView };