-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime_ui.js
59 lines (41 loc) · 1.92 KB
/
time_ui.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
/*----------------------------------------------------------------------------------------------------------------------------------*/
time_ui_new = function (performance) {
var time_ui = {};
time_ui.performance = performance;
time_ui.input_minute = create_input(time_ui, "set_time(this.ui)");
time_ui.input_second = create_input(time_ui, "set_time(this.ui)");
var minute_table = build_input_table("minutes:", time_ui.input_minute);
var second_table = build_input_table("seconds:", time_ui.input_second);
var table = document.createElement("table");
table.tr = document.createElement("tr");
insert_into_table(table, minute_table);
insert_into_table(table, second_table);
/*
var tr = document.createElement("tr");
var p = document.createElement("p");
table.appendChild(tr);
tr.appendChild(p);
*/
return table;
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function time_penalty_update(data) {
if (data.performance.calculate_time_penalty() != 0)
data.p.innerHTML = "Time penalty: " + data.performance.calculate_time_penalty();
else
data.p.innerHTML = "";
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function parse_int_or_return_zero(val) {
var result = parseInt(val);
if (isNaN(result))
return 0;
return result;
}
/*----------------------------------------------------------------------------------------------------------------------------------*/
function set_time(time_ui) {
var minutes = parse_int_or_return_zero(time_ui.input_minute.value);
var seconds = parse_int_or_return_zero(time_ui.input_second.value);
time_ui.performance.set_time(minutes, seconds);
}
/*----------------------------------------------------------------------------------------------------------------------------------*/