1 |
|
---|
2 | // The following needs to be kept in sync with the .voting-countries & .voting-points widths in css/eurovision.css
|
---|
3 | var glob_voting_country_and_points_width = (180+35);
|
---|
4 |
|
---|
5 | function transpose_i(i,num_cols, num_rows)
|
---|
6 | {
|
---|
7 | // Map 'i' to (x,y) position in grid layout
|
---|
8 | var x = (i % num_cols);
|
---|
9 | var y = Math.floor(i / num_cols); // affect int division
|
---|
10 |
|
---|
11 | // Transpose, and then reverse engineer what value of 'i' the transposed position needs to be
|
---|
12 | var trans_x = y;
|
---|
13 | var trans_y = x;
|
---|
14 |
|
---|
15 | var trans_i = trans_y * num_rows + trans_x;
|
---|
16 |
|
---|
17 | return trans_i;
|
---|
18 | }
|
---|
19 |
|
---|
20 | function append_to_country_votes(vote_label, votes_json_type, votes_type_total)
|
---|
21 | {
|
---|
22 | // TODO
|
---|
23 | // Figure out why "United Kingdom-J" and not "UnitedKingdom-J"
|
---|
24 |
|
---|
25 | if (gs.documentMetadata[votes_json_type]) {
|
---|
26 | var all_votes_div_width = $('#to-country-votes').width();
|
---|
27 |
|
---|
28 | var $vote_label_div = $('<div>').attr("class","voting-label").append(vote_label);
|
---|
29 | $vote_label_div.append(" (Total: " + gs.documentMetadata[votes_type_total] + ")");
|
---|
30 | $('#to-country-votes').append($vote_label_div);
|
---|
31 |
|
---|
32 | var $vote_points_div = $('<div>').attr("class","voting-points-div");
|
---|
33 |
|
---|
34 | var VotesJSON = eval(gs.documentMetadata[votes_json_type]);
|
---|
35 | var num_countries = VotesJSON.length;
|
---|
36 |
|
---|
37 | var num_cols = Math.floor(all_votes_div_width / glob_voting_country_and_points_width);
|
---|
38 | var num_rows = Math.ceil(num_countries / num_cols);
|
---|
39 | var num_cells = num_cols * num_rows;
|
---|
40 |
|
---|
41 | VotesJSON.sort();
|
---|
42 |
|
---|
43 | var library_name = gs.xsltParams["library_name"];
|
---|
44 | var coll_name = gs.cgiParams["c"];
|
---|
45 |
|
---|
46 | var collect_doc_prefix_url = library_name + "/collection/" + coll_name + "/document/";
|
---|
47 |
|
---|
48 | for (var i=0; i<num_cells; i++) {
|
---|
49 | var trans_i = transpose_i(i,num_cols, num_rows);
|
---|
50 |
|
---|
51 | // By default, they country and points are set to be empty divs
|
---|
52 | var $to_country_name = $('<div>').attr("class","voting voting-country").append("");
|
---|
53 | var $to_country_points = $('<div>').attr("class","voting voting-points").append("");
|
---|
54 | var $a_from_country = $('<span>');
|
---|
55 |
|
---|
56 | // check to see if trans_i position is within array, otherwise default to filler
|
---|
57 | if (trans_i < num_countries) {
|
---|
58 | var from_country = VotesJSON[trans_i];
|
---|
59 | var from_country_points = gs.documentMetadata[from_country];
|
---|
60 | var year = gs.documentMetadata["Year"];
|
---|
61 |
|
---|
62 | if (typeof from_country_points !== 'undefined') {
|
---|
63 | var from_country_base = from_country.replace(/-(T|J)$/,"");
|
---|
64 | var pp_from_country = from_country_base; // in future look to putting spacing back in for countries like United Kingdom
|
---|
65 |
|
---|
66 | var hyphen_vote_type = from_country.match(/-(?:T|J)$/);
|
---|
67 | var from_country_id = "FromCountry-"+from_country_base + year + hyphen_vote_type;
|
---|
68 | var href_from_country = collect_doc_prefix_url + from_country_id;
|
---|
69 |
|
---|
70 | //var $a_from_country = $('<a>').attr("href",href_from_country).append(pp_from_country);
|
---|
71 | var $a_from_country = $('<a>').attr("href",href_from_country);
|
---|
72 |
|
---|
73 | //$from_country_name = $('<div>').attr("class","voting voting-country").append($a_from_country).append(":")
|
---|
74 | $from_country_name = $('<div>').attr("class","voting voting-country").append(pp_from_country).append(":");
|
---|
75 | $from_country_points = $('<div>').attr("class","voting voting-points").append(from_country_points);
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | /*
|
---|
80 | $('#to-country-votes')
|
---|
81 | .append($from_country_name)
|
---|
82 | .append($from_country_points);
|
---|
83 | */
|
---|
84 | $a_from_country
|
---|
85 | .append($from_country_name)
|
---|
86 | .append($from_country_points);
|
---|
87 | $('#to-country-votes')
|
---|
88 | .append($a_from_country);
|
---|
89 |
|
---|
90 | }
|
---|
91 |
|
---|
92 | $('#to-country-votes').append($vote_points_div);
|
---|
93 |
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 |
|
---|
98 | function compare_countries(a,b)
|
---|
99 | {
|
---|
100 | if (a.Country < b.Country) {
|
---|
101 | return -1;
|
---|
102 | }
|
---|
103 | if (a.Country > b.Country) {
|
---|
104 | return 1;
|
---|
105 | }
|
---|
106 |
|
---|
107 | // names must be equal
|
---|
108 | return 0;
|
---|
109 | }
|
---|
110 |
|
---|
111 | function compare_points(a,b)
|
---|
112 | {
|
---|
113 | return a.Points - b.Points;
|
---|
114 | }
|
---|
115 |
|
---|
116 | function append_from_country_votes(vote_type)
|
---|
117 | {
|
---|
118 | if (vote_type != "") {
|
---|
119 | var all_votes_div_width = $('#from-country-votes').width();
|
---|
120 |
|
---|
121 | var votes_country_json_type = "VotesCountryJSON-" + vote_type;
|
---|
122 | var votes_points_json_type = "VotesPointsJSON-" + vote_type;
|
---|
123 | var vote_label = (vote_type == "J") ? "Jury votes" : "Televotes";
|
---|
124 |
|
---|
125 | var $vote_div = $('<div>').attr("class","voting-label").append(vote_label);
|
---|
126 | $('#from-country-votes').append($vote_div);
|
---|
127 |
|
---|
128 | var VotesCountryJSON = eval(gs.documentMetadata[votes_country_json_type]); // map JSON string into data-structure
|
---|
129 | var VotesPointsJSON = eval(gs.documentMetadata[votes_points_json_type]); // map JSON string into data-structure
|
---|
130 |
|
---|
131 | var num_countries = VotesCountryJSON.length;
|
---|
132 |
|
---|
133 | var num_cols = Math.floor(all_votes_div_width / glob_voting_country_and_points_width);
|
---|
134 | var num_rows = Math.ceil(num_countries / num_cols);
|
---|
135 | var num_cells = num_cols * num_rows;
|
---|
136 |
|
---|
137 | var from_country_votes = [];
|
---|
138 |
|
---|
139 | for (var i=0; i<num_countries; i++) {
|
---|
140 | from_country_votes.push({ "Country" : VotesCountryJSON[i], "Points" : VotesPointsJSON[i]})
|
---|
141 | }
|
---|
142 |
|
---|
143 | from_country_votes.sort(compare_countries);
|
---|
144 |
|
---|
145 | var library_name = gs.xsltParams["library_name"];
|
---|
146 | var coll_name = gs.cgiParams["c"];
|
---|
147 |
|
---|
148 | var collect_doc_prefix_url = library_name + "/collection/" + coll_name + "/document/";
|
---|
149 |
|
---|
150 | var year = gs.documentMetadata["FromCountryYear"];
|
---|
151 |
|
---|
152 | for (var i=0; i<num_cells; i++) {
|
---|
153 |
|
---|
154 | var trans_i = transpose_i(i,num_cols, num_rows);
|
---|
155 |
|
---|
156 | var $to_country_name = $('<div>').attr("class","voting voting-country").append("");
|
---|
157 | var $to_country_points = $('<div>').attr("class","voting voting-points").append("");
|
---|
158 | var $a_to_country = $('<span>');
|
---|
159 |
|
---|
160 | // check to see if trans_i position is within array, otherwise default to filler
|
---|
161 | if (trans_i < num_countries) {
|
---|
162 | var pp_to_country = from_country_votes[trans_i].Country;
|
---|
163 | var to_country = pp_to_country.replace(/\s+/g,"");
|
---|
164 |
|
---|
165 | var to_country_points = from_country_votes[trans_i].Points;
|
---|
166 |
|
---|
167 | if (typeof to_country_points !== 'undefined') {
|
---|
168 |
|
---|
169 | //var doc_id = gs.cgiParams["d"];
|
---|
170 | //var hyphen_vote_type = doc_id.match(/-(?:T|J)$/);
|
---|
171 | var to_country_id = to_country + year;
|
---|
172 | var href_to_country = collect_doc_prefix_url + to_country_id;
|
---|
173 |
|
---|
174 | //$a_to_country = $('<a>').attr("href",href_to_country).append(pp_to_country);
|
---|
175 | $a_to_country = $('<a>').attr("href",href_to_country)
|
---|
176 |
|
---|
177 | $to_country_name = $('<div>').attr("class","voting voting-country").append(pp_to_country).append(":");
|
---|
178 | //$to_country_name = $('<div>').attr("class","voting voting-country").append($a_to_country).append(":");
|
---|
179 | $to_country_points = $('<div>').attr("class","voting voting-points").append(to_country_points);
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | //if ($a_to_country) {
|
---|
184 | $a_to_country
|
---|
185 | .append($to_country_name)
|
---|
186 | .append($to_country_points);
|
---|
187 | $('#from-country-votes')
|
---|
188 | .append($a_to_country);
|
---|
189 | ///}
|
---|
190 | /*
|
---|
191 | else {
|
---|
192 | $('#from-country-votes')
|
---|
193 | .append($to_country_name)
|
---|
194 | .append($to_country_points);
|
---|
195 | }
|
---|
196 | */
|
---|
197 | }
|
---|
198 | }
|
---|
199 | }
|
---|
200 |
|
---|