-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
visualizer_button.js
85 lines (72 loc) · 2.48 KB
/
visualizer_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
/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.provide('shakaDemo.VisualizerButton');
/**
* A custom UI overflow button, to allow users to show the visualizer.
* This cannot actually extend shaka.ui.Element, as that class does not exist
* at load-time when in uncompiled mode.
* @extends {shaka.ui.Element}
*/
shakaDemo.VisualizerButton = class extends shaka.ui.Element {
/**
* @param {!HTMLElement} parent
* @param {!shaka.ui.Controls} controls
*/
constructor(parent, controls) {
super(parent, controls);
/** @private {!HTMLButtonElement} */
this.button_ = /** @type {!HTMLButtonElement} */ (
document.createElement('button'));
this.button_.classList.add('shaka-pip-button');
this.button_.classList.add('shaka-tooltip');
/** @private {!HTMLElement} */
this.icon_ = /** @type {!HTMLElement} */ (
document.createElement('i'));
this.icon_.classList.add('material-icons-round');
this.setIcon_();
this.button_.appendChild(this.icon_);
const label = document.createElement('label');
label.classList.add('shaka-overflow-button-label');
label.classList.add('shaka-overflow-menu-only');
this.nameSpan_ = document.createElement('span');
label.appendChild(this.nameSpan_);
this.nameSpan_.textContent = 'Buffer Visualizer';
/** @private {!HTMLElement} */
this.currentPipState_ = /** @type {!HTMLElement} */ (
document.createElement('span'));
this.currentPipState_.classList.add('shaka-current-selection-span');
label.appendChild(this.currentPipState_);
this.button_.appendChild(label);
this.parent.appendChild(this.button_);
this.eventManager.listen(this.button_, 'click', () => {
shakaDemoMain.setIsVisualizerActive(
!shakaDemoMain.getIsVisualizerActive());
shakaDemoMain.remakeHash();
this.setIcon_();
});
}
/** @private */
setIcon_() {
if (shakaDemoMain.getIsVisualizerActive()) {
this.icon_.textContent = 'bar_chart';
} else {
this.icon_.textContent = 'add_chart';
}
}
};
/**
* @implements {shaka.extern.IUIElement.Factory}
* @final
*/
shakaDemo.VisualizerButton.Factory = class {
/** @override */
create(rootElement, controls) {
return new shakaDemo.VisualizerButton(rootElement, controls);
}
};
// This button is registered inside setup in shakaDemo.Main, rather than
// statically here, since shaka.ui.Controls does not exist in this stage of the
// load process.