Security update for Core, with self-updated composer
[yaffs-website] / node_modules / video.js / es5 / control-bar / playback-rate-menu / playback-rate-menu-button.js
1 'use strict';
2
3 exports.__esModule = true;
4
5 var _menuButton = require('../../menu/menu-button.js');
6
7 var _menuButton2 = _interopRequireDefault(_menuButton);
8
9 var _menu = require('../../menu/menu.js');
10
11 var _menu2 = _interopRequireDefault(_menu);
12
13 var _playbackRateMenuItem = require('./playback-rate-menu-item.js');
14
15 var _playbackRateMenuItem2 = _interopRequireDefault(_playbackRateMenuItem);
16
17 var _component = require('../../component.js');
18
19 var _component2 = _interopRequireDefault(_component);
20
21 var _dom = require('../../utils/dom.js');
22
23 var Dom = _interopRequireWildcard(_dom);
24
25 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; } }
26
27 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
28
29 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
30
31 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; }
32
33 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; } /**
34                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 * @file playback-rate-menu-button.js
35                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 */
36
37
38 /**
39  * The component for controlling the playback rate.
40  *
41  * @extends MenuButton
42  */
43 var PlaybackRateMenuButton = function (_MenuButton) {
44   _inherits(PlaybackRateMenuButton, _MenuButton);
45
46   /**
47    * Creates an instance of this class.
48    *
49    * @param {Player} player
50    *        The `Player` that this class should be attached to.
51    *
52    * @param {Object} [options]
53    *        The key/value store of player options.
54    */
55   function PlaybackRateMenuButton(player, options) {
56     _classCallCheck(this, PlaybackRateMenuButton);
57
58     var _this = _possibleConstructorReturn(this, _MenuButton.call(this, player, options));
59
60     _this.updateVisibility();
61     _this.updateLabel();
62
63     _this.on(player, 'loadstart', _this.updateVisibility);
64     _this.on(player, 'ratechange', _this.updateLabel);
65     return _this;
66   }
67
68   /**
69    * Create the `Component`'s DOM element
70    *
71    * @return {Element}
72    *         The element that was created.
73    */
74
75
76   PlaybackRateMenuButton.prototype.createEl = function createEl() {
77     var el = _MenuButton.prototype.createEl.call(this);
78
79     this.labelEl_ = Dom.createEl('div', {
80       className: 'vjs-playback-rate-value',
81       innerHTML: 1.0
82     });
83
84     el.appendChild(this.labelEl_);
85
86     return el;
87   };
88
89   /**
90    * Builds the default DOM `className`.
91    *
92    * @return {string}
93    *         The DOM `className` for this object.
94    */
95
96
97   PlaybackRateMenuButton.prototype.buildCSSClass = function buildCSSClass() {
98     return 'vjs-playback-rate ' + _MenuButton.prototype.buildCSSClass.call(this);
99   };
100
101   /**
102    * Create the playback rate menu
103    *
104    * @return {Menu}
105    *         Menu object populated with {@link PlaybackRateMenuItem}s
106    */
107
108
109   PlaybackRateMenuButton.prototype.createMenu = function createMenu() {
110     var menu = new _menu2['default'](this.player());
111     var rates = this.playbackRates();
112
113     if (rates) {
114       for (var i = rates.length - 1; i >= 0; i--) {
115         menu.addChild(new _playbackRateMenuItem2['default'](this.player(), { rate: rates[i] + 'x' }));
116       }
117     }
118
119     return menu;
120   };
121
122   /**
123    * Updates ARIA accessibility attributes
124    */
125
126
127   PlaybackRateMenuButton.prototype.updateARIAAttributes = function updateARIAAttributes() {
128     // Current playback rate
129     this.el().setAttribute('aria-valuenow', this.player().playbackRate());
130   };
131
132   /**
133    * This gets called when an `PlaybackRateMenuButton` is "clicked". See
134    * {@link ClickableComponent} for more detailed information on what a click can be.
135    *
136    * @param {EventTarget~Event} [event]
137    *        The `keydown`, `tap`, or `click` event that caused this function to be
138    *        called.
139    *
140    * @listens tap
141    * @listens click
142    */
143
144
145   PlaybackRateMenuButton.prototype.handleClick = function handleClick(event) {
146     // select next rate option
147     var currentRate = this.player().playbackRate();
148     var rates = this.playbackRates();
149
150     // this will select first one if the last one currently selected
151     var newRate = rates[0];
152
153     for (var i = 0; i < rates.length; i++) {
154       if (rates[i] > currentRate) {
155         newRate = rates[i];
156         break;
157       }
158     }
159     this.player().playbackRate(newRate);
160   };
161
162   /**
163    * Get possible playback rates
164    *
165    * @return {Array}
166    *         All possible playback rates
167    */
168
169
170   PlaybackRateMenuButton.prototype.playbackRates = function playbackRates() {
171     return this.options_.playbackRates || this.options_.playerOptions && this.options_.playerOptions.playbackRates;
172   };
173
174   /**
175    * Get whether playback rates is supported by the tech
176    * and an array of playback rates exists
177    *
178    * @return {boolean}
179    *         Whether changing playback rate is supported
180    */
181
182
183   PlaybackRateMenuButton.prototype.playbackRateSupported = function playbackRateSupported() {
184     return this.player().tech_ && this.player().tech_.featuresPlaybackRate && this.playbackRates() && this.playbackRates().length > 0;
185   };
186
187   /**
188    * Hide playback rate controls when they're no playback rate options to select
189    *
190    * @param {EventTarget~Event} [event]
191    *        The event that caused this function to run.
192    *
193    * @listens Player#loadstart
194    */
195
196
197   PlaybackRateMenuButton.prototype.updateVisibility = function updateVisibility(event) {
198     if (this.playbackRateSupported()) {
199       this.removeClass('vjs-hidden');
200     } else {
201       this.addClass('vjs-hidden');
202     }
203   };
204
205   /**
206    * Update button label when rate changed
207    *
208    * @param {EventTarget~Event} [event]
209    *        The event that caused this function to run.
210    *
211    * @listens Player#ratechange
212    */
213
214
215   PlaybackRateMenuButton.prototype.updateLabel = function updateLabel(event) {
216     if (this.playbackRateSupported()) {
217       this.labelEl_.innerHTML = this.player().playbackRate() + 'x';
218     }
219   };
220
221   return PlaybackRateMenuButton;
222 }(_menuButton2['default']);
223
224 /**
225  * The text that should display over the `FullscreenToggle`s controls. Added for localization.
226  *
227  * @type {string}
228  * @private
229  */
230
231
232 PlaybackRateMenuButton.prototype.controlText_ = 'Playback Rate';
233
234 _component2['default'].registerComponent('PlaybackRateMenuButton', PlaybackRateMenuButton);
235 exports['default'] = PlaybackRateMenuButton;