full-screen.src.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /**
  2. * @license Highstock JS v8.2.0 (2020-08-20)
  3. *
  4. * Advanced Highstock tools
  5. *
  6. * (c) 2010-2019 Highsoft AS
  7. * Author: Torstein Honsi
  8. *
  9. * License: www.highcharts.com/license
  10. */
  11. 'use strict';
  12. (function (factory) {
  13. if (typeof module === 'object' && module.exports) {
  14. factory['default'] = factory;
  15. module.exports = factory;
  16. } else if (typeof define === 'function' && define.amd) {
  17. define('highcharts/modules/full-screen', ['highcharts'], function (Highcharts) {
  18. factory(Highcharts);
  19. factory.Highcharts = Highcharts;
  20. return factory;
  21. });
  22. } else {
  23. factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
  24. }
  25. }(function (Highcharts) {
  26. var _modules = Highcharts ? Highcharts._modules : {};
  27. function _registerModule(obj, path, args, fn) {
  28. if (!obj.hasOwnProperty(path)) {
  29. obj[path] = fn.apply(null, args);
  30. }
  31. }
  32. _registerModule(_modules, 'Extensions/FullScreen.js', [_modules['Core/Chart/Chart.js'], _modules['Core/Globals.js'], _modules['Core/Utilities.js']], function (Chart, H, U) {
  33. /* *
  34. * (c) 2009-2020 Rafal Sebestjanski
  35. *
  36. * Full screen for Highcharts
  37. *
  38. * License: www.highcharts.com/license
  39. */
  40. var addEvent = U.addEvent;
  41. /**
  42. * The module allows user to enable display chart in full screen mode.
  43. * Used in StockTools too.
  44. * Based on default solutions in browsers.
  45. *
  46. */
  47. /* eslint-disable no-invalid-this, valid-jsdoc */
  48. /**
  49. * Handles displaying chart's container in the fullscreen mode.
  50. *
  51. * **Note**: Fullscreen is not supported on iPhone due to iOS limitations.
  52. *
  53. * @class
  54. * @name Highcharts.Fullscreen
  55. * @hideconstructor
  56. * @requires modules/full-screen
  57. */
  58. var Fullscreen = /** @class */ (function () {
  59. /* *
  60. *
  61. * Constructors
  62. *
  63. * */
  64. function Fullscreen(chart) {
  65. /**
  66. * Chart managed by the fullscreen controller.
  67. * @name Highcharts.Fullscreen#chart
  68. * @type {Highcharts.Chart}
  69. */
  70. this.chart = chart;
  71. /**
  72. * The flag is set to `true` when the chart is displayed in
  73. * the fullscreen mode.
  74. *
  75. * @name Highcharts.Fullscreen#isOpen
  76. * @type {boolean|undefined}
  77. * @since 8.0.1
  78. */
  79. this.isOpen = false;
  80. var container = chart.renderTo;
  81. // Hold event and methods available only for a current browser.
  82. if (!this.browserProps) {
  83. if (typeof container.requestFullscreen === 'function') {
  84. this.browserProps = {
  85. fullscreenChange: 'fullscreenchange',
  86. requestFullscreen: 'requestFullscreen',
  87. exitFullscreen: 'exitFullscreen'
  88. };
  89. }
  90. else if (container.mozRequestFullScreen) {
  91. this.browserProps = {
  92. fullscreenChange: 'mozfullscreenchange',
  93. requestFullscreen: 'mozRequestFullScreen',
  94. exitFullscreen: 'mozCancelFullScreen'
  95. };
  96. }
  97. else if (container.webkitRequestFullScreen) {
  98. this.browserProps = {
  99. fullscreenChange: 'webkitfullscreenchange',
  100. requestFullscreen: 'webkitRequestFullScreen',
  101. exitFullscreen: 'webkitExitFullscreen'
  102. };
  103. }
  104. else if (container.msRequestFullscreen) {
  105. this.browserProps = {
  106. fullscreenChange: 'MSFullscreenChange',
  107. requestFullscreen: 'msRequestFullscreen',
  108. exitFullscreen: 'msExitFullscreen'
  109. };
  110. }
  111. }
  112. }
  113. /* *
  114. *
  115. * Functions
  116. *
  117. * */
  118. /**
  119. * Stops displaying the chart in fullscreen mode.
  120. * Exporting module required.
  121. *
  122. * @since 8.0.1
  123. *
  124. * @function Highcharts.Fullscreen#close
  125. * @return {void}
  126. * @requires modules/full-screen
  127. */
  128. Fullscreen.prototype.close = function () {
  129. var fullscreen = this,
  130. chart = fullscreen.chart;
  131. // Don't fire exitFullscreen() when user exited using 'Escape' button.
  132. if (fullscreen.isOpen &&
  133. fullscreen.browserProps &&
  134. chart.container.ownerDocument instanceof Document) {
  135. chart.container.ownerDocument[fullscreen.browserProps.exitFullscreen]();
  136. }
  137. // Unbind event as it's necessary only before exiting from fullscreen.
  138. if (fullscreen.unbindFullscreenEvent) {
  139. fullscreen.unbindFullscreenEvent();
  140. }
  141. fullscreen.isOpen = false;
  142. fullscreen.setButtonText();
  143. };
  144. /**
  145. * Displays the chart in fullscreen mode.
  146. * When fired customly by user before exporting context button is created,
  147. * button's text will not be replaced - it's on the user side.
  148. * Exporting module required.
  149. *
  150. * @since 8.0.1
  151. *
  152. * @function Highcharts.Fullscreen#open
  153. * @return {void}
  154. * @requires modules/full-screen
  155. */
  156. Fullscreen.prototype.open = function () {
  157. var fullscreen = this,
  158. chart = fullscreen.chart;
  159. // Handle exitFullscreen() method when user clicks 'Escape' button.
  160. if (fullscreen.browserProps) {
  161. fullscreen.unbindFullscreenEvent = addEvent(chart.container.ownerDocument, // chart's document
  162. fullscreen.browserProps.fullscreenChange, function () {
  163. // Handle lack of async of browser's fullScreenChange event.
  164. if (fullscreen.isOpen) {
  165. fullscreen.isOpen = false;
  166. fullscreen.close();
  167. }
  168. else {
  169. fullscreen.isOpen = true;
  170. fullscreen.setButtonText();
  171. }
  172. });
  173. var promise = chart.renderTo[fullscreen.browserProps.requestFullscreen]();
  174. if (promise) {
  175. // No dot notation because of IE8 compatibility
  176. promise['catch'](function () {
  177. alert(// eslint-disable-line no-alert
  178. 'Full screen is not supported inside a frame.');
  179. });
  180. }
  181. addEvent(chart, 'destroy', fullscreen.unbindFullscreenEvent);
  182. }
  183. };
  184. /**
  185. * Replaces the exporting context button's text when toogling the
  186. * fullscreen mode.
  187. *
  188. * @private
  189. *
  190. * @since 8.0.1
  191. *
  192. * @requires modules/full-screen
  193. * @return {void}
  194. */
  195. Fullscreen.prototype.setButtonText = function () {
  196. var _a;
  197. var chart = this.chart,
  198. exportDivElements = chart.exportDivElements,
  199. exportingOptions = chart.options.exporting,
  200. menuItems = (_a = exportingOptions === null || exportingOptions === void 0 ? void 0 : exportingOptions.buttons) === null || _a === void 0 ? void 0 : _a.contextButton.menuItems,
  201. lang = chart.options.lang;
  202. if ((exportingOptions === null || exportingOptions === void 0 ? void 0 : exportingOptions.menuItemDefinitions) && (lang === null || lang === void 0 ? void 0 : lang.exitFullscreen) &&
  203. lang.viewFullscreen &&
  204. menuItems &&
  205. exportDivElements &&
  206. exportDivElements.length) {
  207. exportDivElements[menuItems.indexOf('viewFullscreen')]
  208. .innerHTML = !this.isOpen ?
  209. (exportingOptions.menuItemDefinitions.viewFullscreen.text ||
  210. lang.viewFullscreen) : lang.exitFullscreen;
  211. }
  212. };
  213. /**
  214. * Toggles displaying the chart in fullscreen mode.
  215. * By default, when the exporting module is enabled, a context button with
  216. * a drop down menu in the upper right corner accesses this function.
  217. * Exporting module required.
  218. *
  219. * @since 8.0.1
  220. *
  221. * @sample highcharts/members/chart-togglefullscreen/
  222. * Toggle fullscreen mode from a HTML button
  223. *
  224. * @function Highcharts.Fullscreen#toggle
  225. * @requires modules/full-screen
  226. */
  227. Fullscreen.prototype.toggle = function () {
  228. var fullscreen = this;
  229. if (!fullscreen.isOpen) {
  230. fullscreen.open();
  231. }
  232. else {
  233. fullscreen.close();
  234. }
  235. };
  236. return Fullscreen;
  237. }());
  238. H.Fullscreen = Fullscreen;
  239. // Initialize fullscreen
  240. addEvent(Chart, 'beforeRender', function () {
  241. /**
  242. * @name Highcharts.Chart#fullscreen
  243. * @type {Highcharts.Fullscreen}
  244. * @requires modules/full-screen
  245. */
  246. this.fullscreen = new H.Fullscreen(this);
  247. });
  248. return H.Fullscreen;
  249. });
  250. _registerModule(_modules, 'masters/modules/full-screen.src.js', [], function () {
  251. });
  252. }));