3 exports.__esModule = true;
5 var _textTrackButton = require('./text-track-button.js');
7 var _textTrackButton2 = _interopRequireDefault(_textTrackButton);
9 var _component = require('../../component.js');
11 var _component2 = _interopRequireDefault(_component);
13 var _chaptersTrackMenuItem = require('./chapters-track-menu-item.js');
15 var _chaptersTrackMenuItem2 = _interopRequireDefault(_chaptersTrackMenuItem);
17 var _toTitleCase = require('../../utils/to-title-case.js');
19 var _toTitleCase2 = _interopRequireDefault(_toTitleCase);
21 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
23 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
25 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; }
27 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; } /**
28 * @file chapters-button.js
33 * The button component for toggling and selecting chapters
34 * Chapters act much differently than other text tracks
35 * Cues are navigation vs. other tracks of alternative languages
37 * @extends TextTrackButton
39 var ChaptersButton = function (_TextTrackButton) {
40 _inherits(ChaptersButton, _TextTrackButton);
43 * Creates an instance of this class.
45 * @param {Player} player
46 * The `Player` that this class should be attached to.
48 * @param {Object} [options]
49 * The key/value store of player options.
51 * @param {Component~ReadyCallback} [ready]
52 * The function to call when this function is ready.
54 function ChaptersButton(player, options, ready) {
55 _classCallCheck(this, ChaptersButton);
57 var _this = _possibleConstructorReturn(this, _TextTrackButton.call(this, player, options, ready));
59 _this.el_.setAttribute('aria-label', 'Chapters Menu');
64 * Builds the default DOM `className`.
67 * The DOM `className` for this object.
71 ChaptersButton.prototype.buildCSSClass = function buildCSSClass() {
72 return 'vjs-chapters-button ' + _TextTrackButton.prototype.buildCSSClass.call(this);
76 * Update the menu based on the current state of its items.
78 * @param {EventTarget~Event} [event]
79 * An event that triggered this function to run.
81 * @listens TextTrackList#addtrack
82 * @listens TextTrackList#removetrack
83 * @listens TextTrackList#change
87 ChaptersButton.prototype.update = function update(event) {
88 if (!this.track_ || event && (event.type === 'addtrack' || event.type === 'removetrack')) {
89 this.setTrack(this.findChaptersTrack());
91 _TextTrackButton.prototype.update.call(this);
95 * Set the currently selected track for the chapters button.
97 * @param {TextTrack} track
98 * The new track to select. Nothing will change if this is the currently selected
103 ChaptersButton.prototype.setTrack = function setTrack(track) {
104 if (this.track_ === track) {
108 if (!this.updateHandler_) {
109 this.updateHandler_ = this.update.bind(this);
112 // here this.track_ refers to the old track instance
114 var remoteTextTrackEl = this.player_.remoteTextTrackEls().getTrackElementByTrack_(this.track_);
116 if (remoteTextTrackEl) {
117 remoteTextTrackEl.removeEventListener('load', this.updateHandler_);
125 // here this.track_ refers to the new track instance
127 this.track_.mode = 'hidden';
129 var _remoteTextTrackEl = this.player_.remoteTextTrackEls().getTrackElementByTrack_(this.track_);
131 if (_remoteTextTrackEl) {
132 _remoteTextTrackEl.addEventListener('load', this.updateHandler_);
138 * Find the track object that is currently in use by this ChaptersButton
140 * @return {TextTrack|undefined}
141 * The current track or undefined if none was found.
145 ChaptersButton.prototype.findChaptersTrack = function findChaptersTrack() {
146 var tracks = this.player_.textTracks() || [];
148 for (var i = tracks.length - 1; i >= 0; i--) {
149 // We will always choose the last track as our chaptersTrack
150 var track = tracks[i];
152 if (track.kind === this.kind_) {
159 * Get the caption for the ChaptersButton based on the track label. This will also
160 * use the current tracks localized kind as a fallback if a label does not exist.
163 * The tracks current label or the localized track kind.
167 ChaptersButton.prototype.getMenuCaption = function getMenuCaption() {
168 if (this.track_ && this.track_.label) {
169 return this.track_.label;
171 return this.localize((0, _toTitleCase2['default'])(this.kind_));
175 * Create menu from chapter track
178 * New menu for the chapter buttons
182 ChaptersButton.prototype.createMenu = function createMenu() {
183 this.options_.title = this.getMenuCaption();
184 return _TextTrackButton.prototype.createMenu.call(this);
188 * Create a menu item for each text track
190 * @return {TextTrackMenuItem[]}
191 * Array of menu items
195 ChaptersButton.prototype.createItems = function createItems() {
202 var cues = this.track_.cues;
208 for (var i = 0, l = cues.length; i < l; i++) {
210 var mi = new _chaptersTrackMenuItem2['default'](this.player_, { track: this.track_, cue: cue });
218 return ChaptersButton;
219 }(_textTrackButton2['default']);
222 * `kind` of TextTrack to look for to associate it with this menu.
229 ChaptersButton.prototype.kind_ = 'chapters';
232 * The text that should display over the `ChaptersButton`s controls. Added for localization.
237 ChaptersButton.prototype.controlText_ = 'Chapters';
239 _component2['default'].registerComponent('ChaptersButton', ChaptersButton);
240 exports['default'] = ChaptersButton;