-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
415 lines (370 loc) · 11.3 KB
/
index.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="height=device-height, user-scalable=no, initial-scale=1, maximum-scale=1" />
<meta charset="utf-8" />
<base href="https://fregate.github.io/web/" target="_blank">
<title>Все в кёрлинг!</title>
<link rel="stylesheet" href="curl/app.css" type="text/css" />
<script src="curl/phaser.js"></script>
<script src="curl/app.js"></script>
<style>
body {
margin: 0px;
padding: 0px;
background-color: #001640;
}
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 10%; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content */
.modal-content {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
border: 1px solid #888;
width: 80%;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.4s;
animation-name: animatetop;
animation-duration: 0.4s
}
/* Add Animation */
@-webkit-keyframes animatetop {
from {top:-300px; opacity:0}
to {top:0; opacity:1}
}
@keyframes animatetop {
from {top:-300px; opacity:0}
to {top:0; opacity:1}
}
/* The Close Button */
.close {
color: white;
float: right;
font-size: 38px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
.modal-header{
padding: 2px 16px;
background-color: #367cde;
color: white;
}
.error {
background-color: #e23d10;
}
.modal-body {padding: 2px 16px;}
.modal-footer {
padding: 2px 16px;
background-color: #367cde;
color: white;
}
.input-container {
position: relative;
margin: 0 10px 25px;
}
.input-container input {
outline: none;
z-index: 1;
position: relative;
background: #f0f0f0;
width: 100%;
height: 60px;
border: 0;
color: #212121;
font-size: 24px;
font-weight: 400;
}
.input-container input:focus ~ label {
color: #9d9d9d;
-webkit-transform: translate(-12%, -50%) scale(0.75);
transform: translate(-12%, -50%) scale(0.75);
}
.input-container input:focus ~ .bar:before, .input-container input:focus ~ .bar:after {
width: 100%;
}
.input-container input:valid ~ label {
color: #9d9d9d;
-webkit-transform: translate(-12%, -50%) scale(0.75);
transform: translate(-12%, -50%) scale(0.75);
}
.input-container label {
position: absolute;
top: 0;
left: 0;
color: #757575;
font-size: 24px;
font-weight: 300;
line-height: 60px;
-webkit-transition: 0.2s ease;
transition: 0.2s ease;
}
.input-container .bar {
position: absolute;
left: 0;
bottom: 0;
background: #757575;
width: 100%;
height: 1px;
}
.input-container .bar:before, .input-container .bar:after {
content: '';
position: absolute;
background: #367cde;
width: 0;
height: 2px;
-webkit-transition: .2s ease;
transition: .2s ease;
}
.input-container .bar:before {
left: 0%;
}
.input-container .bar:after {
right: 0%;
}
.button-container {
margin: 0 10px 25px;
text-align: center;
}
.button-container button {
outline: 0;
cursor: pointer;
position: relative;
display: inline-block;
background: 0;
width: 240px;
border: 2px solid #e3e3e3;
padding: 20px 0;
font-size: 24px;
font-weight: 600;
line-height: 1;
text-transform: uppercase;
overflow: hidden;
-webkit-transition: .3s ease;
transition: .3s ease;
}
.button-container button span {
position: relative;
z-index: 1;
color: #78adf6;
-webkit-transition: .3s ease;
transition: .3s ease;
}
.button-container button:before {
content: '';
position: absolute;
top: 50%;
left: 50%;
display: block;
background: #367cde;
width: 30px;
height: 30px;
border-radius: 100%;
margin: -15px 0 0 -15px;
opacity: 0;
-webkit-transition: .3s ease;
transition: .3s ease;
}
.button-container button:hover, .button-container button:active, .button-container button:focus {
border-color: #367cde;
}
.button-container button:hover span, .button-container button:active span, .button-container button:focus span {
color: #367cde;
}
.button-container button:active span, .button-container button:focus span {
color: #ffffff;
}
.button-container button:active:before, .button-container button:focus:before {
opacity: 1;
-webkit-transform: scale(10);
transform: scale(10);
}
#scores p:first-child {
background-color: #f0f0fc;
}
.rgone {
font-family: 'Times New Roman', Times, serif;
font-style:normal;
}
</style>
</head>
<body>
<div id="saveModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<span class="close">×</span>
<h2>В рекорды!</h2>
</div>
<div class="modal-body">
<p>Здесь необходимо ввести имя, что бы можно было потом узнать, кто это достиг такого результата (<span id="result"></span>)</p>
<div class="input-container">
<input type="text" id="Username" required="required" autofocus>
<div class="bar"></div>
</div>
<div class="button-container">
<button id="btnSave"><span>СОХРАНИТЬ</span></button>
</div>
</div>
</div>
</div>
<div id="scoresModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<span class="close">×</span>
<h2>Рекорды</h2>
</div>
<div class="modal-body" id="scores">
</div>
</div>
</div>
<div id="errorModalSave" class="modal">
<!-- Modal content -->
<div class="modal-content">
<div class="modal-header error">
<span class="close">×</span>
<h2>Ошибка!</h2>
</div>
<div class="modal-body">
<p>Упс! Не получается подключиться к базе данных для сохранения этого выдающегося результата. Гугл подвел!</p>
<p>Шлите апельсины бочками, в смысле, достойные результаты скриншотами.</p>
</div>
</div>
</div>
<div id="errorModalScores" class="modal">
<!-- Modal content -->
<div class="modal-content">
<div class="modal-header error">
<span class="close">×</span>
<h2>Ошибка!</h2>
</div>
<div class="modal-body">
<p>Упс! Не получается подключиться к базе данных и показать самые выдающиеся результаты. Гугл подвел!</p>
<p>Но наверняка можно улучшить! Дерзай! Жми и играй!</p>
</div>
</div>
</div>
<script src="https://www.gstatic.com/firebasejs/3.6.5/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyBsxmDG4ZRrO6AmmstGvNyPh-pLK6phYRM",
authDomain: "curling-817ad.firebaseapp.com",
databaseURL: "https://curling-817ad.firebaseio.com",
storageBucket: "curling-817ad.appspot.com",
messagingSenderId: "802232820682"
};
firebase.initializeApp(config);
</script>
<script>
function databaseAnonymousAuth(ctx, fnCallback) {
if (firebase.auth().currentUser) {
fnCallback.apply(ctx);
return;
}
firebase.auth().onAuthStateChanged(function (user) {
if (user) {
console.log("onAuthStateChanged", user);
fnCallback.apply(ctx);
}
});
firebase.auth().signInAnonymously().catch(function (error) {
console.error(error);
});
}
function showNameBox(points, ctx, fnCallback) {
if (!firebase.auth().currentUser) {
var modal = document.getElementById('errorModalSave');
modal.style.display = "block";
return;
}
// Get the modal
var modal = document.getElementById('saveModal');
modal.style.display = "block";
var resSpan = document.getElementById('result');
resSpan.innerHTML = "";
resSpan.appendChild(document.createTextNode(points));
var btnw = document.getElementById('btnSave');
btnw.onclick = function () {
var txtUsrname = document.getElementById('Username');
if (txtUsrname.value == '') {
console.log("no name!");
return;
}
var entry = firebase.database().ref('highscores').push();
entry.set({
pts: points,
date: new Date().getTime(),
name: txtUsrname.value
}).catch(function (error) {
console.log(error);
});
modal.style.display = "none";
console.log("save with " + entry.key);
fnCallback.apply(ctx);
}
}
function showHighscores() {
if (!firebase.auth().currentUser) {
var modal = document.getElementById('errorModalScores');
modal.style.display = "block";
return;
}
var count = 11;
var modal = document.getElementById('scoresModal');
modal.style.display = "block";
var divScores = document.getElementById('scores');
while (divScores.firstChild) {
divScores.removeChild(divScores.firstChild);
}
var options = {
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: 'numeric',
minute: 'numeric'
};
var tableRef = firebase.database().ref('highscores').orderByChild("pts").limitToLast(count);
tableRef.on('child_added', function (data) {
console.log("child_added", data.val(), data.key);
var obj = data.val();
var d = new Date();
d.setTime(obj.date);
var nodeP = document.createElement("p");
nodeP.innerHTML = "<b>" + obj.pts + "</b> ... " + obj.name + " ... " + d.toLocaleString("ru", options);
divScores.insertBefore(nodeP, divScores.firstChild);
});
}
var spans = document.getElementsByClassName("close");
// When the user clicks on <span> (x), close the modal
[].forEach.call(spans, function (el, idx, arr) {
el.onclick = function () {
var modals = document.getElementsByClassName('modal');
[].forEach.call(modals, function (el, idx, arr) {
el.style.display = 'none';
});
}
});
</script>
</body>
</html>