fullscreen-toggle.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _button = require('../button.js');
  4. var _button2 = _interopRequireDefault(_button);
  5. var _component = require('../component.js');
  6. var _component2 = _interopRequireDefault(_component);
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  8. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  10. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
  11. * @file fullscreen-toggle.js
  12. */
  13. /**
  14. * Toggle fullscreen video
  15. *
  16. * @extends Button
  17. */
  18. var FullscreenToggle = function (_Button) {
  19. _inherits(FullscreenToggle, _Button);
  20. /**
  21. * Creates an instance of this class.
  22. *
  23. * @param {Player} player
  24. * The `Player` that this class should be attached to.
  25. *
  26. * @param {Object} [options]
  27. * The key/value store of player options.
  28. */
  29. function FullscreenToggle(player, options) {
  30. _classCallCheck(this, FullscreenToggle);
  31. var _this = _possibleConstructorReturn(this, _Button.call(this, player, options));
  32. _this.on(player, 'fullscreenchange', _this.handleFullscreenChange);
  33. return _this;
  34. }
  35. /**
  36. * Builds the default DOM `className`.
  37. *
  38. * @return {string}
  39. * The DOM `className` for this object.
  40. */
  41. FullscreenToggle.prototype.buildCSSClass = function buildCSSClass() {
  42. return 'vjs-fullscreen-control ' + _Button.prototype.buildCSSClass.call(this);
  43. };
  44. /**
  45. * Handles fullscreenchange on the player and change control text accordingly.
  46. *
  47. * @param {EventTarget~Event} [event]
  48. * The {@link Player#fullscreenchange} event that caused this function to be
  49. * called.
  50. *
  51. * @listens Player#fullscreenchange
  52. */
  53. FullscreenToggle.prototype.handleFullscreenChange = function handleFullscreenChange(event) {
  54. if (this.player_.isFullscreen()) {
  55. this.controlText('Non-Fullscreen');
  56. } else {
  57. this.controlText('Fullscreen');
  58. }
  59. };
  60. /**
  61. * This gets called when an `FullscreenToggle` is "clicked". See
  62. * {@link ClickableComponent} for more detailed information on what a click can be.
  63. *
  64. * @param {EventTarget~Event} [event]
  65. * The `keydown`, `tap`, or `click` event that caused this function to be
  66. * called.
  67. *
  68. * @listens tap
  69. * @listens click
  70. */
  71. FullscreenToggle.prototype.handleClick = function handleClick(event) {
  72. if (!this.player_.isFullscreen()) {
  73. this.player_.requestFullscreen();
  74. } else {
  75. this.player_.exitFullscreen();
  76. }
  77. };
  78. return FullscreenToggle;
  79. }(_button2['default']);
  80. /**
  81. * The text that should display over the `FullscreenToggle`s controls. Added for localization.
  82. *
  83. * @type {string}
  84. * @private
  85. */
  86. FullscreenToggle.prototype.controlText_ = 'Fullscreen';
  87. _component2['default'].registerComponent('FullscreenToggle', FullscreenToggle);
  88. exports['default'] = FullscreenToggle;