diff options
Diffstat (limited to 'javascript/videojs/src/js/control-bar/playback-rate-menu/playback-rate-menu-item.js')
| -rw-r--r-- | javascript/videojs/src/js/control-bar/playback-rate-menu/playback-rate-menu-item.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/javascript/videojs/src/js/control-bar/playback-rate-menu/playback-rate-menu-item.js b/javascript/videojs/src/js/control-bar/playback-rate-menu/playback-rate-menu-item.js new file mode 100644 index 0000000..b0b145a --- /dev/null +++ b/javascript/videojs/src/js/control-bar/playback-rate-menu/playback-rate-menu-item.js @@ -0,0 +1,82 @@ +/** + * @file playback-rate-menu-item.js + */ +import MenuItem from '../../menu/menu-item.js'; +import Component from '../../component.js'; + +/** @import Player from '../../player' */ + +/** + * The specific menu item type for selecting a playback rate. + * + * @extends MenuItem + */ +class PlaybackRateMenuItem extends MenuItem { + + /** + * Creates an instance of this class. + * + * @param {Player} player + * The `Player` that this class should be attached to. + * + * @param {Object} [options] + * The key/value store of player options. + */ + constructor(player, options) { + const label = options.rate; + const rate = parseFloat(label, 10); + + // Modify options for parent MenuItem class's init. + options.label = label; + options.selected = rate === player.playbackRate(); + options.selectable = true; + options.multiSelectable = false; + + super(player, options); + + this.label = label; + this.rate = rate; + + this.on(player, 'ratechange', (e) => this.update(e)); + } + + /** + * This gets called when an `PlaybackRateMenuItem` is "clicked". See + * {@link ClickableComponent} for more detailed information on what a click can be. + * + * @param {Event} [event] + * The `keydown`, `tap`, or `click` event that caused this function to be + * called. + * + * @listens tap + * @listens click + */ + handleClick(event) { + super.handleClick(); + this.player().playbackRate(this.rate); + } + + /** + * Update the PlaybackRateMenuItem when the playbackrate changes. + * + * @param {Event} [event] + * The `ratechange` event that caused this function to run. + * + * @listens Player#ratechange + */ + update(event) { + this.selected(this.player().playbackRate() === this.rate); + } + +} + +/** + * The text that should display over the `PlaybackRateMenuItem`s controls. Added for localization. + * + * @type {string} + * @private + */ +PlaybackRateMenuItem.prototype.contentElType = 'button'; + +Component.registerComponent('PlaybackRateMenuItem', PlaybackRateMenuItem); +export default PlaybackRateMenuItem; |
