FullScreen.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Business Analytics (C) Copyright IBM Corp. 2019, 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['./FullScreenAPI', 'jquery', '../../../api/DashboardAPI', '../../../app/nls/StringResources', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI'], function (FullScreenAPI, $, DashboardAPI, stringResources, APIFactory, ContentActionsProviderAPI) {
  9. var FULL_SCREEN_CHANGE_EVENTS = 'webkitfullscreenchange mozfullscreenchange MSFullscreenChange fullscreenchange';
  10. /**
  11. * @implements {FullScreenAPI}
  12. */
  13. var FullScreen = function () {
  14. function FullScreen(_ref) {
  15. var features = _ref.features;
  16. _classCallCheck(this, FullScreen);
  17. this._dashboard = features.API;
  18. this._dashboardState = features.DashboardState;
  19. this._contentActions = features.ContentActions;
  20. this._icons = features.Icons;
  21. this._logger = this._dashboard.getService(DashboardAPI.GLOBAL_SERVICES.LOGGER);
  22. }
  23. FullScreen.prototype.initialize = function initialize() {
  24. this._api = APIFactory.createAPI(this, [FullScreenAPI, ContentActionsProviderAPI]);
  25. this._contentActions.registerProvider('fullScreenAction', this._api);
  26. this._dashboardState.onChangeActive(this._onChangeDashboardState.bind(this));
  27. this._dashboardState.onUiStateChange(this._onUiStateChange.bind(this));
  28. this._isEventTriggeredInternally = false;
  29. this._isFullScreen = false;
  30. this._inProgress = false;
  31. };
  32. FullScreen.prototype.getAPI = function getAPI() {
  33. return this._api;
  34. };
  35. FullScreen.prototype.destroy = function destroy() {
  36. this._api = null;
  37. $(document).off(FULL_SCREEN_CHANGE_EVENTS);
  38. };
  39. /**
  40. * @implements {FullScreenAPI#enter}
  41. * @description Enter full screen mode.<br/>
  42. * Please note that this method is REQUIRED to be invoked through a user
  43. * interaction due to security reasons in browsers.<br/>
  44. * See the following link for details:<br/>
  45. * https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen
  46. */
  47. FullScreen.prototype.enter = function enter() {
  48. if (this.isFullScreen()) {
  49. this._logger.info(FullScreen.LOGGER_MESSAGE.ENTER);
  50. return;
  51. }
  52. this._onEnterFullScreen();
  53. if (this._isFullScreenEnabled()) {
  54. this._isEventTriggeredInternally = true;
  55. if (document.body.requestFullscreen) {
  56. document.body.requestFullscreen();
  57. } else if (document.body.webkitRequestFullscreen) {
  58. document.body.webkitRequestFullscreen();
  59. } else if (document.body.mozRequestFullScreen) {
  60. document.body.mozRequestFullScreen();
  61. } else if (document.body.msRequestFullscreen && !(window.frameElement && window.frameElement.nodeName === 'IFRAME')) {
  62. // Don't use full screen mode when we are inside an iframe as
  63. // IE has a bug where sizes are mis-reported by a factor of
  64. // 100 in this case. If we are not in an iframe, then full screen is okay.
  65. //https://connect.microsoft.com/IE/feedback/details/838286
  66. document.body.msRequestFullscreen();
  67. }
  68. }
  69. };
  70. FullScreen.prototype.exit = function exit() {
  71. if (!this.isFullScreen()) {
  72. this._logger.info(FullScreen.LOGGER_MESSAGE.EXIT);
  73. return;
  74. }
  75. this._onExitFullScreen();
  76. if (this._isFullScreenEnabled()) {
  77. this._isEventTriggeredInternally = true;
  78. if (document.exitFullscreen) {
  79. document.exitFullscreen();
  80. } else if (document.webkitExitFullscreen) {
  81. document.webkitExitFullscreen();
  82. } else if (document.mozCancelFullScreen) {
  83. document.mozCancelFullScreen();
  84. } else if (document.msExitFullscreen) {
  85. document.msExitFullscreen();
  86. }
  87. }
  88. };
  89. FullScreen.prototype.isFullScreen = function isFullScreen() {
  90. return this._isFullScreen;
  91. };
  92. FullScreen.prototype._onChangeDashboardState = function _onChangeDashboardState(data) {
  93. if (!data.info.value) {
  94. this.exit();
  95. $(document).off(FULL_SCREEN_CHANGE_EVENTS);
  96. } else {
  97. $(document).on(FULL_SCREEN_CHANGE_EVENTS, this._onFullScreenChangeEvents.bind(this));
  98. }
  99. };
  100. FullScreen.prototype._onFullScreenChangeEvents = function _onFullScreenChangeEvents() {
  101. if (this._isEventTriggeredInternally) {
  102. this._isEventTriggeredInternally = false;
  103. } else {
  104. if (this.isFullScreen()) {
  105. this._onExitFullScreen();
  106. this._dashboardState.setFullScreen(false);
  107. } else {
  108. this._onEnterFullScreen();
  109. }
  110. }
  111. };
  112. /** Helpers */
  113. FullScreen.prototype._onEnterFullScreen = function _onEnterFullScreen() {
  114. // no api to hide the glass yet
  115. //needs to overwrite glass app/nav bar because layout.css has display:flex !important
  116. this._activePaneColumn = $('.appview.paneColumn').not('.hidden');
  117. this._activePaneColumn.find('.appbar').addClass('fullScreenNoGlass');
  118. this._activePaneColumn.find('.navbar').addClass('fullScreenNoGlass');
  119. this._activePaneColumn.find('.templateBox').addClass('fullScreen');
  120. $('body').addClass('fullScreen');
  121. document.body.style.cssText = 'height: 100% !important';
  122. $('body').append($('<div class="dashboardAriaAlert fullScreenAlert" role="alert"></div>').text(stringResources.get('ariaFullScreenMessage')));
  123. if (this._dashboardState.getUiState().authoring === true) {
  124. this._wasAuthoring = true;
  125. this._dashboardState.setAuthoring(false);
  126. }
  127. this._isFullScreen = true;
  128. this._dashboard.triggerDashboardEvent('enter:fullscreen');
  129. };
  130. FullScreen.prototype._onExitFullScreen = function _onExitFullScreen() {
  131. //needs to show the glass app & nav bar again.
  132. this._activePaneColumn.find('.appbar').removeClass('fullScreenNoGlass');
  133. this._activePaneColumn.find('.navbar').removeClass('fullScreenNoGlass');
  134. this._activePaneColumn.find('.templateBox').removeClass('fullScreen');
  135. $('body').removeClass('fullScreen');
  136. document.body.style.cssText = '';
  137. $('body').find('.fullScreenAlert').remove();
  138. if (this._wasAuthoring) {
  139. this._wasAuthoring = false;
  140. this._dashboardState.setAuthoring(true);
  141. }
  142. this._isFullScreen = false;
  143. this._dashboard.triggerDashboardEvent('exit:fullscreen');
  144. };
  145. FullScreen.prototype._isFullScreenEnabled = function _isFullScreenEnabled() {
  146. return document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled ? true : false;
  147. };
  148. /**
  149. * Callback for DashboardStateAPI#onUiStateChange
  150. * @see DashboardStateAPI#onUiStateChange for callback parameters
  151. */
  152. FullScreen.prototype._onUiStateChange = function _onUiStateChange(_ref2) {
  153. var fullScreen = _ref2.fullScreen;
  154. if (this._inProgress) {
  155. this._logger.info(FullScreen.LOGGER_MESSAGE.IN_PROGRESS);
  156. return;
  157. }
  158. this._inProgress = true;
  159. if (fullScreen === true) {
  160. this.enter();
  161. } else {
  162. this.exit();
  163. }
  164. this._inProgress = false;
  165. };
  166. /**
  167. * @implements ContentActionProviderAPI#getContentActionList
  168. */
  169. FullScreen.prototype.getContentActionList = function getContentActionList(idList) {
  170. var _this = this;
  171. var uiState = this._dashboardState.getUiState();
  172. if (idList.length > 0) {
  173. return [];
  174. }
  175. var label = void 0,
  176. icon = void 0;
  177. if (uiState.fullScreen) {
  178. label = stringResources.get('fullScreenClose');
  179. icon = this._icons.getIcon('minimize').id;
  180. } else {
  181. label = stringResources.get('fullScreenEnter');
  182. icon = this._icons.getIcon('maximize').id;
  183. }
  184. return [{
  185. name: 'FullScreen',
  186. type: 'Button',
  187. label: label,
  188. icon: icon,
  189. order: 2,
  190. disabled: uiState.eventGroups,
  191. action: function action() {
  192. if (uiState.fullScreen) {
  193. _this._dashboardState.setFullScreen(false);
  194. } else {
  195. _this._dashboardState.setFullScreen(true);
  196. }
  197. }
  198. }];
  199. };
  200. return FullScreen;
  201. }();
  202. FullScreen.LOGGER_MESSAGE = {
  203. ENTER: 'enter fullScreen - already in full screen',
  204. EXIT: 'exit fullScreen - not in full screen',
  205. IN_PROGRESS: 'change fullScreen state - already in progress'
  206. };
  207. return FullScreen;
  208. });
  209. //# sourceMappingURL=FullScreen.js.map