Added the Porter Stemmer module to improve searches. This doesn't deal with some...
[yaffs-website] / node_modules / video.js / es5 / tracks / video-track-list.js
1 'use strict';
2
3 exports.__esModule = true;
4
5 var _trackList = require('./track-list');
6
7 var _trackList2 = _interopRequireDefault(_trackList);
8
9 var _browser = require('../utils/browser.js');
10
11 var browser = _interopRequireWildcard(_browser);
12
13 var _document = require('global/document');
14
15 var _document2 = _interopRequireDefault(_document);
16
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; } }
18
19 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
20
21 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
22
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; }
24
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; } /**
26                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 * @file video-track-list.js
27                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 */
28
29
30 /**
31  * Un-select all other {@link VideoTrack}s that are selected.
32  *
33  * @param {VideoTrackList} list
34  *        list to work on
35  *
36  * @param {VideoTrack} track
37  *        The track to skip
38  *
39  * @private
40  */
41 var disableOthers = function disableOthers(list, track) {
42   for (var i = 0; i < list.length; i++) {
43     if (track.id === list[i].id) {
44       continue;
45     }
46     // another video track is enabled, disable it
47     list[i].selected = false;
48   }
49 };
50
51 /**
52  * The current list of {@link VideoTrack} for a video.
53  *
54  * @see [Spec]{@link https://html.spec.whatwg.org/multipage/embedded-content.html#videotracklist}
55  * @extends TrackList
56  */
57
58 var VideoTrackList = function (_TrackList) {
59   _inherits(VideoTrackList, _TrackList);
60
61   /**
62    * Create an instance of this class.
63    *
64    * @param {VideoTrack[]} [tracks=[]]
65    *        A list of `VideoTrack` to instantiate the list with.
66    */
67   function VideoTrackList() {
68     var _this, _ret;
69
70     var tracks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
71
72     _classCallCheck(this, VideoTrackList);
73
74     var list = void 0;
75
76     // make sure only 1 track is enabled
77     // sorted from last index to first index
78     for (var i = tracks.length - 1; i >= 0; i--) {
79       if (tracks[i].selected) {
80         disableOthers(tracks, tracks[i]);
81         break;
82       }
83     }
84
85     // IE8 forces us to implement inheritance ourselves
86     // as it does not support Object.defineProperty properly
87     if (browser.IS_IE8) {
88       list = _document2['default'].createElement('custom');
89       for (var prop in _trackList2['default'].prototype) {
90         if (prop !== 'constructor') {
91           list[prop] = _trackList2['default'].prototype[prop];
92         }
93       }
94       for (var _prop in VideoTrackList.prototype) {
95         if (_prop !== 'constructor') {
96           list[_prop] = VideoTrackList.prototype[_prop];
97         }
98       }
99     }
100
101     list = (_this = _possibleConstructorReturn(this, _TrackList.call(this, tracks, list)), _this);
102     list.changing_ = false;
103
104     /**
105      * @member {number} VideoTrackList#selectedIndex
106      *         The current index of the selected {@link VideoTrack`}.
107      */
108     Object.defineProperty(list, 'selectedIndex', {
109       get: function get() {
110         for (var _i = 0; _i < this.length; _i++) {
111           if (this[_i].selected) {
112             return _i;
113           }
114         }
115         return -1;
116       },
117       set: function set() {}
118     });
119
120     return _ret = list, _possibleConstructorReturn(_this, _ret);
121   }
122
123   /**
124    * Add a {@link VideoTrack} to the `VideoTrackList`.
125    *
126    * @param {VideoTrack} track
127    *        The VideoTrack to add to the list
128    *
129    * @fires TrackList#addtrack
130    * @private
131    */
132
133
134   VideoTrackList.prototype.addTrack_ = function addTrack_(track) {
135     var _this2 = this;
136
137     if (track.selected) {
138       disableOthers(this, track);
139     }
140
141     _TrackList.prototype.addTrack_.call(this, track);
142     // native tracks don't have this
143     if (!track.addEventListener) {
144       return;
145     }
146
147     /**
148      * @listens VideoTrack#selectedchange
149      * @fires TrackList#change
150      */
151     track.addEventListener('selectedchange', function () {
152       if (_this2.changing_) {
153         return;
154       }
155       _this2.changing_ = true;
156       disableOthers(_this2, track);
157       _this2.changing_ = false;
158       _this2.trigger('change');
159     });
160   };
161
162   /**
163    * Add a {@link VideoTrack} to the `VideoTrackList`.
164    *
165    * @param {VideoTrack} track
166    *        The VideoTrack to add to the list
167    *
168    * @fires TrackList#addtrack
169    */
170
171
172   VideoTrackList.prototype.addTrack = function addTrack(track) {
173     this.addTrack_(track);
174   };
175
176   /**
177    * Remove a {@link VideoTrack} to the `VideoTrackList`.
178    *
179    * @param {VideoTrack} track
180    *        The VideoTrack to remove from the list.
181    *
182    * @fires TrackList#removetrack
183    */
184
185
186   VideoTrackList.prototype.removeTrack = function removeTrack(track) {
187     _TrackList.prototype.removeTrack_.call(this, track);
188   };
189
190   return VideoTrackList;
191 }(_trackList2['default']);
192
193 exports['default'] = VideoTrackList;