-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlight.js
108 lines (88 loc) · 2.28 KB
/
light.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
var urlDir = "./";
var lightOnButtonObj, lightOffButtonObj;
function requestPage(fileName, procFunc){
document.getElementById(fileName).disabled = true;
fetch(urlDir + fileName + ".html")
.then((res) => {
if (!res.ok) {
throw new Error(`${res.status} ${res.statusText}`);
}
return res.blob();
})
.then((blob) => {
procFunc();
})
.catch((reason) => {
console.log(reason);
});
}
function requestCommandPage(){
document.getElementById("comRetVal").value = "Processing : " + document.getElementById("command").value;
command = document.getElementById('command').value;
document.getElementById("command").value = "";
data = "command=" + command
fetch(urlDir + "getCommand.html",
{
method: 'POST',
cache: 'no-cache',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
},
body: data
})
.then((res) => {
if (!res.ok) {
throw new Error(`${res.status} ${res.statusText}`);
}
return res.text();
})
.then((text) => {
document.getElementById("comRetVal").value = text;
})
.catch((reason) => {
console.log(reason);
});
}
function lightOnProc(){
lightOnButtonObj.style.backgroundColor = 'yellow';
lightOffButtonObj.style.backgroundColor = 'gray';
lightOffButtonObj.disabled = false;
}
function lightOffProc(){
lightOnButtonObj.style.backgroundColor = 'gray';
lightOffButtonObj.style.backgroundColor = 'yellow';
lightOnButtonObj.disabled = false;
}
function zoomInProc(){
//do nothing
}
function zoomOutProc(){
//do nothing
}
function zoomIn(){
requestPage("zoomIn", zoomInProc);
document.getElementById("zoomIn").disabled = false;
}
function zoomOut(){
requestPage("zoomOut", zoomOutProc);
document.getElementById("zoomOut").disabled = false;
}
function lightOn(){
requestPage("lightOn", lightOnProc);
}
function lightOff(){
requestPage("lightOff", lightOffProc);
}
function comSend(){
requestCommandPage();
}
window.onload = function(){
lightOnButtonObj = document.getElementById("lightOn");
lightOffButtonObj = document.getElementById("lightOff");
if(lightOnButtonObj != null && lightOffButtonObj != null){
lightOff();
document.getElementById("lightOn").onclick = lightOn;
document.getElementById("lightOff").onclick = lightOff;
document.getElementById("comSend").onclick = comSend;
}
}