descriptions-button.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _textTrackButton = require('./text-track-button.js');
  4. var _textTrackButton2 = _interopRequireDefault(_textTrackButton);
  5. var _component = require('../../component.js');
  6. var _component2 = _interopRequireDefault(_component);
  7. var _fn = require('../../utils/fn.js');
  8. var Fn = _interopRequireWildcard(_fn);
  9. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  11. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  12. 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; }
  13. 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; } /**
  14. * @file descriptions-button.js
  15. */
  16. /**
  17. * The button component for toggling and selecting descriptions
  18. *
  19. * @extends TextTrackButton
  20. */
  21. var DescriptionsButton = function (_TextTrackButton) {
  22. _inherits(DescriptionsButton, _TextTrackButton);
  23. /**
  24. * Creates an instance of this class.
  25. *
  26. * @param {Player} player
  27. * The `Player` that this class should be attached to.
  28. *
  29. * @param {Object} [options]
  30. * The key/value store of player options.
  31. *
  32. * @param {Component~ReadyCallback} [ready]
  33. * The function to call when this component is ready.
  34. */
  35. function DescriptionsButton(player, options, ready) {
  36. _classCallCheck(this, DescriptionsButton);
  37. var _this = _possibleConstructorReturn(this, _TextTrackButton.call(this, player, options, ready));
  38. _this.el_.setAttribute('aria-label', 'Descriptions Menu');
  39. var tracks = player.textTracks();
  40. if (tracks) {
  41. var changeHandler = Fn.bind(_this, _this.handleTracksChange);
  42. tracks.addEventListener('change', changeHandler);
  43. _this.on('dispose', function () {
  44. tracks.removeEventListener('change', changeHandler);
  45. });
  46. }
  47. return _this;
  48. }
  49. /**
  50. * Handle text track change
  51. *
  52. * @param {EventTarget~Event} event
  53. * The event that caused this function to run
  54. *
  55. * @listens TextTrackList#change
  56. */
  57. DescriptionsButton.prototype.handleTracksChange = function handleTracksChange(event) {
  58. var tracks = this.player().textTracks();
  59. var disabled = false;
  60. // Check whether a track of a different kind is showing
  61. for (var i = 0, l = tracks.length; i < l; i++) {
  62. var track = tracks[i];
  63. if (track.kind !== this.kind_ && track.mode === 'showing') {
  64. disabled = true;
  65. break;
  66. }
  67. }
  68. // If another track is showing, disable this menu button
  69. if (disabled) {
  70. this.disable();
  71. } else {
  72. this.enable();
  73. }
  74. };
  75. /**
  76. * Builds the default DOM `className`.
  77. *
  78. * @return {string}
  79. * The DOM `className` for this object.
  80. */
  81. DescriptionsButton.prototype.buildCSSClass = function buildCSSClass() {
  82. return 'vjs-descriptions-button ' + _TextTrackButton.prototype.buildCSSClass.call(this);
  83. };
  84. return DescriptionsButton;
  85. }(_textTrackButton2['default']);
  86. /**
  87. * `kind` of TextTrack to look for to associate it with this menu.
  88. *
  89. * @type {string}
  90. * @private
  91. */
  92. DescriptionsButton.prototype.kind_ = 'descriptions';
  93. /**
  94. * The text that should display over the `DescriptionsButton`s controls. Added for localization.
  95. *
  96. * @type {string}
  97. * @private
  98. */
  99. DescriptionsButton.prototype.controlText_ = 'Descriptions';
  100. _component2['default'].registerComponent('DescriptionsButton', DescriptionsButton);
  101. exports['default'] = DescriptionsButton;