-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (56 loc) · 1.88 KB
/
index.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
$(function() {
"use strict";
var cards = [$("#first"), $("#second"), $("#third"), $("#fourth"), $("#fifth"), $("#sixth")], socket, i, area = $("#input"), in_area = [], cardtexts = [], m, s, timer_el = $("#timer");
function time() {
s += 1;
if (s == 60) {
m += 1;
s -= 60;
}
timer_el.html(m + ":" + (s < 10 ? '0':'') + s);
setTimeout(function () {
time();
}, 1000);
}
time(0, -1);
function verify() {
var str = area.val(), els = str.split(/(+|\-|\*|\/)/);
}
$(".card").click(function () {
var cursorPos = area.prop('selectionStart');
var v = area.val(),
t = $(this).text();
if(t != '\u232b') {
var textBefore = v.substring(0, cursorPos),
textAfter = v.substring(cursorPos, v.length);
area.val(textBefore + t + textAfter);
area.prop('selectionStart', cursorPos + t.length);
area.prop('selectionEnd', cursorPos + t.length);
} else {
var textBefore = v.substring(0, cursorPos - 1),
textAfter = v.substring(cursorPos, v.length);
area.val(textBefore + textAfter);
area.prop('selectionStart', cursorPos - 1);
area.prop('selectionEnd', cursorPos - 1);
$(this).attr('disabled', 'disabled');
}
verify();
});
area.keyup(function () {
$("#result").text(eval(area.val()));
});
socket = io.connect('http://localhost:1300');
socket.emit('start');
socket.on('new', function (data) {
for (i = 0; i < 6; i += 1) {
cards[i].text(data[i]);
cardtexts[i] = parseInt(data[i]);
}
});
$("#submit").click(function () {
socket.emit('submit', {
solution: area.val(),
time: m * 60 + s
});
});
});