3 exports.__esModule = true;
5 var _eventTarget = require('../event-target');
7 var _eventTarget2 = _interopRequireDefault(_eventTarget);
9 var _browser = require('../utils/browser.js');
11 var browser = _interopRequireWildcard(_browser);
13 var _document = require('global/document');
15 var _document2 = _interopRequireDefault(_document);
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; } }
19 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
21 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
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; } /**
31 * Common functionaliy between {@link TextTrackList}, {@link AudioTrackList}, and
32 * {@link VideoTrackList}
34 * @extends EventTarget
36 var TrackList = function (_EventTarget) {
37 _inherits(TrackList, _EventTarget);
40 * Create an instance of this class
42 * @param {Track[]} tracks
43 * A list of tracks to initialize the list with.
45 * @param {Object} [list]
46 * The child object with inheritance done manually for ie8.
50 function TrackList() {
51 var tracks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
55 var list = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
57 _classCallCheck(this, TrackList);
59 var _this = _possibleConstructorReturn(this, _EventTarget.call(this));
62 list = _this; // eslint-disable-line
64 list = _document2['default'].createElement('custom');
65 for (var prop in TrackList.prototype) {
66 if (prop !== 'constructor') {
67 list[prop] = TrackList.prototype[prop];
76 * @member {number} length
77 * The current number of `Track`s in the this Trackist.
79 Object.defineProperty(list, 'length', {
81 return this.tracks_.length;
85 for (var i = 0; i < tracks.length; i++) {
86 list.addTrack_(tracks[i]);
89 // must return the object, as for ie8 it will not be this
90 // but a reference to a document object
91 return _ret = list, _possibleConstructorReturn(_this, _ret);
95 * Add a {@link Track} to the `TrackList`
97 * @param {Track} track
98 * The audio, video, or text track to add to the list.
100 * @fires TrackList#addtrack
105 TrackList.prototype.addTrack_ = function addTrack_(track) {
106 var index = this.tracks_.length;
108 if (!('' + index in this)) {
109 Object.defineProperty(this, index, {
110 get: function get() {
111 return this.tracks_[index];
116 // Do not add duplicate tracks
117 if (this.tracks_.indexOf(track) === -1) {
118 this.tracks_.push(track);
120 * Triggered when a track is added to a track list.
122 * @event TrackList#addtrack
123 * @type {EventTarget~Event}
124 * @property {Track} track
125 * A reference to track that was added.
135 * Remove a {@link Track} from the `TrackList`
137 * @param {Track} track
138 * The audio, video, or text track to remove from the list.
140 * @fires TrackList#removetrack
145 TrackList.prototype.removeTrack_ = function removeTrack_(rtrack) {
148 for (var i = 0, l = this.length; i < l; i++) {
149 if (this[i] === rtrack) {
155 this.tracks_.splice(i, 1);
166 * Triggered when a track is removed from track list.
168 * @event TrackList#removetrack
169 * @type {EventTarget~Event}
170 * @property {Track} track
171 * A reference to track that was removed.
180 * Get a Track from the TrackList by a tracks id
182 * @param {String} id - the id of the track to get
183 * @method getTrackById
189 TrackList.prototype.getTrackById = function getTrackById(id) {
192 for (var i = 0, l = this.length; i < l; i++) {
195 if (track.id === id) {
205 }(_eventTarget2['default']);
208 * Triggered when a different track is selected/enabled.
210 * @event TrackList#change
211 * @type {EventTarget~Event}
215 * Events that can be called with on + eventName. See {@link EventHandler}.
217 * @property {Object} TrackList#allowedEvents_
222 TrackList.prototype.allowedEvents_ = {
224 addtrack: 'addtrack',
225 removetrack: 'removetrack'
228 // emulate attribute EventHandler support to allow for feature detection
229 for (var event in TrackList.prototype.allowedEvents_) {
230 TrackList.prototype['on' + event] = null;
233 exports['default'] = TrackList;