full-screen.src.js 11 KB

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