Skip to content

Commit c03539a

Browse files
Patrick WrightPatrick Wright
Patrick Wright
authored and
Patrick Wright
committed
Added 'up' and 'down' buttons to faders to easily turn on/off a channel
1 parent e9a765e commit c03539a

File tree

2 files changed

+77
-10
lines changed

2 files changed

+77
-10
lines changed

css/fader.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@
5050
text-align: center;
5151
}
5252

53-
.peek {
53+
.peek, .up, .down {
54+
color: black;
5455
margin-top: 5px;
5556
background-color: #d3d3d3;
5657
height: 40px;
5758
opacity: 0.7;
5859
}
5960

60-
.peek:hover {
61+
.peek:hover, .up:hover, .down:hover {
6162
opacity: 1;
6263
}
6364

js/Fader.js

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
*/
55

66
class Fader {
7-
constructor(faderElement) {
7+
constructor(faderElement)
8+
{
89
var valueElement = document.createElement("div");
910
valueElement.setAttribute("class", "value");
1011

@@ -21,6 +22,15 @@ class Fader {
2122

2223
this.peekElement = document.createElement("button");
2324
this.peekElement.setAttribute("class", "peek btn");
25+
this.peekElement.innerHTML = "<i class='bi-eye'></i>";
26+
27+
this.upElement = document.createElement("button");
28+
this.upElement.setAttribute("class", "up btn");
29+
this.upElement.innerHTML = "<i class='bi-arrow-up'></i>";
30+
31+
this.downElement = document.createElement("button");
32+
this.downElement.setAttribute("class", "down btn");
33+
this.downElement.innerHTML = "<i class='bi-arrow-down'></i>";
2434

2535
var labelElement = document.createElement("div");
2636
labelElement.setAttribute("class", "label");
@@ -38,6 +48,8 @@ class Fader {
3848

3949
this.faderElement.appendChild(valueElement);
4050
this.faderElement.appendChild(bodyElement);
51+
this.faderElement.appendChild(this.upElement);
52+
this.faderElement.appendChild(this.downElement);
4153
this.faderElement.appendChild(this.peekElement);
4254
this.faderElement.appendChild(labelElement);
4355

@@ -61,6 +73,8 @@ class Fader {
6173
this.onMouseUp = this.handleMouseUp.bind(this);
6274
this.onPeekDown = this.handlePeekDown.bind(this);
6375
this.onPeekUp = this.handlePeekUp.bind(this);
76+
this.onUpClicked = this.handleUpClicked.bind(this);
77+
this.onDownClicked = this.handleDownClicked.bind(this);
6478

6579
//Apply initial value
6680
this.faderHeight = this.faderBody.offsetHeight;
@@ -72,7 +86,11 @@ class Fader {
7286
this.unlock();
7387
}
7488

75-
handlePeekDown(e) {
89+
/**
90+
* @brief The "Peek" button was pressed
91+
*/
92+
handlePeekDown(e)
93+
{
7694
this.oldValue = this.value;
7795
let percent = this.valueToPercent(this.max);
7896
this.setValuePercent(percent);
@@ -81,15 +99,39 @@ class Fader {
8199
document.addEventListener('touchend', this.onPeekUp);
82100
}
83101

84-
handlePeekUp(e) {
102+
/**
103+
* @brief The "Peek" button was released
104+
*/
105+
handlePeekUp(e)
106+
{
85107
let percent = this.valueToPercent(this.oldValue);
86108
this.setValuePercent(percent);
87109

88110
document.removeEventListener('mouseup', this.onPeekUp);
89111
document.removeEventListener('touchend', this.onPeekUp);
90112
}
113+
114+
/**
115+
* @brief The "Up" button was clicked
116+
*/
117+
handleUpClicked(e)
118+
{
119+
this.setValuePercent(1);
120+
}
121+
122+
/**
123+
* @brief The "Down" button was clicked
124+
*/
125+
handleDownClicked(e)
126+
{
127+
this.setValuePercent(0);
128+
}
91129

92-
handleMouseDown(e) {
130+
/**
131+
* @brief The fader was pressed
132+
*/
133+
handleMouseDown(e)
134+
{
93135
e.preventDefault();
94136

95137
let startY = 0;
@@ -116,6 +158,9 @@ class Fader {
116158
document.addEventListener('touchend', this.onMouseUp);
117159
}
118160

161+
/**
162+
* @brief The fader was dragged
163+
*/
119164
handleMouseMove(e) {
120165
let y = 0;
121166
if (e.type == "mousemove")
@@ -143,6 +188,9 @@ class Fader {
143188
this.setValuePercent(percent);
144189
}
145190

191+
/**
192+
* @brief The fader was released
193+
*/
146194
handleMouseUp() {
147195
this.offsetY = null;
148196

@@ -209,24 +257,42 @@ class Fader {
209257
this.faderFader.start();
210258
}
211259

260+
/**
261+
* @brief Lock the fader so that it cannot be moved by the user
262+
*
263+
* The fader is "locked" by disabling the user input events.
264+
*/
212265
lock()
213266
{
214267
this.handle.removeEventListener('mousedown', this.onMouseDown);
215268
this.handle.removeEventListener('touchstart', this.onMouseDown);
216269
this.peekElement.removeEventListener('mousedown', this.onPeekDown);
217270
this.peekElement.removeEventListener('touchstart', this.onPeekDown);
218-
//this.peekElement.removeEventListener('mouseup', this.onPeekUp);
219-
//this.peekElement.removeEventListener('touchend', this.onPeekUp);
271+
this.upElement.removeEventListener('click', this.onUpClicked);
272+
this.downElement.removeEventListener('click', this.onDownClicked);
273+
274+
//Hide
275+
this.peekElement.style.display = "none";
276+
this.upElement.style.display = "none";
277+
this.downElement.style.display = "none";
220278
}
221279

280+
/**
281+
* @brief Unlcok the fader so that it can be moved by the user
282+
*/
222283
unlock()
223284
{
224285
this.handle.addEventListener('mousedown', this.onMouseDown);
225286
this.handle.addEventListener('touchstart', this.onMouseDown);
226287
this.peekElement.addEventListener('mousedown', this.onPeekDown);
227288
this.peekElement.addEventListener('touchstart', this.onPeekDown);
228-
//this.peekElement.addEventListener('mouseup', this.onPeekUp);
229-
//this.peekElement.addEventListener('touchend', this.onPeekUp);
289+
this.upElement.addEventListener('click', this.onUpClicked);
290+
this.downElement.addEventListener('click', this.onDownClicked);
291+
292+
//Show
293+
this.peekElement.style.display = "";
294+
this.upElement.style.display = "";
295+
this.downElement.style.display = "";
230296
}
231297

232298
setLocked(locked)

0 commit comments

Comments
 (0)