FullScreenButton.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. define( function() {
  2. "use strict";
  3. function C_FullScreenButton()
  4. {
  5. };
  6. C_FullScreenButton.prototype.draw = function( oControlHost )
  7. {
  8. this.m_sControlName = oControlHost.configuration ? oControlHost.configuration.controlName : "";
  9. var elContainer = oControlHost.container;
  10. elContainer.innerHTML =
  11. '<style>' +
  12. ':-ms-fullscreen { background-color: white; }' +
  13. '.myFullScreenButton { background-color:transparent; padding:0px; border:none; fill:#DDDDDD; }' +
  14. '.myFullScreenButton:hover { cursor:pointer; fill:#B1B6BA; }' +
  15. '</style>' +
  16. '<button class="myFullScreenButton" title="' + ( this.m_sControlName ? 'Full screen' : 'Full screen report' ) + '">' +
  17. '<svg width="32px" height="32px" viewBox="0 0 32 32"><path d="M1,4v4v20h30V8V4H1z M29,26H3V10h26V26z"/><polygon points="18.707,21.707 25,15.414 25,20 27,20 27,12 19,12 19,14 23.586,14 17.293,20.293"/></svg>' +
  18. '</button>';
  19. this.m_btn = elContainer.lastChild;
  20. this.m_btn.onclick = this.onClick.bind( this, oControlHost );
  21. };
  22. C_FullScreenButton.prototype.onClick = function( oControlHost )
  23. {
  24. var el = this.m_sControlName ? oControlHost.page.getControlByName( this.m_sControlName ).element : document.body;
  25. this.requestFullScreen( el );
  26. };
  27. C_FullScreenButton.prototype.requestFullScreen = function( el )
  28. {
  29. var elFullScreenElement = document.fullScreenElement || document.msFullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement;
  30. if ( elFullScreenElement && ( elFullScreenElement == el ) )
  31. {
  32. if ( !document.cancelFullScreen )
  33. {
  34. document.cancelFullScreen = document.msExitFullscreen || document.mozCancelFullScreen || document.webkitCancelFullScreen;
  35. }
  36. document.cancelFullScreen();
  37. }
  38. else
  39. {
  40. if ( !el.requestFullscreen )
  41. {
  42. el.requestFullscreen = el.msRequestFullscreen || el.mozRequestFullScreen || el.webkitRequestFullscreen;
  43. }
  44. el.requestFullscreen();
  45. }
  46. };
  47. return C_FullScreenButton;
  48. });