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 var _fn = require('../utils/fn.js');
15 var Fn = _interopRequireWildcard(_fn);
17 var _events = require('../utils/events.js');
19 var Events = _interopRequireWildcard(_events);
21 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; } }
23 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
25 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
27 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; }
29 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; } /**
35 * The Menu component is used to build popup menus, including subtitle and
36 * captions selection menus.
40 var Menu = function (_Component) {
41 _inherits(Menu, _Component);
44 * Create an instance of this class.
46 * @param {Player} player
47 * the player that this component should attach to
49 * @param {Object} [options]
50 * Object of option names and values
53 function Menu(player, options) {
54 _classCallCheck(this, Menu);
56 var _this = _possibleConstructorReturn(this, _Component.call(this, player, options));
58 _this.focusedChild_ = -1;
60 _this.on('keydown', _this.handleKeyPress);
65 * Add a {@link MenuItem} to the menu.
67 * @param {Object|string} component
68 * The name or instance of the `MenuItem` to add.
73 Menu.prototype.addItem = function addItem(component) {
74 this.addChild(component);
75 component.on('click', Fn.bind(this, function (event) {
77 // TODO: Need to set keyboard focus back to the menuButton
82 * Create the `Menu`s DOM element.
85 * the element that was created
89 Menu.prototype.createEl = function createEl() {
90 var contentElType = this.options_.contentElType || 'ul';
92 this.contentEl_ = Dom.createEl(contentElType, {
93 className: 'vjs-menu-content'
96 this.contentEl_.setAttribute('role', 'menu');
98 var el = _Component.prototype.createEl.call(this, 'div', {
99 append: this.contentEl_,
100 className: 'vjs-menu'
103 el.setAttribute('role', 'presentation');
104 el.appendChild(this.contentEl_);
106 // Prevent clicks from bubbling up. Needed for Menu Buttons,
107 // where a click on the parent is significant
108 Events.on(el, 'click', function (event) {
109 event.preventDefault();
110 event.stopImmediatePropagation();
117 * Handle a `keydown` event on this menu. This listener is added in the constructor.
119 * @param {EventTarget~Event} event
120 * A `keydown` event that happened on the menu.
126 Menu.prototype.handleKeyPress = function handleKeyPress(event) {
127 // Left and Down Arrows
128 if (event.which === 37 || event.which === 40) {
129 event.preventDefault();
132 // Up and Right Arrows
133 } else if (event.which === 38 || event.which === 39) {
134 event.preventDefault();
140 * Move to next (lower) menu item for keyboard users.
144 Menu.prototype.stepForward = function stepForward() {
147 if (this.focusedChild_ !== undefined) {
148 stepChild = this.focusedChild_ + 1;
150 this.focus(stepChild);
154 * Move to previous (higher) menu item for keyboard users.
158 Menu.prototype.stepBack = function stepBack() {
161 if (this.focusedChild_ !== undefined) {
162 stepChild = this.focusedChild_ - 1;
164 this.focus(stepChild);
168 * Set focus on a {@link MenuItem} in the `Menu`.
170 * @param {Object|string} [item=0]
171 * Index of child item set focus on.
175 Menu.prototype.focus = function focus() {
176 var item = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
178 var children = this.children().slice();
179 var haveTitle = children.length && children[0].className && /vjs-menu-title/.test(children[0].className);
185 if (children.length > 0) {
188 } else if (item >= children.length) {
189 item = children.length - 1;
192 this.focusedChild_ = item;
194 children[item].el_.focus();
199 }(_component2['default']);
201 _component2['default'].registerComponent('Menu', Menu);
202 exports['default'] = Menu;