full-screen.src.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /**
  2. * @license Highstock JS v9.1.1 (2021-06-04)
  3. *
  4. * Advanced Highcharts Stock 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 = fullscreen.unbindFullscreenEvent();
  142. }
  143. chart.setSize(fullscreen.origWidth, fullscreen.origHeight, false);
  144. fullscreen.origWidth = void 0;
  145. fullscreen.origHeight = void 0;
  146. optionsChart.width = fullscreen.origWidthOption;
  147. optionsChart.height = fullscreen.origHeightOption;
  148. fullscreen.origWidthOption = void 0;
  149. fullscreen.origHeightOption = void 0;
  150. fullscreen.isOpen = false;
  151. fullscreen.setButtonText();
  152. };
  153. /**
  154. * Displays the chart in fullscreen mode.
  155. * When fired customly by user before exporting context button is created,
  156. * button's text will not be replaced - it's on the user side.
  157. * Exporting module required.
  158. *
  159. * @since 8.0.1
  160. *
  161. * @function Highcharts.Fullscreen#open
  162. * @return {void}
  163. * @requires modules/full-screen
  164. */
  165. Fullscreen.prototype.open = function () {
  166. var fullscreen = this,
  167. chart = fullscreen.chart,
  168. optionsChart = chart.options.chart;
  169. if (optionsChart) {
  170. fullscreen.origWidthOption = optionsChart.width;
  171. fullscreen.origHeightOption = optionsChart.height;
  172. }
  173. fullscreen.origWidth = chart.chartWidth;
  174. fullscreen.origHeight = chart.chartHeight;
  175. // Handle exitFullscreen() method when user clicks 'Escape' button.
  176. if (fullscreen.browserProps) {
  177. var unbindChange_1 = addEvent(chart.container.ownerDocument, // chart's document
  178. fullscreen.browserProps.fullscreenChange,
  179. function () {
  180. // Handle lack of async of browser's fullScreenChange event.
  181. if (fullscreen.isOpen) {
  182. fullscreen.isOpen = false;
  183. fullscreen.close();
  184. }
  185. else {
  186. chart.setSize(null, null, false);
  187. fullscreen.isOpen = true;
  188. fullscreen.setButtonText();
  189. }
  190. });
  191. var unbindDestroy_1 = addEvent(chart, 'destroy',
  192. unbindChange_1);
  193. fullscreen.unbindFullscreenEvent = function () {
  194. unbindChange_1();
  195. unbindDestroy_1();
  196. };
  197. var promise = chart.renderTo[fullscreen.browserProps.requestFullscreen]();
  198. if (promise) {
  199. // No dot notation because of IE8 compatibility
  200. promise['catch'](function () {
  201. alert(// eslint-disable-line no-alert
  202. 'Full screen is not supported inside a frame.');
  203. });
  204. }
  205. }
  206. };
  207. /**
  208. * Replaces the exporting context button's text when toogling the
  209. * fullscreen mode.
  210. *
  211. * @private
  212. *
  213. * @since 8.0.1
  214. *
  215. * @requires modules/full-screen
  216. * @return {void}
  217. */
  218. Fullscreen.prototype.setButtonText = function () {
  219. var chart = this.chart,
  220. exportDivElements = chart.exportDivElements,
  221. exportingOptions = chart.options.exporting,
  222. menuItems = (exportingOptions &&
  223. exportingOptions.buttons &&
  224. exportingOptions.buttons.contextButton.menuItems),
  225. lang = chart.options.lang;
  226. if (exportingOptions &&
  227. exportingOptions.menuItemDefinitions &&
  228. lang &&
  229. lang.exitFullscreen &&
  230. lang.viewFullscreen &&
  231. menuItems &&
  232. exportDivElements &&
  233. exportDivElements.length) {
  234. AST.setElementHTML(exportDivElements[menuItems.indexOf('viewFullscreen')], !this.isOpen ?
  235. (exportingOptions.menuItemDefinitions.viewFullscreen.text ||
  236. lang.viewFullscreen) : lang.exitFullscreen);
  237. }
  238. };
  239. /**
  240. * Toggles displaying the chart in fullscreen mode.
  241. * By default, when the exporting module is enabled, a context button with
  242. * a drop down menu in the upper right corner accesses this function.
  243. * Exporting module required.
  244. *
  245. * @since 8.0.1
  246. *
  247. * @sample highcharts/members/chart-togglefullscreen/
  248. * Toggle fullscreen mode from a HTML button
  249. *
  250. * @function Highcharts.Fullscreen#toggle
  251. * @requires modules/full-screen
  252. */
  253. Fullscreen.prototype.toggle = function () {
  254. var fullscreen = this;
  255. if (!fullscreen.isOpen) {
  256. fullscreen.open();
  257. }
  258. else {
  259. fullscreen.close();
  260. }
  261. };
  262. return Fullscreen;
  263. }());
  264. H.Fullscreen = Fullscreen;
  265. // Initialize fullscreen
  266. addEvent(Chart, 'beforeRender', function () {
  267. /**
  268. * @name Highcharts.Chart#fullscreen
  269. * @type {Highcharts.Fullscreen}
  270. * @requires modules/full-screen
  271. */
  272. this.fullscreen = new H.Fullscreen(this);
  273. });
  274. return H.Fullscreen;
  275. });
  276. _registerModule(_modules, 'masters/modules/full-screen.src.js', [], function () {
  277. });
  278. }));