-
Notifications
You must be signed in to change notification settings - Fork 7.5k
/
close-button.js
94 lines (87 loc) · 2.33 KB
/
close-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
/**
* @file close-button.js
*/
import Button from './button';
import Component from './component';
/** @import Player from './player' */
/**
* The `CloseButton` is a `{@link Button}` that fires a `close` event when
* it gets clicked.
*
* @extends Button
*/
class CloseButton extends Button {
/**
* Creates an instance of the this class.
*
* @param {Player} player
* The `Player` that this class should be attached to.
*
* @param {Object} [options]
* The key/value store of player options.
*/
constructor(player, options) {
super(player, options);
this.setIcon('cancel');
this.controlText(options && options.controlText || this.localize('Close'));
}
/**
* Builds the default DOM `className`.
*
* @return {string}
* The DOM `className` for this object.
*/
buildCSSClass() {
return `vjs-close-button ${super.buildCSSClass()}`;
}
/**
* This gets called when a `CloseButton` gets clicked. See
* {@link ClickableComponent#handleClick} for more information on when
* this will be triggered
*
* @param {Event} event
* The `keydown`, `tap`, or `click` event that caused this function to be
* called.
*
* @listens tap
* @listens click
* @fires CloseButton#close
*/
handleClick(event) {
/**
* Triggered when the a `CloseButton` is clicked.
*
* @event CloseButton#close
* @type {Event}
*
* @property {boolean} [bubbles=false]
* set to false so that the close event does not
* bubble up to parents if there is no listener
*/
this.trigger({type: 'close', bubbles: false});
}
/**
* Event handler that is called when a `CloseButton` receives a
* `keydown` event.
*
* By default, if the key is Esc, it will trigger a `click` event.
*
* @param {KeyboardEvent} event
* The `keydown` event that caused this function to be called.
*
* @listens keydown
*/
handleKeyDown(event) {
// Esc button will trigger `click` event
if (event.key === 'Escape') {
event.preventDefault();
event.stopPropagation();
this.trigger('click');
} else {
// Pass keypress handling up for unsupported keys
super.handleKeyDown(event);
}
}
}
Component.registerComponent('CloseButton', CloseButton);
export default CloseButton;