3 exports.__esModule = true;
5 var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
7 var _menuItem = require('../../menu/menu-item.js');
9 var _menuItem2 = _interopRequireDefault(_menuItem);
11 var _component = require('../../component.js');
13 var _component2 = _interopRequireDefault(_component);
15 var _fn = require('../../utils/fn.js');
17 var Fn = _interopRequireWildcard(_fn);
19 var _window = require('global/window');
21 var _window2 = _interopRequireDefault(_window);
23 var _document = require('global/document');
25 var _document2 = _interopRequireDefault(_document);
27 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; } }
29 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
31 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
33 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; }
35 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; } /**
36 * @file text-track-menu-item.js
41 * The specific menu item type for selecting a language within a text track kind
45 var TextTrackMenuItem = function (_MenuItem) {
46 _inherits(TextTrackMenuItem, _MenuItem);
49 * Creates an instance of this class.
51 * @param {Player} player
52 * The `Player` that this class should be attached to.
54 * @param {Object} [options]
55 * The key/value store of player options.
57 function TextTrackMenuItem(player, options) {
58 _classCallCheck(this, TextTrackMenuItem);
60 var track = options.track;
61 var tracks = player.textTracks();
63 // Modify options for parent MenuItem class's init.
64 options.label = track.label || track.language || 'Unknown';
65 options.selected = track['default'] || track.mode === 'showing';
67 var _this = _possibleConstructorReturn(this, _MenuItem.call(this, player, options));
72 var changeHandler = Fn.bind(_this, _this.handleTracksChange);
74 player.on(['loadstart', 'texttrackchange'], changeHandler);
75 tracks.addEventListener('change', changeHandler);
76 _this.on('dispose', function () {
77 tracks.removeEventListener('change', changeHandler);
81 // iOS7 doesn't dispatch change events to TextTrackLists when an
82 // associated track's mode changes. Without something like
83 // Object.observe() (also not present on iOS7), it's not
84 // possible to detect changes to the mode attribute and polyfill
85 // the change event. As a poor substitute, we manually dispatch
86 // change events whenever the controls modify the mode.
87 if (tracks && tracks.onchange === undefined) {
90 _this.on(['tap', 'click'], function () {
91 if (_typeof(_window2['default'].Event) !== 'object') {
92 // Android 2.3 throws an Illegal Constructor error for window.Event
94 event = new _window2['default'].Event('change');
96 // continue regardless of error
101 event = _document2['default'].createEvent('Event');
102 event.initEvent('change', true, true);
105 tracks.dispatchEvent(event);
112 * This gets called when an `TextTrackMenuItem` is "clicked". See
113 * {@link ClickableComponent} for more detailed information on what a click can be.
115 * @param {EventTarget~Event} event
116 * The `keydown`, `tap`, or `click` event that caused this function to be
124 TextTrackMenuItem.prototype.handleClick = function handleClick(event) {
125 var kind = this.track.kind;
126 var tracks = this.player_.textTracks();
128 _MenuItem.prototype.handleClick.call(this, event);
134 for (var i = 0; i < tracks.length; i++) {
135 var track = tracks[i];
137 if (track.kind !== kind) {
141 if (track === this.track) {
142 track.mode = 'showing';
144 track.mode = 'disabled';
150 * Handle text track list change
152 * @param {EventTarget~Event} event
153 * The `change` event that caused this function to be called.
155 * @listens TextTrackList#change
159 TextTrackMenuItem.prototype.handleTracksChange = function handleTracksChange(event) {
160 this.selected(this.track.mode === 'showing');
163 return TextTrackMenuItem;
164 }(_menuItem2['default']);
166 _component2['default'].registerComponent('TextTrackMenuItem', TextTrackMenuItem);
167 exports['default'] = TextTrackMenuItem;