03c0c945fbdce49df101159767c3b060e8cd6d05
[yaffs-website] / node_modules / video.js / es5 / menu / menu-item.js
1 'use strict';
2
3 exports.__esModule = true;
4
5 var _clickableComponent = require('../clickable-component.js');
6
7 var _clickableComponent2 = _interopRequireDefault(_clickableComponent);
8
9 var _component = require('../component.js');
10
11 var _component2 = _interopRequireDefault(_component);
12
13 var _obj = require('../utils/obj');
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 menu-item.js
23                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 */
24
25
26 /**
27  * The component for a menu item. `<li>`
28  *
29  * @extends ClickableComponent
30  */
31 var MenuItem = function (_ClickableComponent) {
32   _inherits(MenuItem, _ClickableComponent);
33
34   /**
35    * Creates an instance of the 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    */
44   function MenuItem(player, options) {
45     _classCallCheck(this, MenuItem);
46
47     var _this = _possibleConstructorReturn(this, _ClickableComponent.call(this, player, options));
48
49     _this.selectable = options.selectable;
50
51     _this.selected(options.selected);
52
53     if (_this.selectable) {
54       // TODO: May need to be either menuitemcheckbox or menuitemradio,
55       //       and may need logical grouping of menu items.
56       _this.el_.setAttribute('role', 'menuitemcheckbox');
57     } else {
58       _this.el_.setAttribute('role', 'menuitem');
59     }
60     return _this;
61   }
62
63   /**
64    * Create the `MenuItem's DOM element
65    *
66    * @param {string} [type=li]
67    *        Element's node type, not actually used, always set to `li`.
68    *
69    * @param {Object} [props={}]
70    *        An object of properties that should be set on the element
71    *
72    * @param {Object} [attrs={}]
73    *        An object of attributes that should be set on the element
74    *
75    * @return {Element}
76    *         The element that gets created.
77    */
78
79
80   MenuItem.prototype.createEl = function createEl(type, props, attrs) {
81     // The control is textual, not just an icon
82     this.nonIconControl = true;
83
84     return _ClickableComponent.prototype.createEl.call(this, 'li', (0, _obj.assign)({
85       className: 'vjs-menu-item',
86       innerHTML: this.localize(this.options_.label),
87       tabIndex: -1
88     }, props), attrs);
89   };
90
91   /**
92    * Any click on a `MenuItem` puts int into the selected state.
93    * See {@link ClickableComponent#handleClick} for instances where this is called.
94    *
95    * @param {EventTarget~Event} event
96    *        The `keydown`, `tap`, or `click` event that caused this function to be
97    *        called.
98    *
99    * @listens tap
100    * @listens click
101    */
102
103
104   MenuItem.prototype.handleClick = function handleClick(event) {
105     this.selected(true);
106   };
107
108   /**
109    * Set the state for this menu item as selected or not.
110    *
111    * @param {boolean} selected
112    *        if the menu item is selected or not
113    */
114
115
116   MenuItem.prototype.selected = function selected(_selected) {
117     if (this.selectable) {
118       if (_selected) {
119         this.addClass('vjs-selected');
120         this.el_.setAttribute('aria-checked', 'true');
121         // aria-checked isn't fully supported by browsers/screen readers,
122         // so indicate selected state to screen reader in the control text.
123         this.controlText(', selected');
124       } else {
125         this.removeClass('vjs-selected');
126         this.el_.setAttribute('aria-checked', 'false');
127         // Indicate un-selected state to screen reader
128         // Note that a space clears out the selected state text
129         this.controlText(' ');
130       }
131     }
132   };
133
134   return MenuItem;
135 }(_clickableComponent2['default']);
136
137 _component2['default'].registerComponent('MenuItem', MenuItem);
138 exports['default'] = MenuItem;