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