3 exports.__esModule = true;
5 var _menuButton = require('../../menu/menu-button.js');
7 var _menuButton2 = _interopRequireDefault(_menuButton);
9 var _menu = require('../../menu/menu.js');
11 var _menu2 = _interopRequireDefault(_menu);
13 var _playbackRateMenuItem = require('./playback-rate-menu-item.js');
15 var _playbackRateMenuItem2 = _interopRequireDefault(_playbackRateMenuItem);
17 var _component = require('../../component.js');
19 var _component2 = _interopRequireDefault(_component);
21 var _dom = require('../../utils/dom.js');
23 var Dom = _interopRequireWildcard(_dom);
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; } }
27 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
29 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
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
39 * The component for controlling the playback rate.
43 var PlaybackRateMenuButton = function (_MenuButton) {
44 _inherits(PlaybackRateMenuButton, _MenuButton);
47 * Creates an instance of this class.
49 * @param {Player} player
50 * The `Player` that this class should be attached to.
52 * @param {Object} [options]
53 * The key/value store of player options.
55 function PlaybackRateMenuButton(player, options) {
56 _classCallCheck(this, PlaybackRateMenuButton);
58 var _this = _possibleConstructorReturn(this, _MenuButton.call(this, player, options));
60 _this.updateVisibility();
63 _this.on(player, 'loadstart', _this.updateVisibility);
64 _this.on(player, 'ratechange', _this.updateLabel);
69 * Create the `Component`'s DOM element
72 * The element that was created.
76 PlaybackRateMenuButton.prototype.createEl = function createEl() {
77 var el = _MenuButton.prototype.createEl.call(this);
79 this.labelEl_ = Dom.createEl('div', {
80 className: 'vjs-playback-rate-value',
84 el.appendChild(this.labelEl_);
90 * Builds the default DOM `className`.
93 * The DOM `className` for this object.
97 PlaybackRateMenuButton.prototype.buildCSSClass = function buildCSSClass() {
98 return 'vjs-playback-rate ' + _MenuButton.prototype.buildCSSClass.call(this);
102 * Create the playback rate menu
105 * Menu object populated with {@link PlaybackRateMenuItem}s
109 PlaybackRateMenuButton.prototype.createMenu = function createMenu() {
110 var menu = new _menu2['default'](this.player());
111 var rates = this.playbackRates();
114 for (var i = rates.length - 1; i >= 0; i--) {
115 menu.addChild(new _playbackRateMenuItem2['default'](this.player(), { rate: rates[i] + 'x' }));
123 * Updates ARIA accessibility attributes
127 PlaybackRateMenuButton.prototype.updateARIAAttributes = function updateARIAAttributes() {
128 // Current playback rate
129 this.el().setAttribute('aria-valuenow', this.player().playbackRate());
133 * This gets called when an `PlaybackRateMenuButton` is "clicked". See
134 * {@link ClickableComponent} for more detailed information on what a click can be.
136 * @param {EventTarget~Event} [event]
137 * The `keydown`, `tap`, or `click` event that caused this function to be
145 PlaybackRateMenuButton.prototype.handleClick = function handleClick(event) {
146 // select next rate option
147 var currentRate = this.player().playbackRate();
148 var rates = this.playbackRates();
150 // this will select first one if the last one currently selected
151 var newRate = rates[0];
153 for (var i = 0; i < rates.length; i++) {
154 if (rates[i] > currentRate) {
159 this.player().playbackRate(newRate);
163 * Get possible playback rates
166 * All possible playback rates
170 PlaybackRateMenuButton.prototype.playbackRates = function playbackRates() {
171 return this.options_.playbackRates || this.options_.playerOptions && this.options_.playerOptions.playbackRates;
175 * Get whether playback rates is supported by the tech
176 * and an array of playback rates exists
179 * Whether changing playback rate is supported
183 PlaybackRateMenuButton.prototype.playbackRateSupported = function playbackRateSupported() {
184 return this.player().tech_ && this.player().tech_.featuresPlaybackRate && this.playbackRates() && this.playbackRates().length > 0;
188 * Hide playback rate controls when they're no playback rate options to select
190 * @param {EventTarget~Event} [event]
191 * The event that caused this function to run.
193 * @listens Player#loadstart
197 PlaybackRateMenuButton.prototype.updateVisibility = function updateVisibility(event) {
198 if (this.playbackRateSupported()) {
199 this.removeClass('vjs-hidden');
201 this.addClass('vjs-hidden');
206 * Update button label when rate changed
208 * @param {EventTarget~Event} [event]
209 * The event that caused this function to run.
211 * @listens Player#ratechange
215 PlaybackRateMenuButton.prototype.updateLabel = function updateLabel(event) {
216 if (this.playbackRateSupported()) {
217 this.labelEl_.innerHTML = this.player().playbackRate() + 'x';
221 return PlaybackRateMenuButton;
222 }(_menuButton2['default']);
225 * The text that should display over the `FullscreenToggle`s controls. Added for localization.
232 PlaybackRateMenuButton.prototype.controlText_ = 'Playback Rate';
234 _component2['default'].registerComponent('PlaybackRateMenuButton', PlaybackRateMenuButton);
235 exports['default'] = PlaybackRateMenuButton;