full-screen.src.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /**
  2. * @license Highstock JS v8.1.2 (2020-06-16)
  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, 'modules/full-screen.src.js', [_modules['parts/Chart.js'], _modules['parts/Globals.js'], _modules['parts/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. * @class
  52. * @name Highcharts.Fullscreen
  53. * @hideconstructor
  54. * @requires modules/full-screen
  55. */
  56. var Fullscreen = /** @class */ (function () {
  57. /* *
  58. *
  59. * Constructors
  60. *
  61. * */
  62. function Fullscreen(chart) {
  63. /**
  64. * Chart managed by the fullscreen controller.
  65. * @name Highcharts.Fullscreen#chart
  66. * @type {Highcharts.Chart}
  67. */
  68. this.chart = chart;
  69. /**
  70. * The flag is set to `true` when the chart is displayed in
  71. * the fullscreen mode.
  72. *
  73. * @name Highcharts.Fullscreen#isOpen
  74. * @type {boolean|undefined}
  75. * @since 8.0.1
  76. */
  77. this.isOpen = false;
  78. var container = chart.renderTo;
  79. // Hold event and methods available only for a current browser.
  80. if (!this.browserProps) {
  81. if (typeof container.requestFullscreen === 'function') {
  82. this.browserProps = {
  83. fullscreenChange: 'fullscreenchange',
  84. requestFullscreen: 'requestFullscreen',
  85. exitFullscreen: 'exitFullscreen'
  86. };
  87. }
  88. else if (container.mozRequestFullScreen) {
  89. this.browserProps = {
  90. fullscreenChange: 'mozfullscreenchange',
  91. requestFullscreen: 'mozRequestFullScreen',
  92. exitFullscreen: 'mozCancelFullScreen'
  93. };
  94. }
  95. else if (container.webkitRequestFullScreen) {
  96. this.browserProps = {
  97. fullscreenChange: 'webkitfullscreenchange',
  98. requestFullscreen: 'webkitRequestFullScreen',
  99. exitFullscreen: 'webkitExitFullscreen'
  100. };
  101. }
  102. else if (container.msRequestFullscreen) {
  103. this.browserProps = {
  104. fullscreenChange: 'MSFullscreenChange',
  105. requestFullscreen: 'msRequestFullscreen',
  106. exitFullscreen: 'msExitFullscreen'
  107. };
  108. }
  109. }
  110. }
  111. /* *
  112. *
  113. * Functions
  114. *
  115. * */
  116. /**
  117. * Stops displaying the chart in fullscreen mode.
  118. * Exporting module required.
  119. *
  120. * @since 8.0.1
  121. *
  122. * @function Highcharts.Fullscreen#close
  123. * @return {void}
  124. * @requires modules/full-screen
  125. */
  126. Fullscreen.prototype.close = function () {
  127. var fullscreen = this, chart = fullscreen.chart;
  128. // Don't fire exitFullscreen() when user exited using 'Escape' button.
  129. if (fullscreen.isOpen &&
  130. fullscreen.browserProps &&
  131. chart.container.ownerDocument instanceof Document) {
  132. chart.container.ownerDocument[fullscreen.browserProps.exitFullscreen]();
  133. }
  134. // Unbind event as it's necessary only before exiting from fullscreen.
  135. if (fullscreen.unbindFullscreenEvent) {
  136. fullscreen.unbindFullscreenEvent();
  137. }
  138. fullscreen.isOpen = false;
  139. fullscreen.setButtonText();
  140. };
  141. /**
  142. * Displays the chart in fullscreen mode.
  143. * When fired customly by user before exporting context button is created,
  144. * button's text will not be replaced - it's on the user side.
  145. * Exporting module required.
  146. *
  147. * @since 8.0.1
  148. *
  149. * @function Highcharts.Fullscreen#open
  150. * @return {void}
  151. * @requires modules/full-screen
  152. */
  153. Fullscreen.prototype.open = function () {
  154. var fullscreen = this, chart = fullscreen.chart;
  155. // Handle exitFullscreen() method when user clicks 'Escape' button.
  156. if (fullscreen.browserProps) {
  157. fullscreen.unbindFullscreenEvent = addEvent(chart.container.ownerDocument, // chart's document
  158. fullscreen.browserProps.fullscreenChange, function () {
  159. // Handle lack of async of browser's fullScreenChange event.
  160. if (fullscreen.isOpen) {
  161. fullscreen.isOpen = false;
  162. fullscreen.close();
  163. }
  164. else {
  165. fullscreen.isOpen = true;
  166. fullscreen.setButtonText();
  167. }
  168. });
  169. var promise = chart.renderTo[fullscreen.browserProps.requestFullscreen]();
  170. if (promise) {
  171. // No dot notation because of IE8 compatibility
  172. promise['catch'](function () {
  173. alert(// eslint-disable-line no-alert
  174. 'Full screen is not supported inside a frame.');
  175. });
  176. }
  177. addEvent(chart, 'destroy', fullscreen.unbindFullscreenEvent);
  178. }
  179. };
  180. /**
  181. * Replaces the exporting context button's text when toogling the
  182. * fullscreen mode.
  183. *
  184. * @private
  185. *
  186. * @since 8.0.1
  187. *
  188. * @requires modules/full-screen
  189. * @return {void}
  190. */
  191. Fullscreen.prototype.setButtonText = function () {
  192. var _a;
  193. var chart = this.chart, exportDivElements = chart.exportDivElements, exportingOptions = chart.options.exporting, menuItems = (_a = exportingOptions === null || exportingOptions === void 0 ? void 0 : exportingOptions.buttons) === null || _a === void 0 ? void 0 : _a.contextButton.menuItems, lang = chart.options.lang;
  194. if ((exportingOptions === null || exportingOptions === void 0 ? void 0 : exportingOptions.menuItemDefinitions) && (lang === null || lang === void 0 ? void 0 : lang.exitFullscreen) &&
  195. lang.viewFullscreen &&
  196. menuItems &&
  197. exportDivElements &&
  198. exportDivElements.length) {
  199. exportDivElements[menuItems.indexOf('viewFullscreen')]
  200. .innerHTML = !this.isOpen ?
  201. (exportingOptions.menuItemDefinitions.viewFullscreen.text ||
  202. lang.viewFullscreen) : lang.exitFullscreen;
  203. }
  204. };
  205. /**
  206. * Toggles displaying the chart in fullscreen mode.
  207. * By default, when the exporting module is enabled, a context button with
  208. * a drop down menu in the upper right corner accesses this function.
  209. * Exporting module required.
  210. *
  211. * @since 8.0.1
  212. *
  213. * @sample highcharts/members/chart-togglefullscreen/
  214. * Toggle fullscreen mode from a HTML button
  215. *
  216. * @function Highcharts.Fullscreen#toggle
  217. * @requires modules/full-screen
  218. */
  219. Fullscreen.prototype.toggle = function () {
  220. var fullscreen = this;
  221. if (!fullscreen.isOpen) {
  222. fullscreen.open();
  223. }
  224. else {
  225. fullscreen.close();
  226. }
  227. };
  228. return Fullscreen;
  229. }());
  230. H.Fullscreen = Fullscreen;
  231. // Initialize fullscreen
  232. addEvent(Chart, 'beforeRender', function () {
  233. /**
  234. * @name Highcharts.Chart#fullscreen
  235. * @type {Highcharts.Fullscreen}
  236. * @requires modules/full-screen
  237. */
  238. this.fullscreen = new H.Fullscreen(this);
  239. });
  240. return H.Fullscreen;
  241. });
  242. _registerModule(_modules, 'masters/modules/full-screen.src.js', [], function () {
  243. });
  244. }));