1. 1 : /**
  2. 2 : * @file captions-button.js
  3. 3 : */
  4. 4 : import TextTrackButton from './text-track-button.js';
  5. 5 : import Component from '../../component.js';
  6. 6 : import CaptionSettingsMenuItem from './caption-settings-menu-item.js';
  7. 7 :
  8. 8 : /**
  9. 9 : * The button component for toggling and selecting captions
  10. 10 : *
  11. 11 : * @extends TextTrackButton
  12. 12 : */
  13. 13 : class CaptionsButton extends TextTrackButton {
  14. 14 :
  15. 15 : /**
  16. 16 : * Creates an instance of this class.
  17. 17 : *
  18. 18 : * @param {Player} player
  19. 19 : * The `Player` that this class should be attached to.
  20. 20 : *
  21. 21 : * @param {Object} [options]
  22. 22 : * The key/value store of player options.
  23. 23 : *
  24. 24 : * @param {Component~ReadyCallback} [ready]
  25. 25 : * The function to call when this component is ready.
  26. 26 : */
  27. 27 : constructor(player, options, ready) {
  28. 28 : super(player, options, ready);
  29. 29 : }
  30. 30 :
  31. 31 : /**
  32. 32 : * Builds the default DOM `className`.
  33. 33 : *
  34. 34 : * @return {string}
  35. 35 : * The DOM `className` for this object.
  36. 36 : */
  37. 37 : buildCSSClass() {
  38. 38 : return `vjs-captions-button ${super.buildCSSClass()}`;
  39. 39 : }
  40. 40 :
  41. 41 : buildWrapperCSSClass() {
  42. 42 : return `vjs-captions-button ${super.buildWrapperCSSClass()}`;
  43. 43 : }
  44. 44 :
  45. 45 : /**
  46. 46 : * Create caption menu items
  47. 47 : *
  48. 48 : * @return {CaptionSettingsMenuItem[]}
  49. 49 : * The array of current menu items.
  50. 50 : */
  51. 51 : createItems() {
  52. 52 : const items = [];
  53. 53 :
  54. 54 : if (!(this.player().tech_ && this.player().tech_.featuresNativeTextTracks) &&
  55. 55 : this.player().getChild('textTrackSettings')) {
  56. 56 : items.push(new CaptionSettingsMenuItem(this.player_, {kind: this.kind_}));
  57. 57 :
  58. 58 : this.hideThreshold_ += 1;
  59. 59 : }
  60. 60 :
  61. 61 : return super.createItems(items);
  62. 62 : }
  63. 63 :
  64. 64 : }
  65. 65 :
  66. 66 : /**
  67. 67 : * `kind` of TextTrack to look for to associate it with this menu.
  68. 68 : *
  69. 69 : * @type {string}
  70. 70 : * @private
  71. 71 : */
  72. 72 : CaptionsButton.prototype.kind_ = 'captions';
  73. 73 :
  74. 74 : /**
  75. 75 : * The text that should display over the `CaptionsButton`s controls. Added for localization.
  76. 76 : *
  77. 77 : * @type {string}
  78. 78 : * @private
  79. 79 : */
  80. 80 : CaptionsButton.prototype.controlText_ = 'Captions';
  81. 81 :
  82. 82 : Component.registerComponent('CaptionsButton', CaptionsButton);
  83. 83 : export default CaptionsButton;