3 exports.__esModule = true;
5 var _slider = require('../../slider/slider.js');
7 var _slider2 = _interopRequireDefault(_slider);
9 var _component = require('../../component.js');
11 var _component2 = _interopRequireDefault(_component);
13 var _fn = require('../../utils/fn.js');
15 var Fn = _interopRequireWildcard(_fn);
17 var _formatTime = require('../../utils/format-time.js');
19 var _formatTime2 = _interopRequireDefault(_formatTime);
21 var _computedStyle = require('../../utils/computed-style.js');
23 var _computedStyle2 = _interopRequireDefault(_computedStyle);
25 require('./load-progress-bar.js');
27 require('./play-progress-bar.js');
29 require('./tooltip-progress-bar.js');
31 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; } }
33 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
35 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
37 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; }
39 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; } /**
45 * Seek Bar and holder for the progress bars
49 var SeekBar = function (_Slider) {
50 _inherits(SeekBar, _Slider);
53 * Creates an instance of this class.
55 * @param {Player} player
56 * The `Player` that this class should be attached to.
58 * @param {Object} [options]
59 * The key/value store of player options.
61 function SeekBar(player, options) {
62 _classCallCheck(this, SeekBar);
64 var _this = _possibleConstructorReturn(this, _Slider.call(this, player, options));
66 _this.on(player, 'timeupdate', _this.updateProgress);
67 _this.on(player, 'ended', _this.updateProgress);
68 player.ready(Fn.bind(_this, _this.updateProgress));
70 if (options.playerOptions && options.playerOptions.controlBar && options.playerOptions.controlBar.progressControl && options.playerOptions.controlBar.progressControl.keepTooltipsInside) {
71 _this.keepTooltipsInside = options.playerOptions.controlBar.progressControl.keepTooltipsInside;
74 if (_this.keepTooltipsInside) {
75 _this.tooltipProgressBar = _this.addChild('TooltipProgressBar');
81 * Create the `Component`'s DOM element
84 * The element that was created.
88 SeekBar.prototype.createEl = function createEl() {
89 return _Slider.prototype.createEl.call(this, 'div', {
90 className: 'vjs-progress-holder'
92 'aria-label': 'progress bar'
97 * Update the seek bars tooltip and width.
99 * @param {EventTarget~Event} [event]
100 * The `timeupdate` or `ended` event that caused this to run.
102 * @listens Player#timeupdate
103 * @listens Player#ended
107 SeekBar.prototype.updateProgress = function updateProgress(event) {
108 this.updateAriaAttributes(this.el_);
110 if (this.keepTooltipsInside) {
111 this.updateAriaAttributes(this.tooltipProgressBar.el_);
112 this.tooltipProgressBar.el_.style.width = this.bar.el_.style.width;
114 var playerWidth = parseFloat((0, _computedStyle2['default'])(this.player().el(), 'width'));
115 var tooltipWidth = parseFloat((0, _computedStyle2['default'])(this.tooltipProgressBar.tooltip, 'width'));
116 var tooltipStyle = this.tooltipProgressBar.el().style;
118 tooltipStyle.maxWidth = Math.floor(playerWidth - tooltipWidth / 2) + 'px';
119 tooltipStyle.minWidth = Math.ceil(tooltipWidth / 2) + 'px';
120 tooltipStyle.right = '-' + tooltipWidth / 2 + 'px';
125 * Update ARIA accessibility attributes
127 * @param {Element} el
128 * The element to update with aria accessibility attributes.
132 SeekBar.prototype.updateAriaAttributes = function updateAriaAttributes(el) {
133 // Allows for smooth scrubbing, when player can't keep up.
134 var time = this.player_.scrubbing() ? this.player_.getCache().currentTime : this.player_.currentTime();
136 // machine readable value of progress bar (percentage complete)
137 el.setAttribute('aria-valuenow', (this.getPercent() * 100).toFixed(2));
138 // human readable value of progress bar (time complete)
139 el.setAttribute('aria-valuetext', (0, _formatTime2['default'])(time, this.player_.duration()));
143 * Get percentage of video played
146 * The percentage played
150 SeekBar.prototype.getPercent = function getPercent() {
151 var percent = this.player_.currentTime() / this.player_.duration();
153 return percent >= 1 ? 1 : percent;
157 * Handle mouse down on seek bar
159 * @param {EventTarget~Event} event
160 * The `mousedown` event that caused this to run.
166 SeekBar.prototype.handleMouseDown = function handleMouseDown(event) {
167 this.player_.scrubbing(true);
169 this.videoWasPlaying = !this.player_.paused();
170 this.player_.pause();
172 _Slider.prototype.handleMouseDown.call(this, event);
176 * Handle mouse move on seek bar
178 * @param {EventTarget~Event} event
179 * The `mousemove` event that caused this to run.
185 SeekBar.prototype.handleMouseMove = function handleMouseMove(event) {
186 var newTime = this.calculateDistance(event) * this.player_.duration();
188 // Don't let video end while scrubbing.
189 if (newTime === this.player_.duration()) {
190 newTime = newTime - 0.1;
193 // Set new time (tell player to seek to new time)
194 this.player_.currentTime(newTime);
198 * Handle mouse up on seek bar
200 * @param {EventTarget~Event} event
201 * The `mouseup` event that caused this to run.
207 SeekBar.prototype.handleMouseUp = function handleMouseUp(event) {
208 _Slider.prototype.handleMouseUp.call(this, event);
210 this.player_.scrubbing(false);
211 if (this.videoWasPlaying) {
217 * Move more quickly fast forward for keyboard-only users
221 SeekBar.prototype.stepForward = function stepForward() {
222 // more quickly fast forward for keyboard-only users
223 this.player_.currentTime(this.player_.currentTime() + 5);
227 * Move more quickly rewind for keyboard-only users
231 SeekBar.prototype.stepBack = function stepBack() {
232 // more quickly rewind for keyboard-only users
233 this.player_.currentTime(this.player_.currentTime() - 5);
237 }(_slider2['default']);
240 * Default options for the `SeekBar`
247 SeekBar.prototype.options_ = {
248 children: ['loadProgressBar', 'mouseTimeDisplay', 'playProgressBar'],
249 barName: 'playProgressBar'
253 * Call the update event for this Slider when this event happens on the player.
257 SeekBar.prototype.playerEvent = 'timeupdate';
259 _component2['default'].registerComponent('SeekBar', SeekBar);
260 exports['default'] = SeekBar;