-
Notifications
You must be signed in to change notification settings - Fork 0
/
league.html
117 lines (102 loc) · 4.18 KB
/
league.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
<!DOCTYPE html>
<html>
<head>
<!-- head definitions go here -->
<script>
function reset_calculator(just_display) {
document.getElementById('eligible').style.display = 'none';
document.getElementById('not-eligible').style.display = 'none';
if (just_display){
document.getElementById('years-kept').value = '';
document.getElementById('round').value = '';
document.getElementById('udfa').checked = false;
}
}
function toggle_eligible_visibility(id, keeper_cost) {
/* Pass a given ID and this hides it, otherwise makes it visible */
console.log(keeper_cost);
reset_calculator(false);
var eligibility = document.getElementById(id);
if (eligibility.style.display == 'none') {
document.getElementById('cost').innerHTML = keeper_cost.toString() + " round pick";
eligibility.style.display = 'block';
}
}
function determine_eligibility(round, udfa, years_kept) {
var can_be_kept = true;
// Players cannot be kept for more than 2 years, so if they've already kept a player for 2 years, the player is ineligible
if (years_kept > 1) {
return false;
}
// Players drafted before round 3 can never be kept
if (round <= 3) {
return false;
}
if (round <= 3 && years_kept == 1) {
return false;
}
if (udfa){
round = 12;
}
var keeper_cost = "invalid. Please report bug to commish."
if (years_kept == 1){
keeper_cost = Number(round) - (Number(years_kept) + 2) - 2;
}
if (years_kept == 0){
keeper_cost = Number(round) - (Number(years_kept) + 2);
}
// Just to make sure they aren't keepable before 1 because that doesn't make sense
if (keeper_cost < 1){
return false;
}
return keeper_cost;
}
function calculate_keeper_round() {
/* var year = document.getElementById("year").value */;
var round = document.getElementById("round").value;
var udfa = document.getElementById("udfa").checked;
var years_kept = document.getElementById("years-kept").value;
if (years_kept == null || round == null) {
toggle_eligible_visibility("not-eligible");
}
else{
/* console.log(year) */
/* console.log(round) */
/* console.log(udfa) */
/* console.log(years_kept) */
can_be_kept = determine_eligibility(round, udfa, years_kept);
if (can_be_kept == false) {
toggle_eligible_visibility("not-eligible",0);
} else {
toggle_eligible_visibility("eligible", can_be_kept);
}
return false;
}
}
}
</script>
</head>
<body>
<h3>
Keeper Kalculator
</h3>
<form name="keeper" id="keeper" onsubmit="return calculate_keeper_round()">
<!-- <label for="year">Year (between 2017 and 2019):</label>
<input type="number" id="year" name="year" min="2017" max="2019"><br><br> -->
<label for="years-kept">Years kept so far (between 0 and 2):</label>
<input type="number" id="years-kept" name="year" min="0" max="2"><br><br>
<label for="round">Round Drafted (between 1 and 14):</label>
<input type="number" id="round" name="year" min="1" max="14"><br><br>
<input type="checkbox" id="udfa" name="udfa" value="udfa">
<label for="udfa">udfa</label><br><br>
<input type="submit" value="Submit">
</form>
<button type="button" value="Reset" onclick="reset_calculator(true);">Reset</button>
<h3 id="not-eligible" style="display: none;">
A player with the above information is not eligible to be kept.
</h3>
<h3 id="eligible" style="display: none;">
A player with the above information is eligible to be kept as a: <p id="cost" />.
</h3>
</body>
</html>