Security update for Core, with self-updated composer
[yaffs-website] / node_modules / video.js / es5 / control-bar / progress-control / load-progress-bar.js
1 'use strict';
2
3 exports.__esModule = true;
4
5 var _component = require('../../component.js');
6
7 var _component2 = _interopRequireDefault(_component);
8
9 var _dom = require('../../utils/dom.js');
10
11 var Dom = _interopRequireWildcard(_dom);
12
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; } }
14
15 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
16
17 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
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; }
20
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
23                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 */
24
25
26 /**
27  * Shows loading progress
28  *
29  * @extends Component
30  */
31 var LoadProgressBar = function (_Component) {
32   _inherits(LoadProgressBar, _Component);
33
34   /**
35    * Creates an instance of this class.
36    *
37    * @param {Player} player
38    *        The `Player` that this class should be attached to.
39    *
40    * @param {Object} [options]
41    *        The key/value store of player options.
42    */
43   function LoadProgressBar(player, options) {
44     _classCallCheck(this, LoadProgressBar);
45
46     var _this = _possibleConstructorReturn(this, _Component.call(this, player, options));
47
48     _this.partEls_ = [];
49     _this.on(player, 'progress', _this.update);
50     return _this;
51   }
52
53   /**
54    * Create the `Component`'s DOM element
55    *
56    * @return {Element}
57    *         The element that was created.
58    */
59
60
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>'
65     });
66   };
67
68   /**
69    * Update progress bar
70    *
71    * @param {EventTarget~Event} [event]
72    *        The `progress` event that caused this function to run.
73    *
74    * @listens Player#progress
75    */
76
77
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_;
83
84     // get the percent width of a time compared to the total end
85     var percentify = function percentify(time, end) {
86       // no NaN
87       var percent = time / end || 0;
88
89       return (percent >= 1 ? 1 : percent) * 100 + '%';
90     };
91
92     // update the width of the progress bar
93     this.el_.style.width = percentify(bufferedEnd, duration);
94
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];
100
101       if (!part) {
102         part = this.el_.appendChild(Dom.createEl());
103         children[i] = part;
104       }
105
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);
109     }
110
111     // remove unused buffered range elements
112     for (var _i = children.length; _i > buffered.length; _i--) {
113       this.el_.removeChild(children[_i - 1]);
114     }
115     children.length = buffered.length;
116   };
117
118   return LoadProgressBar;
119 }(_component2['default']);
120
121 _component2['default'].registerComponent('LoadProgressBar', LoadProgressBar);
122 exports['default'] = LoadProgressBar;