Version 1
[yaffs-website] / node_modules / video.js / es5 / menu / menu-item.js
diff --git a/node_modules/video.js/es5/menu/menu-item.js b/node_modules/video.js/es5/menu/menu-item.js
new file mode 100644 (file)
index 0000000..03c0c94
--- /dev/null
@@ -0,0 +1,138 @@
+'use strict';
+
+exports.__esModule = true;
+
+var _clickableComponent = require('../clickable-component.js');
+
+var _clickableComponent2 = _interopRequireDefault(_clickableComponent);
+
+var _component = require('../component.js');
+
+var _component2 = _interopRequireDefault(_component);
+
+var _obj = require('../utils/obj');
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
+
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+
+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; }
+
+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; } /**
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                * @file menu-item.js
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                */
+
+
+/**
+ * The component for a menu item. `<li>`
+ *
+ * @extends ClickableComponent
+ */
+var MenuItem = function (_ClickableComponent) {
+  _inherits(MenuItem, _ClickableComponent);
+
+  /**
+   * Creates an instance of the this class.
+   *
+   * @param {Player} player
+   *        The `Player` that this class should be attached to.
+   *
+   * @param {Object} [options={}]
+   *        The key/value store of player options.
+   *
+   */
+  function MenuItem(player, options) {
+    _classCallCheck(this, MenuItem);
+
+    var _this = _possibleConstructorReturn(this, _ClickableComponent.call(this, player, options));
+
+    _this.selectable = options.selectable;
+
+    _this.selected(options.selected);
+
+    if (_this.selectable) {
+      // TODO: May need to be either menuitemcheckbox or menuitemradio,
+      //       and may need logical grouping of menu items.
+      _this.el_.setAttribute('role', 'menuitemcheckbox');
+    } else {
+      _this.el_.setAttribute('role', 'menuitem');
+    }
+    return _this;
+  }
+
+  /**
+   * Create the `MenuItem's DOM element
+   *
+   * @param {string} [type=li]
+   *        Element's node type, not actually used, always set to `li`.
+   *
+   * @param {Object} [props={}]
+   *        An object of properties that should be set on the element
+   *
+   * @param {Object} [attrs={}]
+   *        An object of attributes that should be set on the element
+   *
+   * @return {Element}
+   *         The element that gets created.
+   */
+
+
+  MenuItem.prototype.createEl = function createEl(type, props, attrs) {
+    // The control is textual, not just an icon
+    this.nonIconControl = true;
+
+    return _ClickableComponent.prototype.createEl.call(this, 'li', (0, _obj.assign)({
+      className: 'vjs-menu-item',
+      innerHTML: this.localize(this.options_.label),
+      tabIndex: -1
+    }, props), attrs);
+  };
+
+  /**
+   * Any click on a `MenuItem` puts int into the selected state.
+   * See {@link ClickableComponent#handleClick} for instances where this is called.
+   *
+   * @param {EventTarget~Event} event
+   *        The `keydown`, `tap`, or `click` event that caused this function to be
+   *        called.
+   *
+   * @listens tap
+   * @listens click
+   */
+
+
+  MenuItem.prototype.handleClick = function handleClick(event) {
+    this.selected(true);
+  };
+
+  /**
+   * Set the state for this menu item as selected or not.
+   *
+   * @param {boolean} selected
+   *        if the menu item is selected or not
+   */
+
+
+  MenuItem.prototype.selected = function selected(_selected) {
+    if (this.selectable) {
+      if (_selected) {
+        this.addClass('vjs-selected');
+        this.el_.setAttribute('aria-checked', 'true');
+        // aria-checked isn't fully supported by browsers/screen readers,
+        // so indicate selected state to screen reader in the control text.
+        this.controlText(', selected');
+      } else {
+        this.removeClass('vjs-selected');
+        this.el_.setAttribute('aria-checked', 'false');
+        // Indicate un-selected state to screen reader
+        // Note that a space clears out the selected state text
+        this.controlText(' ');
+      }
+    }
+  };
+
+  return MenuItem;
+}(_clickableComponent2['default']);
+
+_component2['default'].registerComponent('MenuItem', MenuItem);
+exports['default'] = MenuItem;