3 exports.__esModule = true;
5 var _component = require('../../component.js');
7 var _component2 = _interopRequireDefault(_component);
9 var _dom = require('../../utils/dom.js');
11 var Dom = _interopRequireWildcard(_dom);
13 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; } }
15 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
17 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19 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; }
21 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; } /**
22 * @file load-progress-bar.js
27 * Shows loading progress
31 var LoadProgressBar = function (_Component) {
32 _inherits(LoadProgressBar, _Component);
35 * Creates an instance of this class.
37 * @param {Player} player
38 * The `Player` that this class should be attached to.
40 * @param {Object} [options]
41 * The key/value store of player options.
43 function LoadProgressBar(player, options) {
44 _classCallCheck(this, LoadProgressBar);
46 var _this = _possibleConstructorReturn(this, _Component.call(this, player, options));
49 _this.on(player, 'progress', _this.update);
54 * Create the `Component`'s DOM element
57 * The element that was created.
61 LoadProgressBar.prototype.createEl = function createEl() {
62 return _Component.prototype.createEl.call(this, 'div', {
63 className: 'vjs-load-progress',
64 innerHTML: '<span class="vjs-control-text"><span>' + this.localize('Loaded') + '</span>: 0%</span>'
71 * @param {EventTarget~Event} [event]
72 * The `progress` event that caused this function to run.
74 * @listens Player#progress
78 LoadProgressBar.prototype.update = function update(event) {
79 var buffered = this.player_.buffered();
80 var duration = this.player_.duration();
81 var bufferedEnd = this.player_.bufferedEnd();
82 var children = this.partEls_;
84 // get the percent width of a time compared to the total end
85 var percentify = function percentify(time, end) {
87 var percent = time / end || 0;
89 return (percent >= 1 ? 1 : percent) * 100 + '%';
92 // update the width of the progress bar
93 this.el_.style.width = percentify(bufferedEnd, duration);
95 // add child elements to represent the individual buffered time ranges
96 for (var i = 0; i < buffered.length; i++) {
97 var start = buffered.start(i);
98 var end = buffered.end(i);
99 var part = children[i];
102 part = this.el_.appendChild(Dom.createEl());
106 // set the percent based on the width of the progress bar (bufferedEnd)
107 part.style.left = percentify(start, bufferedEnd);
108 part.style.width = percentify(end - start, bufferedEnd);
111 // remove unused buffered range elements
112 for (var _i = children.length; _i > buffered.length; _i--) {
113 this.el_.removeChild(children[_i - 1]);
115 children.length = buffered.length;
118 return LoadProgressBar;
119 }(_component2['default']);
121 _component2['default'].registerComponent('LoadProgressBar', LoadProgressBar);
122 exports['default'] = LoadProgressBar;