-
Notifications
You must be signed in to change notification settings - Fork 7.5k
/
big-play-button.js
114 lines (96 loc) · 2.68 KB
/
big-play-button.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* @file big-play-button.js
*/
import Button from './button.js';
import Component from './component.js';
import {isPromise, silencePromise} from './utils/promise';
/**
* The initial play button that shows before the video has played. The hiding of the
* `BigPlayButton` get done via CSS and `Player` states.
*
* @extends Button
*/
class BigPlayButton extends Button {
constructor(player, options) {
super(player, options);
this.mouseused_ = false;
this.setIcon('play');
this.on('mousedown', (e) => this.handleMouseDown(e));
}
/**
* Builds the default DOM `className`.
*
* @return {string}
* The DOM `className` for this object. Always returns 'vjs-big-play-button'.
*/
buildCSSClass() {
return 'vjs-big-play-button';
}
/**
* This gets called when a `BigPlayButton` "clicked". See {@link ClickableComponent}
* for more detailed information on what a click can be.
*
* @param {KeyboardEvent|MouseEvent|TouchEvent} event
* The `keydown`, `tap`, or `click` event that caused this function to be
* called.
*
* @listens tap
* @listens click
*/
handleClick(event) {
const playPromise = this.player_.play();
// exit early if clicked via the mouse
if (this.mouseused_ && 'clientX' in event && 'clientY' in event) {
silencePromise(playPromise);
if (this.player_.tech(true)) {
this.player_.tech(true).focus();
}
return;
}
const cb = this.player_.getChild('controlBar');
const playToggle = cb && cb.getChild('playToggle');
if (!playToggle) {
this.player_.tech(true).focus();
return;
}
const playFocus = () => playToggle.focus();
if (isPromise(playPromise)) {
playPromise.then(playFocus, () => {});
} else {
this.setTimeout(playFocus, 1);
}
}
/**
* Event handler that is called when a `BigPlayButton` receives a
* `keydown` event.
*
* @param {KeyboardEvent} event
* The `keydown` event that caused this function to be called.
*
* @listens keydown
*/
handleKeyDown(event) {
this.mouseused_ = false;
super.handleKeyDown(event);
}
/**
* Handle `mousedown` events on the `BigPlayButton`.
*
* @param {MouseEvent} event
* `mousedown` or `touchstart` event that triggered this function
*
* @listens mousedown
*/
handleMouseDown(event) {
this.mouseused_ = true;
}
}
/**
* The text that should display over the `BigPlayButton`s controls. Added to for localization.
*
* @type {string}
* @protected
*/
BigPlayButton.prototype.controlText_ = 'Play Video';
Component.registerComponent('BigPlayButton', BigPlayButton);
export default BigPlayButton;