-
Notifications
You must be signed in to change notification settings - Fork 7.5k
/
subs-caps-button.js
82 lines (70 loc) · 2.11 KB
/
subs-caps-button.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* @file sub-caps-button.js
*/
import TextTrackButton from './text-track-button.js';
import Component from '../../component.js';
import CaptionSettingsMenuItem from './caption-settings-menu-item.js';
import SubsCapsMenuItem from './subs-caps-menu-item.js';
import {toTitleCase} from '../../utils/string-cases.js';
/**
* The button component for toggling and selecting captions and/or subtitles
*
* @extends TextTrackButton
*/
class SubsCapsButton extends TextTrackButton {
constructor(player, options = {}) {
super(player, options);
// Although North America uses "captions" in most cases for
// "captions and subtitles" other locales use "subtitles"
this.label_ = 'subtitles';
if (['en', 'en-us', 'en-ca', 'fr-ca'].indexOf(this.player_.language_) > -1) {
this.label_ = 'captions';
}
this.menuButton_.controlText(toTitleCase(this.label_));
}
/**
* Builds the default DOM `className`.
*
* @return {string}
* The DOM `className` for this object.
*/
buildCSSClass() {
return `vjs-subs-caps-button ${super.buildCSSClass()}`;
}
buildWrapperCSSClass() {
return `vjs-subs-caps-button ${super.buildWrapperCSSClass()}`;
}
/**
* Create caption/subtitles menu items
*
* @return {CaptionSettingsMenuItem[]}
* The array of current menu items.
*/
createItems() {
let items = [];
if (!(this.player().tech_ && this.player().tech_.featuresNativeTextTracks) &&
this.player().getChild('textTrackSettings')) {
items.push(new CaptionSettingsMenuItem(this.player_, {kind: this.label_}));
this.hideThreshold_ += 1;
}
items = super.createItems(items, SubsCapsMenuItem);
return items;
}
}
/**
* `kind`s of TextTrack to look for to associate it with this menu.
*
* @type {array}
* @private
*/
SubsCapsButton.prototype.kinds_ = ['captions', 'subtitles'];
/**
* The text that should display over the `SubsCapsButton`s controls.
*
*
* @type {string}
* @private
*/
SubsCapsButton.prototype.controlText_ = 'Subtitles';
Component.registerComponent('SubsCapsButton', SubsCapsButton);
export default SubsCapsButton;