3 exports.__esModule = true;
5 var _component = require('./component');
7 var _component2 = _interopRequireDefault(_component);
9 var _dom = require('./utils/dom.js');
11 var Dom = _interopRequireWildcard(_dom);
13 var _events = require('./utils/events.js');
15 var Events = _interopRequireWildcard(_events);
17 var _fn = require('./utils/fn.js');
19 var Fn = _interopRequireWildcard(_fn);
21 var _log = require('./utils/log.js');
23 var _log2 = _interopRequireDefault(_log);
25 var _document = require('global/document');
27 var _document2 = _interopRequireDefault(_document);
29 var _obj = require('./utils/obj');
31 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; } }
33 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
35 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
37 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; }
39 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; } /**
45 * Clickable Component which is clickable or keyboard actionable,
46 * but is not a native HTML button.
50 var ClickableComponent = function (_Component) {
51 _inherits(ClickableComponent, _Component);
54 * Creates an instance of this class.
56 * @param {Player} player
57 * The `Player` that this class should be attached to.
59 * @param {Object} [options]
60 * The key/value store of player options.
62 function ClickableComponent(player, options) {
63 _classCallCheck(this, ClickableComponent);
65 var _this = _possibleConstructorReturn(this, _Component.call(this, player, options));
67 _this.emitTapEvents();
74 * Create the `Component`s DOM element.
76 * @param {string} [tag=div]
77 * The element's node type.
79 * @param {Object} [props={}]
80 * An object of properties that should be set on the element.
82 * @param {Object} [attributes={}]
83 * An object of attributes that should be set on the element.
86 * The element that gets created.
90 ClickableComponent.prototype.createEl = function createEl() {
91 var tag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'div';
92 var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
93 var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
95 props = (0, _obj.assign)({
96 className: this.buildCSSClass(),
100 if (tag === 'button') {
101 _log2['default'].error('Creating a ClickableComponent with an HTML element of ' + tag + ' is not supported; use a Button instead.');
104 // Add ARIA attributes for clickable element which is not a native HTML button
105 attributes = (0, _obj.assign)({
108 // let the screen reader user know that the text of the element may change
109 'aria-live': 'polite'
112 this.tabIndex_ = props.tabIndex;
114 var el = _Component.prototype.createEl.call(this, tag, props, attributes);
116 this.createControlTextEl(el);
122 * Create a control text element on this `Component`
124 * @param {Element} [el]
125 * Parent element for the control text.
128 * The control text element that gets created.
132 ClickableComponent.prototype.createControlTextEl = function createControlTextEl(el) {
133 this.controlTextEl_ = Dom.createEl('span', {
134 className: 'vjs-control-text'
138 el.appendChild(this.controlTextEl_);
141 this.controlText(this.controlText_, el);
143 return this.controlTextEl_;
147 * Get or set the localize text to use for the controls on the `Component`.
149 * @param {string} [text]
150 * Control text for element.
152 * @param {Element} [el=this.el()]
153 * Element to set the title on.
155 * @return {string|ClickableComponent}
156 * - The control text when getting
157 * - Returns itself when setting; method can be chained.
161 ClickableComponent.prototype.controlText = function controlText(text) {
162 var el = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.el();
165 return this.controlText_ || 'Need Text';
168 var localizedText = this.localize(text);
170 this.controlText_ = text;
171 this.controlTextEl_.innerHTML = localizedText;
173 if (!this.nonIconControl) {
174 // Set title attribute if only an icon is shown
175 el.setAttribute('title', localizedText);
182 * Builds the default DOM `className`.
185 * The DOM `className` for this object.
189 ClickableComponent.prototype.buildCSSClass = function buildCSSClass() {
190 return 'vjs-control vjs-button ' + _Component.prototype.buildCSSClass.call(this);
194 * Enable this `Component`s element.
196 * @return {ClickableComponent}
197 * Returns itself; method can be chained.
201 ClickableComponent.prototype.enable = function enable() {
202 this.removeClass('vjs-disabled');
203 this.el_.setAttribute('aria-disabled', 'false');
204 if (typeof this.tabIndex_ !== 'undefined') {
205 this.el_.setAttribute('tabIndex', this.tabIndex_);
207 this.on('tap', this.handleClick);
208 this.on('click', this.handleClick);
209 this.on('focus', this.handleFocus);
210 this.on('blur', this.handleBlur);
215 * Disable this `Component`s element.
217 * @return {ClickableComponent}
218 * Returns itself; method can be chained.
222 ClickableComponent.prototype.disable = function disable() {
223 this.addClass('vjs-disabled');
224 this.el_.setAttribute('aria-disabled', 'true');
225 if (typeof this.tabIndex_ !== 'undefined') {
226 this.el_.removeAttribute('tabIndex');
228 this.off('tap', this.handleClick);
229 this.off('click', this.handleClick);
230 this.off('focus', this.handleFocus);
231 this.off('blur', this.handleBlur);
236 * This gets called when a `ClickableComponent` gets:
237 * - Clicked (via the `click` event, listening starts in the constructor)
238 * - Tapped (via the `tap` event, listening starts in the constructor)
239 * - The following things happen in order:
240 * 1. {@link ClickableComponent#handleFocus} is called via a `focus` event on the
241 * `ClickableComponent`.
242 * 2. {@link ClickableComponent#handleFocus} adds a listener for `keydown` on using
243 * {@link ClickableComponent#handleKeyPress}.
244 * 3. `ClickableComponent` has not had a `blur` event (`blur` means that focus was lost). The user presses
245 * the space or enter key.
246 * 4. {@link ClickableComponent#handleKeyPress} calls this function with the `keydown`
247 * event as a parameter.
249 * @param {EventTarget~Event} event
250 * The `keydown`, `tap`, or `click` event that caused this function to be
259 ClickableComponent.prototype.handleClick = function handleClick(event) {};
262 * This gets called when a `ClickableComponent` gains focus via a `focus` event.
263 * Turns on listening for `keydown` events. When they happen it
264 * calls `this.handleKeyPress`.
266 * @param {EventTarget~Event} event
267 * The `focus` event that caused this function to be called.
273 ClickableComponent.prototype.handleFocus = function handleFocus(event) {
274 Events.on(_document2['default'], 'keydown', Fn.bind(this, this.handleKeyPress));
278 * Called when this ClickableComponent has focus and a key gets pressed down. By
279 * default it will call `this.handleClick` when the key is space or enter.
281 * @param {EventTarget~Event} event
282 * The `keydown` event that caused this function to be called.
288 ClickableComponent.prototype.handleKeyPress = function handleKeyPress(event) {
290 // Support Space (32) or Enter (13) key operation to fire a click event
291 if (event.which === 32 || event.which === 13) {
292 event.preventDefault();
293 this.handleClick(event);
294 } else if (_Component.prototype.handleKeyPress) {
296 // Pass keypress handling up for unsupported keys
297 _Component.prototype.handleKeyPress.call(this, event);
302 * Called when a `ClickableComponent` loses focus. Turns off the listener for
303 * `keydown` events. Which Stops `this.handleKeyPress` from getting called.
305 * @param {EventTarget~Event} event
306 * The `blur` event that caused this function to be called.
312 ClickableComponent.prototype.handleBlur = function handleBlur(event) {
313 Events.off(_document2['default'], 'keydown', Fn.bind(this, this.handleKeyPress));
316 return ClickableComponent;
317 }(_component2['default']);
319 _component2['default'].registerComponent('ClickableComponent', ClickableComponent);
320 exports['default'] = ClickableComponent;