-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
51 lines (48 loc) · 1.5 KB
/
Copy pathmain.js
File metadata and controls
51 lines (48 loc) · 1.5 KB
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
var inputs, index, mainColor;
$(function(){
inputs = document.getElementsByTagName('input');
for (index = 0; index < inputs.length; index++) {
if (inputs[index].type == 'color') {
inputs[index].addEventListener('change', update, false);
}
else {
inputs[index].addEventListener('change', sendcmd, false);
}
}
});
function led_on() {
$.ajax('/test/on')
.done(function (response) {
console.log(response);
});
$('#toggle').html('<button class=\'btn btn-secondary m-2\' onclick=\'led_off()\'>OFF</button>');
}
function led_off() {
$.ajax('/test/off')
.done(function (response) {
console.log(response);
});
$('#toggle').html('<button class=\'btn btn-primary m-2\' onclick=\'led_on()\' id=\'on\'>ON</button>');
}
function sendcmd(event) {
$.ajax(event.target.id + '/' + event.target.value).done((response) => {
console.log(response);
});
}
function sendvar(vrb) {
if(vrb == 'allSame'){
vrb = vrb + '/' + mainColor;
}
$.ajax('/' + vrb).done((response) => {
console.log(response);
});
}
function update(event) {
console.log(event.target.id + event.target.value);
if (event.target.id == 'strip1') {
mainColor = event.target.value.substring(1);
}
$.ajax(event.target.id + '/' + event.target.value.substring(1)).done((response) => {
console.log(response);
});
}