Menubar.View.js 2.0 KB

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