-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaucus.html
More file actions
121 lines (106 loc) · 3.12 KB
/
caucus.html
File metadata and controls
121 lines (106 loc) · 3.12 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Caucus Calculator</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js" type="text/javascript"></script>
<style>
body{
margin:0px auto;
width: 800px;
}
div#container {
text-align: center;
border: 1px solid black;
}
</style>
<script type="text/javascript">
//<![CDATA[
var attendees = 0;
var candidates = 0;
var viability = 0;
var viability_portion = 1;
var count_candidates = function() {
candidates = $('.candidate').length;
$('#candidate_count').html( candidates );
}
var remove_candidate = function(me){
$(me).parent().parent().remove();
count_candidates();
}
$(function(){
$("button#add_candidate").click( function(){
var count=parseInt(1 + ( Math.pow( Math.random(), 2 ) ) * 100);
s="<div class='candidate'>"
s+="<p>"
s+="Name: <input type='text' size='40' autocomplete='off' /> "
s+="Group Count: <input class='group_count' type='text' size='10' autocomplete='off' value='"+count+"' /> "
s+="Delegates: <input class='delegates' type='text' size='10' autocomplete='off' /> "
s+="<a class='candidate_delete' href='javascript:void(0);' onclick='remove_candidate(this);' >Delete</a>"
s+="</p>"
s+="</div>"
$('div#candidates').append(s);
count_candidates();
} );
$("button#calculate").click( function(){
attendees = 0;
$.each($('.candidate'), function(){
attendees += parseInt( $(this).find('.group_count').val() );
} )
$('#attendees').html( attendees );
$.each($('.candidate'), function(){
var group_count = parseInt( $(this).find('.group_count').val() );
$(this).find('.delegates').val( Math.round( $('#delegates').val() * group_count / attendees ) );
} )
switch (candidates) {
case 0:
alert("Sorry, but seems that no one is home.")
viability_portion = "Sorry, but no one is here.";
break;
case 1:
viability_portion = "Majority rule.";
break;
case 2:
viability_portion = "1/4";
viability = attendees / 4;
break;
case 3:
viability_portion = "1/6";
viability = attendees / 6;
break;
default:
viability_portion = "3/20";
viability = 3 * attendees / 20;
break;
}
$('#viability_portion').html( viability_portion );
$('#viability').html( viability );
viability = Math.ceil( viability );
$('#viability').append( " : " );
$('#viability').append( viability );
} );
$("button#add_candidate").click();
$("button#add_candidate").click();
$("button#add_candidate").click();
$("button#add_candidate").click();
$("button#add_candidate").click();
});
//]]>
</script>
</head>
<body>
<div id='container'>
<h1>Caucus Calculator</h1>
<p><label for='delegates'>Delegates:</label>
<input id='delegates' type='text' size='10' autocomplete="off" value='34' /></p>
<p>Total Attendees: <span id='attendees'>0</span></p>
<p>Viability Portion: <span id='viability_portion'>0</span></p>
<p>Viability: <span id='viability'>0</span></p>
<p>Candidate Count: <span id='candidate_count'>0</span></p>
<div id='candidates'></div>
<p>
<button id='add_candidate'>Add Candidate</button>
<button id='calculate'>Calculate</button>
</p>
</div>
</body>
</html>