58407b830f20bbe4c2b10e0a527ff6e3621fb2a9
[yaffs-website] / node_modules / video.js / es5 / control-bar / volume-control / volume-bar.js
1 'use strict';
2
3 exports.__esModule = true;
4
5 var _slider = require('../../slider/slider.js');
6
7 var _slider2 = _interopRequireDefault(_slider);
8
9 var _component = require('../../component.js');
10
11 var _component2 = _interopRequireDefault(_component);
12
13 var _fn = require('../../utils/fn.js');
14
15 var Fn = _interopRequireWildcard(_fn);
16
17 require('./volume-level.js');
18
19 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; } }
20
21 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
22
23 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
24
25 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; }
26
27 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; } /**
28                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 * @file volume-bar.js
29                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 */
30
31
32 // Required children
33
34
35 /**
36  * The bar that contains the volume level and can be clicked on to adjust the level
37  *
38  * @extends Slider
39  */
40 var VolumeBar = function (_Slider) {
41   _inherits(VolumeBar, _Slider);
42
43   /**
44    * Creates an instance of this class.
45    *
46    * @param {Player} player
47    *        The `Player` that this class should be attached to.
48    *
49    * @param {Object} [options]
50    *        The key/value store of player options.
51    */
52   function VolumeBar(player, options) {
53     _classCallCheck(this, VolumeBar);
54
55     var _this = _possibleConstructorReturn(this, _Slider.call(this, player, options));
56
57     _this.on(player, 'volumechange', _this.updateARIAAttributes);
58     player.ready(Fn.bind(_this, _this.updateARIAAttributes));
59     return _this;
60   }
61
62   /**
63    * Create the `Component`'s DOM element
64    *
65    * @return {Element}
66    *         The element that was created.
67    */
68
69
70   VolumeBar.prototype.createEl = function createEl() {
71     return _Slider.prototype.createEl.call(this, 'div', {
72       className: 'vjs-volume-bar vjs-slider-bar'
73     }, {
74       'aria-label': 'volume level'
75     });
76   };
77
78   /**
79    * Handle movement events on the {@link VolumeMenuButton}.
80    *
81    * @param {EventTarget~Event} event
82    *        The event that caused this function to run.
83    *
84    * @listens mousemove
85    */
86
87
88   VolumeBar.prototype.handleMouseMove = function handleMouseMove(event) {
89     this.checkMuted();
90     this.player_.volume(this.calculateDistance(event));
91   };
92
93   /**
94    * If the player is muted unmute it.
95    */
96
97
98   VolumeBar.prototype.checkMuted = function checkMuted() {
99     if (this.player_.muted()) {
100       this.player_.muted(false);
101     }
102   };
103
104   /**
105    * Get percent of volume level
106    *
107    * @return {number}
108    *         Volume level percent as a decimal number.
109    */
110
111
112   VolumeBar.prototype.getPercent = function getPercent() {
113     if (this.player_.muted()) {
114       return 0;
115     }
116     return this.player_.volume();
117   };
118
119   /**
120    * Increase volume level for keyboard users
121    */
122
123
124   VolumeBar.prototype.stepForward = function stepForward() {
125     this.checkMuted();
126     this.player_.volume(this.player_.volume() + 0.1);
127   };
128
129   /**
130    * Decrease volume level for keyboard users
131    */
132
133
134   VolumeBar.prototype.stepBack = function stepBack() {
135     this.checkMuted();
136     this.player_.volume(this.player_.volume() - 0.1);
137   };
138
139   /**
140    * Update ARIA accessibility attributes
141    *
142    * @param {EventTarget~Event} [event]
143    *        The `volumechange` event that caused this function to run.
144    *
145    * @listens Player#volumechange
146    */
147
148
149   VolumeBar.prototype.updateARIAAttributes = function updateARIAAttributes(event) {
150     // Current value of volume bar as a percentage
151     var volume = (this.player_.volume() * 100).toFixed(2);
152
153     this.el_.setAttribute('aria-valuenow', volume);
154     this.el_.setAttribute('aria-valuetext', volume + '%');
155   };
156
157   return VolumeBar;
158 }(_slider2['default']);
159
160 /**
161  * Default options for the `VolumeBar`
162  *
163  * @type {Object}
164  * @private
165  */
166
167
168 VolumeBar.prototype.options_ = {
169   children: ['volumeLevel'],
170   barName: 'volumeLevel'
171 };
172
173 /**
174  * Call the update event for this Slider when this event happens on the player.
175  *
176  * @type {string}
177  */
178 VolumeBar.prototype.playerEvent = 'volumechange';
179
180 _component2['default'].registerComponent('VolumeBar', VolumeBar);
181 exports['default'] = VolumeBar;