volume-menu-button.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _fn = require('../utils/fn.js');
  4. var Fn = _interopRequireWildcard(_fn);
  5. var _component = require('../component.js');
  6. var _component2 = _interopRequireDefault(_component);
  7. var _popup = require('../popup/popup.js');
  8. var _popup2 = _interopRequireDefault(_popup);
  9. var _popupButton = require('../popup/popup-button.js');
  10. var _popupButton2 = _interopRequireDefault(_popupButton);
  11. var _muteToggle = require('./mute-toggle.js');
  12. var _muteToggle2 = _interopRequireDefault(_muteToggle);
  13. var _volumeBar = require('./volume-control/volume-bar.js');
  14. var _volumeBar2 = _interopRequireDefault(_volumeBar);
  15. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  16. 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; } }
  17. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  18. 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; }
  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 volume-menu-button.js
  21. */
  22. /**
  23. * Button for volume popup
  24. *
  25. * @extends PopupButton
  26. */
  27. var VolumeMenuButton = function (_PopupButton) {
  28. _inherits(VolumeMenuButton, _PopupButton);
  29. /**
  30. * Creates an instance of this class.
  31. *
  32. * @param {Player} player
  33. * The `Player` that this class should be attached to.
  34. *
  35. * @param {Object} [options={}]
  36. * The key/value store of player options.
  37. */
  38. function VolumeMenuButton(player) {
  39. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  40. _classCallCheck(this, VolumeMenuButton);
  41. // Default to inline
  42. if (options.inline === undefined) {
  43. options.inline = true;
  44. }
  45. // If the vertical option isn't passed at all, default to true.
  46. if (options.vertical === undefined) {
  47. // If an inline volumeMenuButton is used, we should default to using
  48. // a horizontal slider for obvious reasons.
  49. if (options.inline) {
  50. options.vertical = false;
  51. } else {
  52. options.vertical = true;
  53. }
  54. }
  55. // The vertical option needs to be set on the volumeBar as well,
  56. // since that will need to be passed along to the VolumeBar constructor
  57. options.volumeBar = options.volumeBar || {};
  58. options.volumeBar.vertical = !!options.vertical;
  59. // Same listeners as MuteToggle
  60. var _this = _possibleConstructorReturn(this, _PopupButton.call(this, player, options));
  61. _this.on(player, 'volumechange', _this.volumeUpdate);
  62. _this.on(player, 'loadstart', _this.volumeUpdate);
  63. // hide mute toggle if the current tech doesn't support volume control
  64. function updateVisibility() {
  65. if (player.tech_ && player.tech_.featuresVolumeControl === false) {
  66. this.addClass('vjs-hidden');
  67. } else {
  68. this.removeClass('vjs-hidden');
  69. }
  70. }
  71. updateVisibility.call(_this);
  72. _this.on(player, 'loadstart', updateVisibility);
  73. _this.on(_this.volumeBar, ['slideractive', 'focus'], function () {
  74. this.addClass('vjs-slider-active');
  75. });
  76. _this.on(_this.volumeBar, ['sliderinactive', 'blur'], function () {
  77. this.removeClass('vjs-slider-active');
  78. });
  79. _this.on(_this.volumeBar, ['focus'], function () {
  80. this.addClass('vjs-lock-showing');
  81. });
  82. _this.on(_this.volumeBar, ['blur'], function () {
  83. this.removeClass('vjs-lock-showing');
  84. });
  85. return _this;
  86. }
  87. /**
  88. * Builds the default DOM `className`.
  89. *
  90. * @return {string}
  91. * The DOM `className` for this object.
  92. */
  93. VolumeMenuButton.prototype.buildCSSClass = function buildCSSClass() {
  94. var orientationClass = '';
  95. if (this.options_.vertical) {
  96. orientationClass = 'vjs-volume-menu-button-vertical';
  97. } else {
  98. orientationClass = 'vjs-volume-menu-button-horizontal';
  99. }
  100. return 'vjs-volume-menu-button ' + _PopupButton.prototype.buildCSSClass.call(this) + ' ' + orientationClass;
  101. };
  102. /**
  103. * Create the VolumeMenuButton popup
  104. *
  105. * @return {Popup}
  106. * The popup that was created
  107. */
  108. VolumeMenuButton.prototype.createPopup = function createPopup() {
  109. var popup = new _popup2['default'](this.player_, {
  110. contentElType: 'div'
  111. });
  112. var vb = new _volumeBar2['default'](this.player_, this.options_.volumeBar);
  113. popup.addChild(vb);
  114. this.menuContent = popup;
  115. this.volumeBar = vb;
  116. this.attachVolumeBarEvents();
  117. return popup;
  118. };
  119. /**
  120. * This gets called when an `VolumeMenuButton` is "clicked". See
  121. * {@link ClickableComponent} for more detailed information on what a click can be.
  122. *
  123. * @param {EventTarget~Event} [event]
  124. * The `keydown`, `tap`, or `click` event that caused this function to be
  125. * called.
  126. *
  127. * @listens tap
  128. * @listens click
  129. */
  130. VolumeMenuButton.prototype.handleClick = function handleClick(event) {
  131. _muteToggle2['default'].prototype.handleClick.call(this);
  132. _PopupButton.prototype.handleClick.call(this);
  133. };
  134. /**
  135. * Add events listeners to the created `VolumeBar`.
  136. */
  137. VolumeMenuButton.prototype.attachVolumeBarEvents = function attachVolumeBarEvents() {
  138. this.menuContent.on(['mousedown', 'touchdown'], Fn.bind(this, this.handleMouseDown));
  139. };
  140. /**
  141. * Handle the `mousedown` and `touchdown` events on the `VolumeBar`
  142. *
  143. * @param {EventTarget~Event} [event]
  144. * The `mousedown` or `touchdown` event that caused this to run.
  145. *
  146. * @listens mousedown
  147. * @listens touchdown
  148. */
  149. VolumeMenuButton.prototype.handleMouseDown = function handleMouseDown(event) {
  150. this.on(['mousemove', 'touchmove'], Fn.bind(this.volumeBar, this.volumeBar.handleMouseMove));
  151. this.on(this.el_.ownerDocument, ['mouseup', 'touchend'], this.handleMouseUp);
  152. };
  153. /**
  154. * Handle the `mouseup` and `touchend` events on the `VolumeBar`
  155. *
  156. * @param {EventTarget~Event} [event]
  157. * The `mouseup` or `touchend` event that caused this to run.
  158. *
  159. * @listens mouseup
  160. * @listens touchend
  161. */
  162. VolumeMenuButton.prototype.handleMouseUp = function handleMouseUp(event) {
  163. this.off(['mousemove', 'touchmove'], Fn.bind(this.volumeBar, this.volumeBar.handleMouseMove));
  164. };
  165. return VolumeMenuButton;
  166. }(_popupButton2['default']);
  167. /**
  168. * @borrows MuteToggle#update as VolumeMenuButton#volumeUpdate
  169. */
  170. VolumeMenuButton.prototype.volumeUpdate = _muteToggle2['default'].prototype.update;
  171. /**
  172. * The text that should display over the `VolumeMenuButton`s controls. Added for localization.
  173. *
  174. * @type {string}
  175. * @private
  176. */
  177. VolumeMenuButton.prototype.controlText_ = 'Mute';
  178. _component2['default'].registerComponent('VolumeMenuButton', VolumeMenuButton);
  179. exports['default'] = VolumeMenuButton;