summaryrefslogtreecommitdiff
path: root/javascript/videojs/src/js/control-bar/text-track-controls/captions-button.js
diff options
context:
space:
mode:
Diffstat (limited to 'javascript/videojs/src/js/control-bar/text-track-controls/captions-button.js')
-rw-r--r--javascript/videojs/src/js/control-bar/text-track-controls/captions-button.js87
1 files changed, 87 insertions, 0 deletions
diff --git a/javascript/videojs/src/js/control-bar/text-track-controls/captions-button.js b/javascript/videojs/src/js/control-bar/text-track-controls/captions-button.js
new file mode 100644
index 0000000..8f5f6da
--- /dev/null
+++ b/javascript/videojs/src/js/control-bar/text-track-controls/captions-button.js
@@ -0,0 +1,87 @@
+/**
+ * @file captions-button.js
+ */
+import TextTrackButton from './text-track-button.js';
+import Component from '../../component.js';
+import CaptionSettingsMenuItem from './caption-settings-menu-item.js';
+
+/** @import Player from '../../player' */
+
+/**
+ * The button component for toggling and selecting captions
+ *
+ * @extends TextTrackButton
+ */
+class CaptionsButton extends TextTrackButton {
+
+ /**
+ * Creates an instance of this class.
+ *
+ * @param {Player} player
+ * The `Player` that this class should be attached to.
+ *
+ * @param {Object} [options]
+ * The key/value store of player options.
+ *
+ * @param {Function} [ready]
+ * The function to call when this component is ready.
+ */
+ constructor(player, options, ready) {
+ super(player, options, ready);
+
+ this.setIcon('captions');
+ }
+
+ /**
+ * Builds the default DOM `className`.
+ *
+ * @return {string}
+ * The DOM `className` for this object.
+ */
+ buildCSSClass() {
+ return `vjs-captions-button ${super.buildCSSClass()}`;
+ }
+
+ buildWrapperCSSClass() {
+ return `vjs-captions-button ${super.buildWrapperCSSClass()}`;
+ }
+
+ /**
+ * Create caption menu items
+ *
+ * @return {CaptionSettingsMenuItem[]}
+ * The array of current menu items.
+ */
+ createItems() {
+ const items = [];
+
+ if (!(this.player().tech_ && this.player().tech_.featuresNativeTextTracks) &&
+ this.player().getChild('textTrackSettings')) {
+ items.push(new CaptionSettingsMenuItem(this.player_, {kind: this.kind_}));
+
+ this.hideThreshold_ += 1;
+ }
+
+ return super.createItems(items);
+ }
+
+}
+
+/**
+ * `kind` of TextTrack to look for to associate it with this menu.
+ *
+ * @type {string}
+ * @private
+ */
+CaptionsButton.prototype.kind_ = 'captions';
+
+/**
+ * The text that should display over the `CaptionsButton`s controls. Added for localization.
+ *
+ * @type {string}
+ * @protected
+ */
+CaptionsButton.prototype.controlText_ = 'Captions';
+
+Component.registerComponent('CaptionsButton', CaptionsButton);
+export default CaptionsButton;