liquid_feedback_frontend
diff static/js/voting.js @ 519:7492497005bd
Fixed voting for non javascript capable browser, removed browser warning
author | bsw |
---|---|
date | Mon Apr 16 23:27:07 2012 +0200 (2012-04-16) |
parents | 00d1004545f1 |
children | ea3d3757ddc3 |
line diff
1.1 --- a/static/js/voting.js Sun Apr 15 18:26:06 2012 +0200 1.2 +++ b/static/js/voting.js Mon Apr 16 23:27:07 2012 +0200 1.3 @@ -1,117 +1,36 @@ 1.4 -voting_text_approval_single = "Approval" 1.5 -voting_text_approval_multi = "Approval" 1.6 -voting_text_first_preference_single = "Approval (first preference)" 1.7 -voting_text_first_preference_multi = "Approval (first preference)" 1.8 -voting_text_second_preference_single = "Approval (second preference)" 1.9 -voting_text_second_preference_multi = "Approval (second preference)" 1.10 -voting_text_third_preference_single = "Approval (third preference)" 1.11 -voting_text_third_preference_multi = "Approval (third preference)" 1.12 -voting_text_numeric_preference_single = "Approval (#th preference)" 1.13 -voting_text_numeric_preference_multi = "Approval (#th preference)" 1.14 -voting_text_abstention_single = "Abstention" 1.15 -voting_text_abstention_multi = "Abstention" 1.16 -voting_text_disapproval_above_one_single = "Disapproval (prefer to lower block)" 1.17 -voting_text_disapproval_above_one_multi = "Disapproval (prefer to lower block)" 1.18 -voting_text_disapproval_above_many_single = "Disapproval (prefer to lower blocks)" 1.19 -voting_text_disapproval_above_many_multi = "Disapproval (prefer to lower blocks)" 1.20 -voting_text_disapproval_above_last_single = "Disapproval (prefer to last block)" 1.21 -voting_text_disapproval_above_last_multi = "Disapproval (prefer to last block)" 1.22 -voting_text_disapproval_single = "Disapproval" 1.23 -voting_text_disapproval_multi = "Disapproval" 1.24 +if (!jsFail) { 1.25 + voting_text_approval_single = "Approval" 1.26 + voting_text_approval_multi = "Approval" 1.27 + voting_text_first_preference_single = "Approval (first preference)" 1.28 + voting_text_first_preference_multi = "Approval (first preference)" 1.29 + voting_text_second_preference_single = "Approval (second preference)" 1.30 + voting_text_second_preference_multi = "Approval (second preference)" 1.31 + voting_text_third_preference_single = "Approval (third preference)" 1.32 + voting_text_third_preference_multi = "Approval (third preference)" 1.33 + voting_text_numeric_preference_single = "Approval (#th preference)" 1.34 + voting_text_numeric_preference_multi = "Approval (#th preference)" 1.35 + voting_text_abstention_single = "Abstention" 1.36 + voting_text_abstention_multi = "Abstention" 1.37 + voting_text_disapproval_above_one_single = "Disapproval (prefer to lower block)" 1.38 + voting_text_disapproval_above_one_multi = "Disapproval (prefer to lower block)" 1.39 + voting_text_disapproval_above_many_single = "Disapproval (prefer to lower blocks)" 1.40 + voting_text_disapproval_above_many_multi = "Disapproval (prefer to lower blocks)" 1.41 + voting_text_disapproval_above_last_single = "Disapproval (prefer to last block)" 1.42 + voting_text_disapproval_above_last_multi = "Disapproval (prefer to last block)" 1.43 + voting_text_disapproval_single = "Disapproval" 1.44 + voting_text_disapproval_multi = "Disapproval" 1.45 1.46 -function voting_setCategoryHeadings() { 1.47 - var approvalCount = 0; 1.48 - var disapprovalCount = 0; 1.49 - var sections = document.getElementById("voting").childNodes; 1.50 - for (var i=0; i<sections.length; i++) { 1.51 - var section = sections[i]; 1.52 - if (section.className == "approval") approvalCount++; 1.53 - if (section.className == "disapproval") disapprovalCount++; 1.54 - } 1.55 - var approvalIndex = 0; 1.56 - var disapprovalIndex = 0; 1.57 - for (var i=0; i<sections.length; i++) { 1.58 - var section = sections[i]; 1.59 - if ( 1.60 - section.className == "approval" || 1.61 - section.className == "abstention" || 1.62 - section.className == "disapproval" 1.63 - ) { 1.64 - var setHeading = function(heading) { 1.65 - var headingNodes = section.childNodes; 1.66 - for (var j=0; j<headingNodes.length; j++) { 1.67 - var headingNode = headingNodes[j]; 1.68 - if (headingNode.className == "cathead") { 1.69 - headingNode.textContent = heading; 1.70 - } 1.71 - } 1.72 - } 1.73 - var count = 0; 1.74 - var entries = section.childNodes; 1.75 - for (var j=0; j<entries.length; j++) { 1.76 - var entry = entries[j]; 1.77 - if (entry.className == "movable") count++; 1.78 - } 1.79 - if (section.className == "approval") { 1.80 - if (approvalCount > 1) { 1.81 - if (approvalIndex == 0) { 1.82 - if (count == 1) setHeading(voting_text_first_preference_single); 1.83 - else setHeading(voting_text_first_preference_multi); 1.84 - } else if (approvalIndex == 1) { 1.85 - if (count == 1) setHeading(voting_text_second_preference_single); 1.86 - else setHeading(voting_text_second_preference_multi); 1.87 - } else if (approvalIndex == 2) { 1.88 - if (count == 1) setHeading(voting_text_third_preference_single); 1.89 - else setHeading(voting_text_third_preference_multi); 1.90 - } else { 1.91 - var text; 1.92 - if (count == 1) text = voting_text_numeric_preference_single; 1.93 - else text = voting_text_numeric_preference_multi; 1.94 - text = text.replace(/#/, "" + (approvalIndex + 1)) 1.95 - setHeading(text); 1.96 - } 1.97 - } else { 1.98 - if (count == 1) setHeading(voting_text_approval_single); 1.99 - else setHeading(voting_text_approval_multi); 1.100 - } 1.101 - approvalIndex++; 1.102 - } else if (section.className == "abstention") { 1.103 - if (count == 1) setHeading(voting_text_abstention_single); 1.104 - else setHeading(voting_text_abstention_multi); 1.105 - } else if (section.className == "disapproval") { 1.106 - if (disapprovalCount > disapprovalIndex + 2) { 1.107 - if (count == 1) setHeading(voting_text_disapproval_above_many_single); 1.108 - else setHeading(voting_text_disapproval_above_many_multi); 1.109 - } else if (disapprovalCount == 2 && disapprovalIndex == 0) { 1.110 - if (count == 1) setHeading(voting_text_disapproval_above_one_single); 1.111 - else setHeading(voting_text_disapproval_above_one_multi); 1.112 - } else if (disapprovalIndex == disapprovalCount - 2) { 1.113 - if (count == 1) setHeading(voting_text_disapproval_above_last_single); 1.114 - else setHeading(voting_text_disapproval_above_last_multi); 1.115 - } else { 1.116 - if (count == 1) setHeading(voting_text_disapproval_single); 1.117 - else setHeading(voting_text_disapproval_multi); 1.118 - } 1.119 - disapprovalIndex++; 1.120 - } 1.121 + function voting_setCategoryHeadings() { 1.122 + var approvalCount = 0; 1.123 + var disapprovalCount = 0; 1.124 + var sections = document.getElementById("voting").childNodes; 1.125 + for (var i=0; i<sections.length; i++) { 1.126 + var section = sections[i]; 1.127 + if (section.className == "approval") approvalCount++; 1.128 + if (section.className == "disapproval") disapprovalCount++; 1.129 } 1.130 - } 1.131 -} 1.132 -function voting_move(element, up, dropX, dropY) { 1.133 - if (typeof(element) == "string") element = document.getElementById(element); 1.134 - var mouse = (up == null); 1.135 - var oldParent = element.parentNode; 1.136 - if (mouse) var centerY = dropY + element.clientHeight / 2; 1.137 - var approvalCount = 0; 1.138 - var disapprovalCount = 0; 1.139 - var mainDiv = document.getElementById("voting"); 1.140 - var sections = mainDiv.childNodes; 1.141 - for (var i=0; i<sections.length; i++) { 1.142 - var section = sections[i]; 1.143 - if (section.className == "approval") approvalCount++; 1.144 - if (section.className == "disapproval") disapprovalCount++; 1.145 - } 1.146 - if (mouse) { 1.147 + var approvalIndex = 0; 1.148 + var disapprovalIndex = 0; 1.149 for (var i=0; i<sections.length; i++) { 1.150 var section = sections[i]; 1.151 if ( 1.152 @@ -119,36 +38,81 @@ 1.153 section.className == "abstention" || 1.154 section.className == "disapproval" 1.155 ) { 1.156 - if ( 1.157 - centerY >= section.offsetTop && 1.158 - centerY < section.offsetTop + section.clientHeight 1.159 - ) { 1.160 - var entries = section.childNodes; 1.161 - for (var j=0; j<entries.length; j++) { 1.162 - var entry = entries[j]; 1.163 - if (entry.className == "movable") { 1.164 - if (centerY < entry.offsetTop + entry.clientHeight / 2) { 1.165 - if (element != entry) { 1.166 - oldParent.removeChild(element); 1.167 - section.insertBefore(element, entry); 1.168 - } 1.169 - break; 1.170 - } 1.171 + var setHeading = function(heading) { 1.172 + var headingNodes = section.childNodes; 1.173 + for (var j=0; j<headingNodes.length; j++) { 1.174 + var headingNode = headingNodes[j]; 1.175 + if (headingNode.className == "cathead") { 1.176 + headingNode.textContent = heading; 1.177 } 1.178 } 1.179 - if (j == entries.length) { 1.180 - oldParent.removeChild(element); 1.181 - section.appendChild(element); 1.182 + } 1.183 + var count = 0; 1.184 + var entries = section.childNodes; 1.185 + for (var j=0; j<entries.length; j++) { 1.186 + var entry = entries[j]; 1.187 + if (entry.className == "movable") count++; 1.188 + } 1.189 + if (section.className == "approval") { 1.190 + if (approvalCount > 1) { 1.191 + if (approvalIndex == 0) { 1.192 + if (count == 1) setHeading(voting_text_first_preference_single); 1.193 + else setHeading(voting_text_first_preference_multi); 1.194 + } else if (approvalIndex == 1) { 1.195 + if (count == 1) setHeading(voting_text_second_preference_single); 1.196 + else setHeading(voting_text_second_preference_multi); 1.197 + } else if (approvalIndex == 2) { 1.198 + if (count == 1) setHeading(voting_text_third_preference_single); 1.199 + else setHeading(voting_text_third_preference_multi); 1.200 + } else { 1.201 + var text; 1.202 + if (count == 1) text = voting_text_numeric_preference_single; 1.203 + else text = voting_text_numeric_preference_multi; 1.204 + text = text.replace(/#/, "" + (approvalIndex + 1)) 1.205 + setHeading(text); 1.206 + } 1.207 + } else { 1.208 + if (count == 1) setHeading(voting_text_approval_single); 1.209 + else setHeading(voting_text_approval_multi); 1.210 } 1.211 - break; 1.212 + approvalIndex++; 1.213 + } else if (section.className == "abstention") { 1.214 + if (count == 1) setHeading(voting_text_abstention_single); 1.215 + else setHeading(voting_text_abstention_multi); 1.216 + } else if (section.className == "disapproval") { 1.217 + if (disapprovalCount > disapprovalIndex + 2) { 1.218 + if (count == 1) setHeading(voting_text_disapproval_above_many_single); 1.219 + else setHeading(voting_text_disapproval_above_many_multi); 1.220 + } else if (disapprovalCount == 2 && disapprovalIndex == 0) { 1.221 + if (count == 1) setHeading(voting_text_disapproval_above_one_single); 1.222 + else setHeading(voting_text_disapproval_above_one_multi); 1.223 + } else if (disapprovalIndex == disapprovalCount - 2) { 1.224 + if (count == 1) setHeading(voting_text_disapproval_above_last_single); 1.225 + else setHeading(voting_text_disapproval_above_last_multi); 1.226 + } else { 1.227 + if (count == 1) setHeading(voting_text_disapproval_single); 1.228 + else setHeading(voting_text_disapproval_multi); 1.229 + } 1.230 + disapprovalIndex++; 1.231 } 1.232 } 1.233 } 1.234 - if (i == sections.length) { 1.235 - var newSection = document.createElement("div"); 1.236 - var cathead = document.createElement("div"); 1.237 - cathead.setAttribute("class", "cathead"); 1.238 - newSection.appendChild(cathead); 1.239 + } 1.240 + function voting_move(element, up, dropX, dropY) { 1.241 + if (typeof(element) == "string") element = document.getElementById(element); 1.242 + var mouse = (up == null); 1.243 + var oldParent = element.parentNode; 1.244 + if (mouse) var centerY = dropY + element.clientHeight / 2; 1.245 + var approvalCount = 0; 1.246 + var disapprovalCount = 0; 1.247 + var mainDiv = document.getElementById("voting"); 1.248 + var sections = mainDiv.childNodes; 1.249 + for (var i=0; i<sections.length; i++) { 1.250 + var section = sections[i]; 1.251 + if (section.className == "approval") approvalCount++; 1.252 + if (section.className == "disapproval") disapprovalCount++; 1.253 + } 1.254 + if (mouse) { 1.255 for (var i=0; i<sections.length; i++) { 1.256 var section = sections[i]; 1.257 if ( 1.258 @@ -156,194 +120,234 @@ 1.259 section.className == "abstention" || 1.260 section.className == "disapproval" 1.261 ) { 1.262 - if (centerY < section.offsetTop + section.clientHeight / 2) { 1.263 - if (section.className == "disapproval") { 1.264 - newSection.setAttribute("class", "disapproval"); 1.265 - disapprovalCount++; 1.266 - } else { 1.267 - newSection.setAttribute("class", "approval"); 1.268 - approvalCount++; 1.269 + if ( 1.270 + centerY >= section.offsetTop && 1.271 + centerY < section.offsetTop + section.clientHeight 1.272 + ) { 1.273 + var entries = section.childNodes; 1.274 + for (var j=0; j<entries.length; j++) { 1.275 + var entry = entries[j]; 1.276 + if (entry.className == "movable") { 1.277 + if (centerY < entry.offsetTop + entry.clientHeight / 2) { 1.278 + if (element != entry) { 1.279 + oldParent.removeChild(element); 1.280 + section.insertBefore(element, entry); 1.281 + } 1.282 + break; 1.283 + } 1.284 + } 1.285 } 1.286 - mainDiv.insertBefore(newSection, section); 1.287 + if (j == entries.length) { 1.288 + oldParent.removeChild(element); 1.289 + section.appendChild(element); 1.290 + } 1.291 break; 1.292 } 1.293 } 1.294 } 1.295 if (i == sections.length) { 1.296 - newSection.setAttribute("class", "disapproval"); 1.297 - disapprovalCount++; 1.298 - mainDiv.appendChild(newSection); 1.299 + var newSection = document.createElement("div"); 1.300 + var cathead = document.createElement("div"); 1.301 + cathead.setAttribute("class", "cathead"); 1.302 + newSection.appendChild(cathead); 1.303 + for (var i=0; i<sections.length; i++) { 1.304 + var section = sections[i]; 1.305 + if ( 1.306 + section.className == "approval" || 1.307 + section.className == "abstention" || 1.308 + section.className == "disapproval" 1.309 + ) { 1.310 + if (centerY < section.offsetTop + section.clientHeight / 2) { 1.311 + if (section.className == "disapproval") { 1.312 + newSection.setAttribute("class", "disapproval"); 1.313 + disapprovalCount++; 1.314 + } else { 1.315 + newSection.setAttribute("class", "approval"); 1.316 + approvalCount++; 1.317 + } 1.318 + mainDiv.insertBefore(newSection, section); 1.319 + break; 1.320 + } 1.321 + } 1.322 + } 1.323 + if (i == sections.length) { 1.324 + newSection.setAttribute("class", "disapproval"); 1.325 + disapprovalCount++; 1.326 + mainDiv.appendChild(newSection); 1.327 + } 1.328 + oldParent.removeChild(element); 1.329 + newSection.appendChild(element); 1.330 } 1.331 - oldParent.removeChild(element); 1.332 - newSection.appendChild(element); 1.333 - } 1.334 - } else { 1.335 - var oldFound = false; 1.336 - var prevSection = null; 1.337 - var nextSection = null; 1.338 - for (var i=0; i<sections.length; i++) { 1.339 - var section = sections[i]; 1.340 - if ( 1.341 - section.className == "approval" || 1.342 - section.className == "abstention" || 1.343 - section.className == "disapproval" 1.344 - ) { 1.345 - if (oldFound) { 1.346 - nextSection = section; 1.347 - break; 1.348 - } else if (section == oldParent) { 1.349 - oldFound = true; 1.350 - } else { 1.351 - prevSection = section; 1.352 + } else { 1.353 + var oldFound = false; 1.354 + var prevSection = null; 1.355 + var nextSection = null; 1.356 + for (var i=0; i<sections.length; i++) { 1.357 + var section = sections[i]; 1.358 + if ( 1.359 + section.className == "approval" || 1.360 + section.className == "abstention" || 1.361 + section.className == "disapproval" 1.362 + ) { 1.363 + if (oldFound) { 1.364 + nextSection = section; 1.365 + break; 1.366 + } else if (section == oldParent) { 1.367 + oldFound = true; 1.368 + } else { 1.369 + prevSection = section; 1.370 + } 1.371 } 1.372 } 1.373 - } 1.374 - var create; 1.375 - if (oldParent.className == "abstention") { 1.376 - create = true; 1.377 - } else { 1.378 - create = false; 1.379 - for (var i=0; i<oldParent.childNodes.length; i++) { 1.380 - var entry = oldParent.childNodes[i]; 1.381 - if (entry.className == "movable") { 1.382 - if (entry != element) { 1.383 - create = true; 1.384 - break; 1.385 + var create; 1.386 + if (oldParent.className == "abstention") { 1.387 + create = true; 1.388 + } else { 1.389 + create = false; 1.390 + for (var i=0; i<oldParent.childNodes.length; i++) { 1.391 + var entry = oldParent.childNodes[i]; 1.392 + if (entry.className == "movable") { 1.393 + if (entry != element) { 1.394 + create = true; 1.395 + break; 1.396 + } 1.397 } 1.398 } 1.399 } 1.400 + var newSection; 1.401 + if (create) { 1.402 + newSection = document.createElement("div"); 1.403 + var cathead = document.createElement("div"); 1.404 + cathead.setAttribute("class", "cathead"); 1.405 + newSection.appendChild(cathead); 1.406 + if ( 1.407 + oldParent.className == "approval" || 1.408 + (oldParent.className == "abstention" && up) 1.409 + ) { 1.410 + newSection.setAttribute("class", "approval"); 1.411 + approvalCount++; 1.412 + } else { 1.413 + newSection.setAttribute("class", "disapproval"); 1.414 + disapprovalCount++; 1.415 + } 1.416 + if (up) { 1.417 + mainDiv.insertBefore(newSection, oldParent); 1.418 + } else { 1.419 + if (nextSection) mainDiv.insertBefore(newSection, nextSection); 1.420 + else mainDiv.appendChild(newSection); 1.421 + } 1.422 + } else { 1.423 + if (up) newSection = prevSection; 1.424 + else newSection = nextSection; 1.425 + } 1.426 + if (newSection) { 1.427 + oldParent.removeChild(element); 1.428 + if (create || up) { 1.429 + newSection.appendChild(element); 1.430 + } else { 1.431 + var inserted = false; 1.432 + for (var i=0; i<newSection.childNodes.length; i++) { 1.433 + var entry = newSection.childNodes[i]; 1.434 + if (entry.className == "movable") { 1.435 + newSection.insertBefore(element, entry); 1.436 + inserted = true; 1.437 + break; 1.438 + } 1.439 + } 1.440 + if (!inserted) newSection.appendChild(element); 1.441 + } 1.442 + } 1.443 } 1.444 - var newSection; 1.445 - if (create) { 1.446 - newSection = document.createElement("div"); 1.447 - var cathead = document.createElement("div"); 1.448 - cathead.setAttribute("class", "cathead"); 1.449 - newSection.appendChild(cathead); 1.450 + // sections = mainDiv.childNodes; 1.451 + for (i=0; i<sections.length; i++) { 1.452 + var section = sections[i]; 1.453 if ( 1.454 - oldParent.className == "approval" || 1.455 - (oldParent.className == "abstention" && up) 1.456 + (section.className == "approval" && approvalCount > 1) || 1.457 + (section.className == "disapproval" && disapprovalCount > 1) 1.458 ) { 1.459 - newSection.setAttribute("class", "approval"); 1.460 - approvalCount++; 1.461 - } else { 1.462 - newSection.setAttribute("class", "disapproval"); 1.463 - disapprovalCount++; 1.464 - } 1.465 - if (up) { 1.466 - mainDiv.insertBefore(newSection, oldParent); 1.467 - } else { 1.468 - if (nextSection) mainDiv.insertBefore(newSection, nextSection); 1.469 - else mainDiv.appendChild(newSection); 1.470 - } 1.471 - } else { 1.472 - if (up) newSection = prevSection; 1.473 - else newSection = nextSection; 1.474 - } 1.475 - if (newSection) { 1.476 - oldParent.removeChild(element); 1.477 - if (create || up) { 1.478 - newSection.appendChild(element); 1.479 - } else { 1.480 - var inserted = false; 1.481 - for (var i=0; i<newSection.childNodes.length; i++) { 1.482 - var entry = newSection.childNodes[i]; 1.483 - if (entry.className == "movable") { 1.484 - newSection.insertBefore(element, entry); 1.485 - inserted = true; 1.486 - break; 1.487 - } 1.488 + var entries = section.childNodes; 1.489 + for (var j=0; j<entries.length; j++) { 1.490 + var entry = entries[j]; 1.491 + if (entry.className == "movable") break; 1.492 } 1.493 - if (!inserted) newSection.appendChild(element); 1.494 + if (j == entries.length) { 1.495 + section.parentNode.removeChild(section); 1.496 + } 1.497 } 1.498 } 1.499 + voting_setCategoryHeadings(); 1.500 } 1.501 - // sections = mainDiv.childNodes; 1.502 - for (i=0; i<sections.length; i++) { 1.503 - var section = sections[i]; 1.504 - if ( 1.505 - (section.className == "approval" && approvalCount > 1) || 1.506 - (section.className == "disapproval" && disapprovalCount > 1) 1.507 - ) { 1.508 - var entries = section.childNodes; 1.509 - for (var j=0; j<entries.length; j++) { 1.510 - var entry = entries[j]; 1.511 - if (entry.className == "movable") break; 1.512 - } 1.513 - if (j == entries.length) { 1.514 - section.parentNode.removeChild(section); 1.515 - } 1.516 - } 1.517 + function elementDropped(element, dropX, dropY) { 1.518 + voting_move(element, null, dropX, dropY); 1.519 } 1.520 - voting_setCategoryHeadings(); 1.521 -} 1.522 -function elementDropped(element, dropX, dropY) { 1.523 - voting_move(element, null, dropX, dropY); 1.524 -} 1.525 -window.addEventListener("load", function(event) { 1.526 - voting_setCategoryHeadings(); 1.527 - var mainDiv = document.getElementById("voting"); 1.528 - var form = document.getElementById("voting_form"); 1.529 - var elements = document.getElementsByTagName("input"); 1.530 - for (var i=0; i<elements.length; i++) { 1.531 - var element = elements[i]; 1.532 - if (element.className == "voting_done") { 1.533 - element.addEventListener("click", function(event) { 1.534 - var scoringString = ""; 1.535 - var approvalCount = 0; 1.536 - var disapprovalCount = 0; 1.537 - var sections = mainDiv.childNodes; 1.538 - for (var j=0; j<sections.length; j++) { 1.539 - var section = sections[j]; 1.540 - if (section.className == "approval") approvalCount++; 1.541 - if (section.className == "disapproval") disapprovalCount++; 1.542 - } 1.543 - var approvalIndex = 0; 1.544 - var disapprovalIndex = 0; 1.545 - for (var j=0; j<sections.length; j++) { 1.546 - var section = sections[j]; 1.547 - if ( 1.548 - section.className == "approval" || 1.549 - section.className == "abstention" || 1.550 - section.className == "disapproval" 1.551 - ) { 1.552 - var score; 1.553 - if (section.className == "approval") { 1.554 - score = approvalCount - approvalIndex; 1.555 - approvalIndex++; 1.556 - } else if (section.className == "abstention") { 1.557 - score = 0; 1.558 - } else if (section.className == "disapproval") { 1.559 - score = -1 - disapprovalIndex; 1.560 - disapprovalIndex++; 1.561 - } 1.562 - var entries = section.childNodes; 1.563 - for (var k=0; k<entries.length; k++) { 1.564 - var entry = entries[k]; 1.565 - if (entry.className == "movable") { 1.566 - var id = entry.id.match(/[0-9]+/); 1.567 - var field = document.createElement("input"); 1.568 - scoringString += id + ":" + score + ";"; 1.569 + window.addEventListener("load", function(event) { 1.570 + voting_setCategoryHeadings(); 1.571 + var mainDiv = document.getElementById("voting"); 1.572 + var form = document.getElementById("voting_form"); 1.573 + var elements = document.getElementsByTagName("input"); 1.574 + for (var i=0; i<elements.length; i++) { 1.575 + var element = elements[i]; 1.576 + if (element.className == "voting_done") { 1.577 + element.addEventListener("click", function(event) { 1.578 + var scoringString = ""; 1.579 + var approvalCount = 0; 1.580 + var disapprovalCount = 0; 1.581 + var sections = mainDiv.childNodes; 1.582 + for (var j=0; j<sections.length; j++) { 1.583 + var section = sections[j]; 1.584 + if (section.className == "approval") approvalCount++; 1.585 + if (section.className == "disapproval") disapprovalCount++; 1.586 + } 1.587 + var approvalIndex = 0; 1.588 + var disapprovalIndex = 0; 1.589 + for (var j=0; j<sections.length; j++) { 1.590 + var section = sections[j]; 1.591 + if ( 1.592 + section.className == "approval" || 1.593 + section.className == "abstention" || 1.594 + section.className == "disapproval" 1.595 + ) { 1.596 + var score; 1.597 + if (section.className == "approval") { 1.598 + score = approvalCount - approvalIndex; 1.599 + approvalIndex++; 1.600 + } else if (section.className == "abstention") { 1.601 + score = 0; 1.602 + } else if (section.className == "disapproval") { 1.603 + score = -1 - disapprovalIndex; 1.604 + disapprovalIndex++; 1.605 + } 1.606 + var entries = section.childNodes; 1.607 + for (var k=0; k<entries.length; k++) { 1.608 + var entry = entries[k]; 1.609 + if (entry.className == "movable") { 1.610 + var id = entry.id.match(/[0-9]+/); 1.611 + var field = document.createElement("input"); 1.612 + scoringString += id + ":" + score + ";"; 1.613 + } 1.614 } 1.615 } 1.616 } 1.617 - } 1.618 - var fields = form.childNodes; 1.619 - for (var j=0; j<fields.length; j++) { 1.620 - var field = fields[j]; 1.621 - if (field.name == "scoring") { 1.622 - field.setAttribute("value", scoringString); 1.623 - form.submit(); 1.624 - return; 1.625 + var fields = form.childNodes; 1.626 + for (var j=0; j<fields.length; j++) { 1.627 + var field = fields[j]; 1.628 + if (field.name == "scoring") { 1.629 + field.setAttribute("value", scoringString); 1.630 + form.submit(); 1.631 + return; 1.632 + } 1.633 } 1.634 - } 1.635 - alert('Hidden input field named "scoring" not found.'); 1.636 - }, false); 1.637 + alert('Hidden input field named "scoring" not found.'); 1.638 + }, false); 1.639 + } 1.640 } 1.641 + }, false); 1.642 + function voting_moveUp(element) { 1.643 + return voting_move(element, true); 1.644 } 1.645 -}, false); 1.646 -function voting_moveUp(element) { 1.647 - return voting_move(element, true); 1.648 -} 1.649 -function voting_moveDown(element) { 1.650 - return voting_move(element, false); 1.651 -} 1.652 + function voting_moveDown(element) { 1.653 + return voting_move(element, false); 1.654 + } 1.655 + 1.656 + 1.657 +} 1.658 \ No newline at end of file