forked from Grafkom-A-IF-ITS-2018/final-project-inp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol.html
162 lines (148 loc) · 4.85 KB
/
control.html
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<title>Control</title>
<style>
.planet {
display: inline-block;
padding: 15px 25px;
width: 200px;
font-size: 30px;
cursor: pointer;
text-align: center;
border-radius: 20px;
border: none;
background-color: #2095C1;
color: #fff;
font-weight: 700;
box-shadow: 0 7px #999;
text-decoration: none;
outline: none;
}
.planet:hover {background-color: #0F5590}
.planet:active {
background-color: #0F5590;
box-shadow: 0 4px #555;
transform: translateY(7px);
}
.satellite {
display: inline-block;
padding: 15px 25px;
width: 200px;
font-size: 27px;
cursor: pointer;
text-align: center;
border-radius: 50px;
border: none;
background-color: #F27395;
color: #fff;
font-weight: 530;
box-shadow: 0 7px #999;
text-decoration: none;
outline: none;
transition: all 0.6s;
margin: 7px;
}
.satellite span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.6s;
}
.satellite span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -5px;
transition: 0.6s;
}
.satellite:hover span {
padding-right: 20px;
}
.satellite:hover span:after {
opacity: 1;
right: 0;
}
.satellite:hover{background-color: #A0529D;}
.table{
vertical-align: middle;
}
td {
font-size: 30px;
font-weight: 300;
color: #715097;
border-bottom: 0px solid #ddd;
border-top: 0px solid #ddd;
}
th {
background-color: #715097;
color: #fff;
text-align: center;
font-size: 30px;
}
</style>
</head>
<body style="background-image: url('../../assets/pic/1.jpg'); background-attachment: fixed; background-size: 100%;">
<table class="table">
<thead>
<tr>
<th scope="col"></th>
<th scope="col">PLANET</th>
<th scope="col">SATELLITE</th>
</tr>
</thead>
<tbody id='button-data'>
</tbody>
</table>
<script src="http://10.151.254.214:8080/socket.io.js"></script>
<script>
'use strict'
var socket = new io();
socket.connect('http://10.151.252.208:8080');
socket.emit('create', 'controller');
// Sends a message to the server via sockets
function sendMessageToServer(message) {
socket.emit('message', message);
};
function clickButton(id){
console.log(id)
socket.emit('button.planet.click', id)
}
function travelToPlanet(id){
socket.emit('travel', id)
}
sendMessageToServer('The Jorney of Solar System');
</script>
<script>
var request = new XMLHttpRequest();
var data;
request.open('GET', './data/solarsystem.json', false)
request.send()
if(request.status === 200){
data = JSON.parse(request.responseText);
}
var tabelElement = document.getElementById('button-data');
for(var i = 0; i < data.planets.length; i++){
var planetId = data.planets[i].id;
var planetName = data.planets[i].name;
var stringButtonPlanet = `<button onclick=clickButton(${planetId}) class='planet' id='${planetId}'>${planetName}</button>`;
var stringButtonMoons = '';
if(data.planets[i].satellites.length){
for(var j = 0; j < data.planets[i].satellites.length; j++){
var moonId = data.planets[i].satellites[j].id;
var moonName = data.planets[i].satellites[j].name;
stringButtonMoons += `<button onclick=clickButton('${moonId}') class='satellite' id='${moonId}'><span>${moonName}</span></button>`;
}
}
tabelElement.innerHTML += `<tr><td></td><td>${stringButtonPlanet}</td><td>${stringButtonMoons}</td></tr>`;
}
</script>
</body>
</html>