Version 1
[yaffs-website] / node_modules / video.js / es5 / control-bar / playback-rate-menu / playback-rate-menu-item.js
1 'use strict';
2
3 exports.__esModule = true;
4
5 var _menuItem = require('../../menu/menu-item.js');
6
7 var _menuItem2 = _interopRequireDefault(_menuItem);
8
9 var _component = require('../../component.js');
10
11 var _component2 = _interopRequireDefault(_component);
12
13 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
14
15 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16
17 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; }
18
19 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; } /**
20                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 * @file playback-rate-menu-item.js
21                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 */
22
23
24 /**
25  * The specific menu item type for selecting a playback rate.
26  *
27  * @extends MenuItem
28  */
29 var PlaybackRateMenuItem = function (_MenuItem) {
30   _inherits(PlaybackRateMenuItem, _MenuItem);
31
32   /**
33    * Creates an instance of this class.
34    *
35    * @param {Player} player
36    *        The `Player` that this class should be attached to.
37    *
38    * @param {Object} [options]
39    *        The key/value store of player options.
40    */
41   function PlaybackRateMenuItem(player, options) {
42     _classCallCheck(this, PlaybackRateMenuItem);
43
44     var label = options.rate;
45     var rate = parseFloat(label, 10);
46
47     // Modify options for parent MenuItem class's init.
48     options.label = label;
49     options.selected = rate === 1;
50     options.selectable = true;
51
52     var _this = _possibleConstructorReturn(this, _MenuItem.call(this, player, options));
53
54     _this.label = label;
55     _this.rate = rate;
56
57     _this.on(player, 'ratechange', _this.update);
58     return _this;
59   }
60
61   /**
62    * This gets called when an `PlaybackRateMenuItem` is "clicked". See
63    * {@link ClickableComponent} for more detailed information on what a click can be.
64    *
65    * @param {EventTarget~Event} [event]
66    *        The `keydown`, `tap`, or `click` event that caused this function to be
67    *        called.
68    *
69    * @listens tap
70    * @listens click
71    */
72
73
74   PlaybackRateMenuItem.prototype.handleClick = function handleClick(event) {
75     _MenuItem.prototype.handleClick.call(this);
76     this.player().playbackRate(this.rate);
77   };
78
79   /**
80    * Update the PlaybackRateMenuItem when the playbackrate changes.
81    *
82    * @param {EventTarget~Event} [event]
83    *        The `ratechange` event that caused this function to run.
84    *
85    * @listens Player#ratechange
86    */
87
88
89   PlaybackRateMenuItem.prototype.update = function update(event) {
90     this.selected(this.player().playbackRate() === this.rate);
91   };
92
93   return PlaybackRateMenuItem;
94 }(_menuItem2['default']);
95
96 /**
97  * The text that should display over the `PlaybackRateMenuItem`s controls. Added for localization.
98  *
99  * @type {string}
100  * @private
101  */
102
103
104 PlaybackRateMenuItem.prototype.contentElType = 'button';
105
106 _component2['default'].registerComponent('PlaybackRateMenuItem', PlaybackRateMenuItem);
107 exports['default'] = PlaybackRateMenuItem;