007c87245a198d784bcb04749773b49693fe2b55
[yaffs-website] / node_modules / video.js / es5 / control-bar / mute-toggle.js
1 'use strict';
2
3 exports.__esModule = true;
4
5 var _button = require('../button');
6
7 var _button2 = _interopRequireDefault(_button);
8
9 var _component = require('../component');
10
11 var _component2 = _interopRequireDefault(_component);
12
13 var _dom = require('../utils/dom.js');
14
15 var Dom = _interopRequireWildcard(_dom);
16
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; } }
18
19 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
20
21 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
22
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; }
24
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
27                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 */
28
29
30 /**
31  * A button component for muting the audio.
32  *
33  * @extends Button
34  */
35 var MuteToggle = function (_Button) {
36   _inherits(MuteToggle, _Button);
37
38   /**
39    * Creates an instance of this class.
40    *
41    * @param {Player} player
42    *        The `Player` that this class should be attached to.
43    *
44    * @param {Object} [options]
45    *        The key/value store of player options.
46    */
47   function MuteToggle(player, options) {
48     _classCallCheck(this, MuteToggle);
49
50     var _this = _possibleConstructorReturn(this, _Button.call(this, player, options));
51
52     _this.on(player, 'volumechange', _this.update);
53
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');
57     }
58
59     _this.on(player, 'loadstart', function () {
60       // We need to update the button to account for a default muted state.
61       this.update();
62
63       if (player.tech_.featuresVolumeControl === false) {
64         this.addClass('vjs-hidden');
65       } else {
66         this.removeClass('vjs-hidden');
67       }
68     });
69     return _this;
70   }
71
72   /**
73    * Builds the default DOM `className`.
74    *
75    * @return {string}
76    *         The DOM `className` for this object.
77    */
78
79
80   MuteToggle.prototype.buildCSSClass = function buildCSSClass() {
81     return 'vjs-mute-control ' + _Button.prototype.buildCSSClass.call(this);
82   };
83
84   /**
85    * This gets called when an `MuteToggle` is "clicked". See
86    * {@link ClickableComponent} for more detailed information on what a click can be.
87    *
88    * @param {EventTarget~Event} [event]
89    *        The `keydown`, `tap`, or `click` event that caused this function to be
90    *        called.
91    *
92    * @listens tap
93    * @listens click
94    */
95
96
97   MuteToggle.prototype.handleClick = function handleClick(event) {
98     this.player_.muted(this.player_.muted() ? false : true);
99   };
100
101   /**
102    * Update the state of volume.
103    *
104    * @param {EventTarget~Event} [event]
105    *        The {@link Player#loadstart} event if this function was called through an
106    *        event.
107    *
108    * @listens Player#loadstart
109    */
110
111
112   MuteToggle.prototype.update = function update(event) {
113     var vol = this.player_.volume();
114     var level = 3;
115
116     if (vol === 0 || this.player_.muted()) {
117       level = 0;
118     } else if (vol < 0.33) {
119       level = 1;
120     } else if (vol < 0.67) {
121       level = 2;
122     }
123
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';
128
129     if (this.controlText() !== toMute) {
130       this.controlText(toMute);
131     }
132
133     // TODO improve muted icon classes
134     for (var i = 0; i < 4; i++) {
135       Dom.removeElClass(this.el_, 'vjs-vol-' + i);
136     }
137     Dom.addElClass(this.el_, 'vjs-vol-' + level);
138   };
139
140   return MuteToggle;
141 }(_button2['default']);
142
143 /**
144  * The text that should display over the `MuteToggle`s controls. Added for localization.
145  *
146  * @type {string}
147  * @private
148  */
149
150
151 MuteToggle.prototype.controlText_ = 'Mute';
152
153 _component2['default'].registerComponent('MuteToggle', MuteToggle);
154 exports['default'] = MuteToggle;