a685d2676bcbed693ae2e73958aa4d53bef53794
[yaffs-website] / node_modules / video.js / es5 / button.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');
10
11 var _component2 = _interopRequireDefault(_component);
12
13 var _log = require('./utils/log.js');
14
15 var _log2 = _interopRequireDefault(_log);
16
17 var _obj = require('./utils/obj');
18
19 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
20
21 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
22
23 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; }
24
25 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; } /**
26                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 * @file button.js
27                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 */
28
29
30 /**
31  * Base class for all buttons.
32  *
33  * @extends ClickableComponent
34  */
35 var Button = function (_ClickableComponent) {
36   _inherits(Button, _ClickableComponent);
37
38   function Button() {
39     _classCallCheck(this, Button);
40
41     return _possibleConstructorReturn(this, _ClickableComponent.apply(this, arguments));
42   }
43
44   /**
45    * Create the `Button`s DOM element.
46    *
47    * @param {string} [tag=button]
48    *        Element's node type. e.g. 'button'
49    *
50    * @param {Object} [props={}]
51    *        An object of properties that should be set on the element.
52    *
53    * @param {Object} [attributes={}]
54    *        An object of attributes that should be set on the element.
55    *
56    * @return {Element}
57    *         The element that gets created.
58    */
59   Button.prototype.createEl = function createEl() {
60     var tag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'button';
61     var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
62     var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
63
64     props = (0, _obj.assign)({
65       className: this.buildCSSClass()
66     }, props);
67
68     if (tag !== 'button') {
69       _log2['default'].warn('Creating a Button with an HTML element of ' + tag + ' is deprecated; use ClickableComponent instead.');
70
71       // Add properties for clickable element which is not a native HTML button
72       props = (0, _obj.assign)({
73         tabIndex: 0
74       }, props);
75
76       // Add ARIA attributes for clickable element which is not a native HTML button
77       attributes = (0, _obj.assign)({
78         role: 'button'
79       }, attributes);
80     }
81
82     // Add attributes for button element
83     attributes = (0, _obj.assign)({
84
85       // Necessary since the default button type is "submit"
86       'type': 'button',
87
88       // let the screen reader user know that the text of the button may change
89       'aria-live': 'polite'
90     }, attributes);
91
92     var el = _component2['default'].prototype.createEl.call(this, tag, props, attributes);
93
94     this.createControlTextEl(el);
95
96     return el;
97   };
98
99   /**
100    * Add a child `Component` inside of this `Button`.
101    *
102    * @param {string|Component} child
103    *        The name or instance of a child to add.
104    *
105    * @param {Object} [options={}]
106    *        The key/value store of options that will get passed to children of
107    *        the child.
108    *
109    * @return {Component}
110    *         The `Component` that gets added as a child. When using a string the
111    *         `Component` will get created by this process.
112    *
113    * @deprecated since version 5
114    */
115
116
117   Button.prototype.addChild = function addChild(child) {
118     var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
119
120     var className = this.constructor.name;
121
122     _log2['default'].warn('Adding an actionable (user controllable) child to a Button (' + className + ') is not supported; use a ClickableComponent instead.');
123
124     // Avoid the error message generated by ClickableComponent's addChild method
125     return _component2['default'].prototype.addChild.call(this, child, options);
126   };
127
128   /**
129    * Enable the `Button` element so that it can be activated or clicked. Use this with
130    * {@link Button#disable}.
131    */
132
133
134   Button.prototype.enable = function enable() {
135     _ClickableComponent.prototype.enable.call(this);
136     this.el_.removeAttribute('disabled');
137   };
138
139   /**
140    * Enable the `Button` element so that it cannot be activated or clicked. Use this with
141    * {@link Button#enable}.
142    */
143
144
145   Button.prototype.disable = function disable() {
146     _ClickableComponent.prototype.disable.call(this);
147     this.el_.setAttribute('disabled', 'disabled');
148   };
149
150   /**
151    * This gets called when a `Button` has focus and `keydown` is triggered via a key
152    * press.
153    *
154    * @param {EventTarget~Event} event
155    *        The event that caused this function to get called.
156    *
157    * @listens keydown
158    */
159
160
161   Button.prototype.handleKeyPress = function handleKeyPress(event) {
162
163     // Ignore Space (32) or Enter (13) key operation, which is handled by the browser for a button.
164     if (event.which === 32 || event.which === 13) {
165       return;
166     }
167
168     // Pass keypress handling up for unsupported keys
169     _ClickableComponent.prototype.handleKeyPress.call(this, event);
170   };
171
172   return Button;
173 }(_clickableComponent2['default']);
174
175 _component2['default'].registerComponent('Button', Button);
176 exports['default'] = Button;