3 exports.__esModule = true;
5 var _button = require('../button');
7 var _button2 = _interopRequireDefault(_button);
9 var _component = require('../component');
11 var _component2 = _interopRequireDefault(_component);
13 var _dom = require('../utils/dom.js');
15 var Dom = _interopRequireWildcard(_dom);
17 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; } }
19 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
21 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23 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; }
25 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; } /**
26 * @file mute-toggle.js
31 * A button component for muting the audio.
35 var MuteToggle = function (_Button) {
36 _inherits(MuteToggle, _Button);
39 * Creates an instance of this class.
41 * @param {Player} player
42 * The `Player` that this class should be attached to.
44 * @param {Object} [options]
45 * The key/value store of player options.
47 function MuteToggle(player, options) {
48 _classCallCheck(this, MuteToggle);
50 var _this = _possibleConstructorReturn(this, _Button.call(this, player, options));
52 _this.on(player, 'volumechange', _this.update);
54 // hide mute toggle if the current tech doesn't support volume control
55 if (player.tech_ && player.tech_.featuresVolumeControl === false) {
56 _this.addClass('vjs-hidden');
59 _this.on(player, 'loadstart', function () {
60 // We need to update the button to account for a default muted state.
63 if (player.tech_.featuresVolumeControl === false) {
64 this.addClass('vjs-hidden');
66 this.removeClass('vjs-hidden');
73 * Builds the default DOM `className`.
76 * The DOM `className` for this object.
80 MuteToggle.prototype.buildCSSClass = function buildCSSClass() {
81 return 'vjs-mute-control ' + _Button.prototype.buildCSSClass.call(this);
85 * This gets called when an `MuteToggle` is "clicked". See
86 * {@link ClickableComponent} for more detailed information on what a click can be.
88 * @param {EventTarget~Event} [event]
89 * The `keydown`, `tap`, or `click` event that caused this function to be
97 MuteToggle.prototype.handleClick = function handleClick(event) {
98 this.player_.muted(this.player_.muted() ? false : true);
102 * Update the state of volume.
104 * @param {EventTarget~Event} [event]
105 * The {@link Player#loadstart} event if this function was called through an
108 * @listens Player#loadstart
112 MuteToggle.prototype.update = function update(event) {
113 var vol = this.player_.volume();
116 if (vol === 0 || this.player_.muted()) {
118 } else if (vol < 0.33) {
120 } else if (vol < 0.67) {
124 // Don't rewrite the button text if the actual text doesn't change.
125 // This causes unnecessary and confusing information for screen reader users.
126 // This check is needed because this function gets called every time the volume level is changed.
127 var toMute = this.player_.muted() ? 'Unmute' : 'Mute';
129 if (this.controlText() !== toMute) {
130 this.controlText(toMute);
133 // TODO improve muted icon classes
134 for (var i = 0; i < 4; i++) {
135 Dom.removeElClass(this.el_, 'vjs-vol-' + i);
137 Dom.addElClass(this.el_, 'vjs-vol-' + level);
141 }(_button2['default']);
144 * The text that should display over the `MuteToggle`s controls. Added for localization.
151 MuteToggle.prototype.controlText_ = 'Mute';
153 _component2['default'].registerComponent('MuteToggle', MuteToggle);
154 exports['default'] = MuteToggle;