playback-rate-menu-item.js 4.4 KB

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