3 exports.__esModule = true;
5 var _clickableComponent = require('./clickable-component.js');
7 var _clickableComponent2 = _interopRequireDefault(_clickableComponent);
9 var _component = require('./component.js');
11 var _component2 = _interopRequireDefault(_component);
13 var _fn = require('./utils/fn.js');
15 var Fn = _interopRequireWildcard(_fn);
17 var _dom = require('./utils/dom.js');
19 var Dom = _interopRequireWildcard(_dom);
21 var _browser = require('./utils/browser.js');
23 var browser = _interopRequireWildcard(_browser);
25 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; } }
27 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
29 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
31 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; }
33 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; } /**
34 * @file poster-image.js
39 * A `ClickableComponent` that handles showing the poster image for the player.
41 * @extends ClickableComponent
43 var PosterImage = function (_ClickableComponent) {
44 _inherits(PosterImage, _ClickableComponent);
47 * Create an instance of this class.
49 * @param {Player} player
50 * The `Player` that this class should attach to.
52 * @param {Object} [options]
53 * The key/value store of player options.
55 function PosterImage(player, options) {
56 _classCallCheck(this, PosterImage);
58 var _this = _possibleConstructorReturn(this, _ClickableComponent.call(this, player, options));
61 player.on('posterchange', Fn.bind(_this, _this.update));
66 * Clean up and dispose of the `PosterImage`.
70 PosterImage.prototype.dispose = function dispose() {
71 this.player().off('posterchange', this.update);
72 _ClickableComponent.prototype.dispose.call(this);
76 * Create the `PosterImage`s DOM element.
79 * The element that gets created.
83 PosterImage.prototype.createEl = function createEl() {
84 var el = Dom.createEl('div', {
85 className: 'vjs-poster',
87 // Don't want poster to be tabbable.
91 // To ensure the poster image resizes while maintaining its original aspect
92 // ratio, use a div with `background-size` when available. For browsers that
93 // do not support `background-size` (e.g. IE8), fall back on using a regular
95 if (!browser.BACKGROUND_SIZE_SUPPORTED) {
96 this.fallbackImg_ = Dom.createEl('img');
97 el.appendChild(this.fallbackImg_);
104 * An {@link EventTarget~EventListener} for {@link Player#posterchange} events.
106 * @listens Player#posterchange
108 * @param {EventTarget~Event} [event]
109 * The `Player#posterchange` event that triggered this function.
113 PosterImage.prototype.update = function update(event) {
114 var url = this.player().poster();
118 // If there's no poster source we should display:none on this component
119 // so it's not still clickable or right-clickable
128 * Set the source of the `PosterImage` depending on the display method.
130 * @param {string} url
131 * The URL to the source for the `PosterImage`.
135 PosterImage.prototype.setSrc = function setSrc(url) {
136 if (this.fallbackImg_) {
137 this.fallbackImg_.src = url;
139 var backgroundImage = '';
141 // Any falsey values should stay as an empty string, otherwise
142 // this will throw an extra error
144 backgroundImage = 'url("' + url + '")';
147 this.el_.style.backgroundImage = backgroundImage;
152 * An {@link EventTarget~EventListener} for clicks on the `PosterImage`. See
153 * {@link ClickableComponent#handleClick} for instances where this will be triggered.
159 * @param {EventTarget~Event} event
160 + The `click`, `tap` or `keydown` event that caused this function to be called.
164 PosterImage.prototype.handleClick = function handleClick(event) {
165 // We don't want a click to trigger playback when controls are disabled
166 if (!this.player_.controls()) {
170 if (this.player_.paused()) {
173 this.player_.pause();
178 }(_clickableComponent2['default']);
180 _component2['default'].registerComponent('PosterImage', PosterImage);
181 exports['default'] = PosterImage;