203f0e222535f605278d1624d9910f7a8e862675
[yaffs-website] / control-bar / fullscreen-toggle.js
1 'use strict';
2
3 exports.__esModule = true;
4
5 var _button = require('../button.js');
6
7 var _button2 = _interopRequireDefault(_button);
8
9 var _component = require('../component.js');
10
11 var _component2 = _interopRequireDefault(_component);
12
13 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
14
15 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16
17 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; }
18
19 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; } /**
20                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 * @file fullscreen-toggle.js
21                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 */
22
23
24 /**
25  * Toggle fullscreen video
26  *
27  * @extends Button
28  */
29 var FullscreenToggle = function (_Button) {
30   _inherits(FullscreenToggle, _Button);
31
32   /**
33    * Creates an instance of this class.
34    *
35    * @param {Player} player
36    *        The `Player` that this class should be attached to.
37    *
38    * @param {Object} [options]
39    *        The key/value store of player options.
40    */
41   function FullscreenToggle(player, options) {
42     _classCallCheck(this, FullscreenToggle);
43
44     var _this = _possibleConstructorReturn(this, _Button.call(this, player, options));
45
46     _this.on(player, 'fullscreenchange', _this.handleFullscreenChange);
47     return _this;
48   }
49
50   /**
51    * Builds the default DOM `className`.
52    *
53    * @return {string}
54    *         The DOM `className` for this object.
55    */
56
57
58   FullscreenToggle.prototype.buildCSSClass = function buildCSSClass() {
59     return 'vjs-fullscreen-control ' + _Button.prototype.buildCSSClass.call(this);
60   };
61
62   /**
63    * Handles fullscreenchange on the player and change control text accordingly.
64    *
65    * @param {EventTarget~Event} [event]
66    *        The {@link Player#fullscreenchange} event that caused this function to be
67    *        called.
68    *
69    * @listens Player#fullscreenchange
70    */
71
72
73   FullscreenToggle.prototype.handleFullscreenChange = function handleFullscreenChange(event) {
74     if (this.player_.isFullscreen()) {
75       this.controlText('Non-Fullscreen');
76     } else {
77       this.controlText('Fullscreen');
78     }
79   };
80
81   /**
82    * This gets called when an `FullscreenToggle` is "clicked". See
83    * {@link ClickableComponent} for more detailed information on what a click can be.
84    *
85    * @param {EventTarget~Event} [event]
86    *        The `keydown`, `tap`, or `click` event that caused this function to be
87    *        called.
88    *
89    * @listens tap
90    * @listens click
91    */
92
93
94   FullscreenToggle.prototype.handleClick = function handleClick(event) {
95     if (!this.player_.isFullscreen()) {
96       this.player_.requestFullscreen();
97     } else {
98       this.player_.exitFullscreen();
99     }
100   };
101
102   return FullscreenToggle;
103 }(_button2['default']);
104
105 /**
106  * The text that should display over the `FullscreenToggle`s controls. Added for localization.
107  *
108  * @type {string}
109  * @private
110  */
111
112
113 FullscreenToggle.prototype.controlText_ = 'Fullscreen';
114
115 _component2['default'].registerComponent('FullscreenToggle', FullscreenToggle);
116 exports['default'] = FullscreenToggle;