liquid_feedback_frontend
changeset 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 | 46c05d8837b7 |
children | f9b80c930456 |
files | app/main/_layout/default.html app/main/vote/_action/update.lua app/main/vote/list.lua static/js/browser_warning.js static/js/dragdrop.js static/js/voting.js |
line diff
1.1 --- a/app/main/_layout/default.html Sun Apr 15 18:26:06 2012 +0200 1.2 +++ b/app/main/_layout/default.html Mon Apr 16 23:27:07 2012 +0200 1.3 @@ -7,6 +7,10 @@ 1.4 <link rel="stylesheet" type="text/css" media="screen" href="__BASEURL__/static/gregor.js/gregor.css" /> 1.5 <link rel="stylesheet" type="text/css" media="screen" href="<!-- WEBMCP SLOTNODIV stylesheet_url -->" /> 1.6 <!-- WEBMCP SLOTNODIV html_head --> 1.7 + <script type="text/javascript">jsFail = true;</script> 1.8 + <![if !IE]> 1.9 + <script type="text/javascript">jsFail = false;</script> 1.10 + <![endif]> 1.11 <script type="text/javascript" src="__BASEURL__/static/js/partialload.js"></script> 1.12 <script type="text/javascript">var ui_tabs_active = {};</script> 1.13 </head>
2.1 --- a/app/main/vote/_action/update.lua Sun Apr 15 18:26:06 2012 +0200 2.2 +++ b/app/main/vote/_action/update.lua Mon Apr 16 23:27:07 2012 +0200 2.3 @@ -15,9 +15,22 @@ 2.4 end 2.5 2.6 2.7 +local move_up 2.8 +local move_down 2.9 2.10 -local move_up = param.get("move_up", atom.integer) 2.11 -local move_down = param.get("move_down", atom.integer) 2.12 +local tempvoting_string = param.get("scoring") 2.13 + 2.14 +local tempvotings = {} 2.15 +for match in tempvoting_string:gmatch("([^;]+)") do 2.16 + for initiative_id, grade in match:gmatch("([^:;]+):([^:;]+)") do 2.17 + tempvotings[tonumber(initiative_id)] = tonumber(grade) 2.18 + if param.get("move_up_" .. initiative_id .. ".x", atom.integer) then 2.19 + move_up = tonumber(initiative_id) 2.20 + elseif param.get("move_down_" .. initiative_id .. ".x", atom.integer) then 2.21 + move_down = tonumber(initiative_id) 2.22 + end 2.23 + end 2.24 +end 2.25 2.26 if not move_down and not move_up then 2.27 local direct_voter = DirectVoter:by_pk(issue.id, app.session.member_id) 2.28 @@ -60,15 +73,6 @@ 2.29 2.30 else 2.31 2.32 - local tempvoting_string = param.get("scoring") 2.33 - 2.34 - local tempvotings = {} 2.35 - for match in tempvoting_string:gmatch("([^;]+)") do 2.36 - for initiative_id, grade in match:gmatch("([^:;]+):([^:;]+)") do 2.37 - tempvotings[tonumber(initiative_id)] = tonumber(grade) 2.38 - end 2.39 - end 2.40 - 2.41 local current_initiative_id = move_up or move_down 2.42 2.43 local current_grade = tempvotings[current_initiative_id] or 0
3.1 --- a/app/main/vote/list.lua Sun Apr 15 18:26:06 2012 +0200 3.2 +++ b/app/main/vote/list.lua Mon Apr 16 23:27:07 2012 +0200 3.3 @@ -81,12 +81,6 @@ 3.4 end 3.5 3.6 3.7 -local warning_text = _"Some JavaScript based functions (voting in particular) will not work.\nFor this beta, please use a current version of Firefox, Safari, Chrome, Opera(?), Konqueror or another (more) standard compliant browser.\nAlternative access without JavaScript will be available soon." 3.8 - 3.9 -ui.script{ static = "js/browser_warning.js" } 3.10 -ui.script{ script = "checkBrowser(" .. encode.json(_"Your web browser is not fully supported yet." .. " " .. warning_text:gsub("\n", "\n\n")) .. ");" } 3.11 - 3.12 - 3.13 local tempvoting_string = param.get("scoring") 3.14 3.15 local tempvotings = {} 3.16 @@ -341,7 +335,7 @@ 3.17 end 3.18 local initiator_names_string = table.concat(initiator_names, ", ") 3.19 ui.container{ 3.20 - attr = { style = "float: right;" }, 3.21 + attr = { style = "float: right; position: relative;" }, 3.22 content = function() 3.23 ui.link{ 3.24 attr = { class = "clickable" }, 3.25 @@ -366,14 +360,13 @@ 3.26 } 3.27 if not readonly then 3.28 ui.container{ 3.29 - attr = { style = "float: left;" }, 3.30 + attr = { style = "float: left; position: relative;" }, 3.31 content = function() 3.32 ui.tag{ 3.33 tag = "input", 3.34 attr = { 3.35 - onclick = "voting_moveUp(this.parentNode.parentNode); return(false);", 3.36 - name = "move_up", 3.37 - value = initiative.id, 3.38 + onclick = "if (jsFail) return true; voting_moveUp(this.parentNode.parentNode); return(false);", 3.39 + name = "move_up_" .. tostring(initiative.id), 3.40 class = not disabled and "clickable" or nil, 3.41 type = "image", 3.42 src = encode.url{ static = "icons/move_up.png" }, 3.43 @@ -384,9 +377,8 @@ 3.44 ui.tag{ 3.45 tag = "input", 3.46 attr = { 3.47 - onclick = "voting_moveDown(this.parentNode.parentNode); return(false);", 3.48 - name = "move_down", 3.49 - value = initiative.id, 3.50 + onclick = "if (jsFail) return true; voting_moveDown(this.parentNode.parentNode); return(false);", 3.51 + name = "move_down_" .. tostring(initiative.id), 3.52 class = not disabled and "clickable" or nil, 3.53 type = "image", 3.54 src = encode.url{ static = "icons/move_down.png" },
4.1 --- a/static/js/browser_warning.js Sun Apr 15 18:26:06 2012 +0200 4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 4.3 @@ -1,9 +0,0 @@ 4.4 -function evilBrowser() { 4.5 - return (navigator.appName == "Microsoft Internet Explorer" || ! window.addEventListener); 4.6 -} 4.7 - 4.8 -function checkBrowser(message) { 4.9 - if (evilBrowser()) { 4.10 - document.getElementById("layout_warning").innerHTML += '<div class="slot_warning">' + message + '</div>' ; 4.11 - } 4.12 -}
5.1 --- a/static/js/dragdrop.js Sun Apr 15 18:26:06 2012 +0200 5.2 +++ b/static/js/dragdrop.js Mon Apr 16 23:27:07 2012 +0200 5.3 @@ -1,73 +1,76 @@ 5.4 -window.addEventListener("load", function(event) { 5.5 - var originalElement; 5.6 - var draggedElement; 5.7 - var mouseX; 5.8 - var mouseY; 5.9 - var mouseOffsetX; 5.10 - var mouseOffsetY; 5.11 - var elementOffsetX; 5.12 - var elementOffsetY; 5.13 - var dropFunc; 5.14 - var dragElement = function(element, func) { 5.15 - //if (typeof(element) == "string") element = document.getElementById(element); 5.16 - originalElement = element; 5.17 - draggedElement = originalElement.cloneNode(true); 5.18 - originalElement.style.visibility = "hidden"; 5.19 - draggedElement.style.margin = 0; 5.20 - draggedElement.style.position = "absolute"; 5.21 - draggedElement.style.left = elementOffsetX = originalElement.offsetLeft; 5.22 - draggedElement.style.top = elementOffsetY = originalElement.offsetTop; 5.23 - draggedElement.style.width = originalElement.clientWidth; 5.24 - draggedElement.style.height = originalElement.clientHeight; 5.25 - draggedElement.style.backgroundColor = "#eee"; 5.26 - draggedElement.style.opacity = 0.8; 5.27 - originalElement.offsetParent.appendChild(draggedElement); 5.28 - // workaround for wrong clientWidth and clientHeight information: 5.29 - draggedElement.style.width = 2*originalElement.clientWidth - draggedElement.clientWidth; 5.30 - draggedElement.style.height = 2*originalElement.clientHeight - draggedElement.clientHeight; 5.31 - mouseOffsetX = mouseX; 5.32 - mouseOffsetY = mouseY; 5.33 - dropFunc = func; 5.34 - }; 5.35 - window.addEventListener("mousemove", function(event) { 5.36 - mouseX = event.pageX; 5.37 - mouseY = event.pageY; 5.38 - if (draggedElement) { 5.39 - draggedElement.style.left = elementOffsetX + mouseX - mouseOffsetX; 5.40 - draggedElement.style.top = elementOffsetY + mouseY - mouseOffsetY; 5.41 +if (!jsFail) { 5.42 + window.addEventListener("load", function(event) { 5.43 + var originalElement; 5.44 + var draggedElement; 5.45 + var mouseX; 5.46 + var mouseY; 5.47 + var mouseOffsetX; 5.48 + var mouseOffsetY; 5.49 + var elementOffsetX; 5.50 + var elementOffsetY; 5.51 + var dropFunc; 5.52 + var dragElement = function(element, func) { 5.53 + //if (typeof(element) == "string") element = document.getElementById(element); 5.54 + originalElement = element; 5.55 + draggedElement = originalElement.cloneNode(true); 5.56 + originalElement.style.visibility = "hidden"; 5.57 + draggedElement.style.margin = 0; 5.58 + draggedElement.style.position = "absolute"; 5.59 + draggedElement.style.left = elementOffsetX = originalElement.offsetLeft; 5.60 + draggedElement.style.top = elementOffsetY = originalElement.offsetTop; 5.61 + draggedElement.style.width = originalElement.clientWidth; 5.62 + draggedElement.style.height = originalElement.clientHeight; 5.63 + draggedElement.style.backgroundColor = "#eee"; 5.64 + draggedElement.style.opacity = 0.8; 5.65 + originalElement.offsetParent.appendChild(draggedElement); 5.66 + // workaround for wrong clientWidth and clientHeight information: 5.67 + draggedElement.style.width = 2*originalElement.clientWidth - draggedElement.clientWidth; 5.68 + draggedElement.style.height = 2*originalElement.clientHeight - draggedElement.clientHeight; 5.69 + mouseOffsetX = mouseX; 5.70 + mouseOffsetY = mouseY; 5.71 + dropFunc = func; 5.72 + }; 5.73 + window.addEventListener("mousemove", function(event) { 5.74 + mouseX = event.pageX; 5.75 + mouseY = event.pageY; 5.76 + if (draggedElement) { 5.77 + draggedElement.style.left = elementOffsetX + mouseX - mouseOffsetX; 5.78 + draggedElement.style.top = elementOffsetY + mouseY - mouseOffsetY; 5.79 + } 5.80 + }, true); 5.81 + var mouseDrop = function(event) { 5.82 + if (draggedElement) { 5.83 + dropFunc( 5.84 + originalElement, 5.85 + elementOffsetX + mouseX - mouseOffsetX, 5.86 + elementOffsetY + mouseY - mouseOffsetY 5.87 + ); 5.88 + originalElement.style.visibility = ''; 5.89 + draggedElement.parentNode.removeChild(draggedElement); 5.90 + originalElement = null; 5.91 + draggedElement = null; 5.92 + } 5.93 + }; 5.94 + window.addEventListener("mouseup", mouseDrop, true); 5.95 + window.addEventListener("mousedown", mouseDrop, true); 5.96 + var elements = document.getElementsByTagName("*"); 5.97 + for (var i=0; i<elements.length; i++) { 5.98 + var element = elements[i]; 5.99 + if (element.className == "movable") { 5.100 + element.addEventListener("mousedown", function(event) { 5.101 + event.target.style.cursor = "move"; 5.102 + dragElement(event.currentTarget, function(element, dropX, dropY) { 5.103 + event.target.style.cursor = ''; 5.104 + elementDropped(element, dropX, dropY); 5.105 + }); 5.106 + event.preventDefault(); 5.107 + }, false); 5.108 + } else if (element.className == "clickable") { 5.109 + element.addEventListener("mousedown", function(event) { 5.110 + event.stopPropagation(); 5.111 + }, false); 5.112 + } 5.113 } 5.114 - }, true); 5.115 - var mouseDrop = function(event) { 5.116 - if (draggedElement) { 5.117 - dropFunc( 5.118 - originalElement, 5.119 - elementOffsetX + mouseX - mouseOffsetX, 5.120 - elementOffsetY + mouseY - mouseOffsetY 5.121 - ); 5.122 - originalElement.style.visibility = ''; 5.123 - draggedElement.parentNode.removeChild(draggedElement); 5.124 - originalElement = null; 5.125 - draggedElement = null; 5.126 - } 5.127 - }; 5.128 - window.addEventListener("mouseup", mouseDrop, true); 5.129 - window.addEventListener("mousedown", mouseDrop, true); 5.130 - var elements = document.getElementsByTagName("*"); 5.131 - for (var i=0; i<elements.length; i++) { 5.132 - var element = elements[i]; 5.133 - if (element.className == "movable") { 5.134 - element.addEventListener("mousedown", function(event) { 5.135 - event.target.style.cursor = "move"; 5.136 - dragElement(event.currentTarget, function(element, dropX, dropY) { 5.137 - event.target.style.cursor = ''; 5.138 - elementDropped(element, dropX, dropY); 5.139 - }); 5.140 - event.preventDefault(); 5.141 - }, false); 5.142 - } else if (element.className == "clickable") { 5.143 - element.addEventListener("mousedown", function(event) { 5.144 - event.stopPropagation(); 5.145 - }, false); 5.146 - } 5.147 - } 5.148 -}, false); 5.149 + }, false); 5.150 + 5.151 +} 5.152 \ No newline at end of file
6.1 --- a/static/js/voting.js Sun Apr 15 18:26:06 2012 +0200 6.2 +++ b/static/js/voting.js Mon Apr 16 23:27:07 2012 +0200 6.3 @@ -1,117 +1,36 @@ 6.4 -voting_text_approval_single = "Approval" 6.5 -voting_text_approval_multi = "Approval" 6.6 -voting_text_first_preference_single = "Approval (first preference)" 6.7 -voting_text_first_preference_multi = "Approval (first preference)" 6.8 -voting_text_second_preference_single = "Approval (second preference)" 6.9 -voting_text_second_preference_multi = "Approval (second preference)" 6.10 -voting_text_third_preference_single = "Approval (third preference)" 6.11 -voting_text_third_preference_multi = "Approval (third preference)" 6.12 -voting_text_numeric_preference_single = "Approval (#th preference)" 6.13 -voting_text_numeric_preference_multi = "Approval (#th preference)" 6.14 -voting_text_abstention_single = "Abstention" 6.15 -voting_text_abstention_multi = "Abstention" 6.16 -voting_text_disapproval_above_one_single = "Disapproval (prefer to lower block)" 6.17 -voting_text_disapproval_above_one_multi = "Disapproval (prefer to lower block)" 6.18 -voting_text_disapproval_above_many_single = "Disapproval (prefer to lower blocks)" 6.19 -voting_text_disapproval_above_many_multi = "Disapproval (prefer to lower blocks)" 6.20 -voting_text_disapproval_above_last_single = "Disapproval (prefer to last block)" 6.21 -voting_text_disapproval_above_last_multi = "Disapproval (prefer to last block)" 6.22 -voting_text_disapproval_single = "Disapproval" 6.23 -voting_text_disapproval_multi = "Disapproval" 6.24 +if (!jsFail) { 6.25 + voting_text_approval_single = "Approval" 6.26 + voting_text_approval_multi = "Approval" 6.27 + voting_text_first_preference_single = "Approval (first preference)" 6.28 + voting_text_first_preference_multi = "Approval (first preference)" 6.29 + voting_text_second_preference_single = "Approval (second preference)" 6.30 + voting_text_second_preference_multi = "Approval (second preference)" 6.31 + voting_text_third_preference_single = "Approval (third preference)" 6.32 + voting_text_third_preference_multi = "Approval (third preference)" 6.33 + voting_text_numeric_preference_single = "Approval (#th preference)" 6.34 + voting_text_numeric_preference_multi = "Approval (#th preference)" 6.35 + voting_text_abstention_single = "Abstention" 6.36 + voting_text_abstention_multi = "Abstention" 6.37 + voting_text_disapproval_above_one_single = "Disapproval (prefer to lower block)" 6.38 + voting_text_disapproval_above_one_multi = "Disapproval (prefer to lower block)" 6.39 + voting_text_disapproval_above_many_single = "Disapproval (prefer to lower blocks)" 6.40 + voting_text_disapproval_above_many_multi = "Disapproval (prefer to lower blocks)" 6.41 + voting_text_disapproval_above_last_single = "Disapproval (prefer to last block)" 6.42 + voting_text_disapproval_above_last_multi = "Disapproval (prefer to last block)" 6.43 + voting_text_disapproval_single = "Disapproval" 6.44 + voting_text_disapproval_multi = "Disapproval" 6.45 6.46 -function voting_setCategoryHeadings() { 6.47 - var approvalCount = 0; 6.48 - var disapprovalCount = 0; 6.49 - var sections = document.getElementById("voting").childNodes; 6.50 - for (var i=0; i<sections.length; i++) { 6.51 - var section = sections[i]; 6.52 - if (section.className == "approval") approvalCount++; 6.53 - if (section.className == "disapproval") disapprovalCount++; 6.54 - } 6.55 - var approvalIndex = 0; 6.56 - var disapprovalIndex = 0; 6.57 - for (var i=0; i<sections.length; i++) { 6.58 - var section = sections[i]; 6.59 - if ( 6.60 - section.className == "approval" || 6.61 - section.className == "abstention" || 6.62 - section.className == "disapproval" 6.63 - ) { 6.64 - var setHeading = function(heading) { 6.65 - var headingNodes = section.childNodes; 6.66 - for (var j=0; j<headingNodes.length; j++) { 6.67 - var headingNode = headingNodes[j]; 6.68 - if (headingNode.className == "cathead") { 6.69 - headingNode.textContent = heading; 6.70 - } 6.71 - } 6.72 - } 6.73 - var count = 0; 6.74 - var entries = section.childNodes; 6.75 - for (var j=0; j<entries.length; j++) { 6.76 - var entry = entries[j]; 6.77 - if (entry.className == "movable") count++; 6.78 - } 6.79 - if (section.className == "approval") { 6.80 - if (approvalCount > 1) { 6.81 - if (approvalIndex == 0) { 6.82 - if (count == 1) setHeading(voting_text_first_preference_single); 6.83 - else setHeading(voting_text_first_preference_multi); 6.84 - } else if (approvalIndex == 1) { 6.85 - if (count == 1) setHeading(voting_text_second_preference_single); 6.86 - else setHeading(voting_text_second_preference_multi); 6.87 - } else if (approvalIndex == 2) { 6.88 - if (count == 1) setHeading(voting_text_third_preference_single); 6.89 - else setHeading(voting_text_third_preference_multi); 6.90 - } else { 6.91 - var text; 6.92 - if (count == 1) text = voting_text_numeric_preference_single; 6.93 - else text = voting_text_numeric_preference_multi; 6.94 - text = text.replace(/#/, "" + (approvalIndex + 1)) 6.95 - setHeading(text); 6.96 - } 6.97 - } else { 6.98 - if (count == 1) setHeading(voting_text_approval_single); 6.99 - else setHeading(voting_text_approval_multi); 6.100 - } 6.101 - approvalIndex++; 6.102 - } else if (section.className == "abstention") { 6.103 - if (count == 1) setHeading(voting_text_abstention_single); 6.104 - else setHeading(voting_text_abstention_multi); 6.105 - } else if (section.className == "disapproval") { 6.106 - if (disapprovalCount > disapprovalIndex + 2) { 6.107 - if (count == 1) setHeading(voting_text_disapproval_above_many_single); 6.108 - else setHeading(voting_text_disapproval_above_many_multi); 6.109 - } else if (disapprovalCount == 2 && disapprovalIndex == 0) { 6.110 - if (count == 1) setHeading(voting_text_disapproval_above_one_single); 6.111 - else setHeading(voting_text_disapproval_above_one_multi); 6.112 - } else if (disapprovalIndex == disapprovalCount - 2) { 6.113 - if (count == 1) setHeading(voting_text_disapproval_above_last_single); 6.114 - else setHeading(voting_text_disapproval_above_last_multi); 6.115 - } else { 6.116 - if (count == 1) setHeading(voting_text_disapproval_single); 6.117 - else setHeading(voting_text_disapproval_multi); 6.118 - } 6.119 - disapprovalIndex++; 6.120 - } 6.121 + function voting_setCategoryHeadings() { 6.122 + var approvalCount = 0; 6.123 + var disapprovalCount = 0; 6.124 + var sections = document.getElementById("voting").childNodes; 6.125 + for (var i=0; i<sections.length; i++) { 6.126 + var section = sections[i]; 6.127 + if (section.className == "approval") approvalCount++; 6.128 + if (section.className == "disapproval") disapprovalCount++; 6.129 } 6.130 - } 6.131 -} 6.132 -function voting_move(element, up, dropX, dropY) { 6.133 - if (typeof(element) == "string") element = document.getElementById(element); 6.134 - var mouse = (up == null); 6.135 - var oldParent = element.parentNode; 6.136 - if (mouse) var centerY = dropY + element.clientHeight / 2; 6.137 - var approvalCount = 0; 6.138 - var disapprovalCount = 0; 6.139 - var mainDiv = document.getElementById("voting"); 6.140 - var sections = mainDiv.childNodes; 6.141 - for (var i=0; i<sections.length; i++) { 6.142 - var section = sections[i]; 6.143 - if (section.className == "approval") approvalCount++; 6.144 - if (section.className == "disapproval") disapprovalCount++; 6.145 - } 6.146 - if (mouse) { 6.147 + var approvalIndex = 0; 6.148 + var disapprovalIndex = 0; 6.149 for (var i=0; i<sections.length; i++) { 6.150 var section = sections[i]; 6.151 if ( 6.152 @@ -119,36 +38,81 @@ 6.153 section.className == "abstention" || 6.154 section.className == "disapproval" 6.155 ) { 6.156 - if ( 6.157 - centerY >= section.offsetTop && 6.158 - centerY < section.offsetTop + section.clientHeight 6.159 - ) { 6.160 - var entries = section.childNodes; 6.161 - for (var j=0; j<entries.length; j++) { 6.162 - var entry = entries[j]; 6.163 - if (entry.className == "movable") { 6.164 - if (centerY < entry.offsetTop + entry.clientHeight / 2) { 6.165 - if (element != entry) { 6.166 - oldParent.removeChild(element); 6.167 - section.insertBefore(element, entry); 6.168 - } 6.169 - break; 6.170 - } 6.171 + var setHeading = function(heading) { 6.172 + var headingNodes = section.childNodes; 6.173 + for (var j=0; j<headingNodes.length; j++) { 6.174 + var headingNode = headingNodes[j]; 6.175 + if (headingNode.className == "cathead") { 6.176 + headingNode.textContent = heading; 6.177 } 6.178 } 6.179 - if (j == entries.length) { 6.180 - oldParent.removeChild(element); 6.181 - section.appendChild(element); 6.182 + } 6.183 + var count = 0; 6.184 + var entries = section.childNodes; 6.185 + for (var j=0; j<entries.length; j++) { 6.186 + var entry = entries[j]; 6.187 + if (entry.className == "movable") count++; 6.188 + } 6.189 + if (section.className == "approval") { 6.190 + if (approvalCount > 1) { 6.191 + if (approvalIndex == 0) { 6.192 + if (count == 1) setHeading(voting_text_first_preference_single); 6.193 + else setHeading(voting_text_first_preference_multi); 6.194 + } else if (approvalIndex == 1) { 6.195 + if (count == 1) setHeading(voting_text_second_preference_single); 6.196 + else setHeading(voting_text_second_preference_multi); 6.197 + } else if (approvalIndex == 2) { 6.198 + if (count == 1) setHeading(voting_text_third_preference_single); 6.199 + else setHeading(voting_text_third_preference_multi); 6.200 + } else { 6.201 + var text; 6.202 + if (count == 1) text = voting_text_numeric_preference_single; 6.203 + else text = voting_text_numeric_preference_multi; 6.204 + text = text.replace(/#/, "" + (approvalIndex + 1)) 6.205 + setHeading(text); 6.206 + } 6.207 + } else { 6.208 + if (count == 1) setHeading(voting_text_approval_single); 6.209 + else setHeading(voting_text_approval_multi); 6.210 } 6.211 - break; 6.212 + approvalIndex++; 6.213 + } else if (section.className == "abstention") { 6.214 + if (count == 1) setHeading(voting_text_abstention_single); 6.215 + else setHeading(voting_text_abstention_multi); 6.216 + } else if (section.className == "disapproval") { 6.217 + if (disapprovalCount > disapprovalIndex + 2) { 6.218 + if (count == 1) setHeading(voting_text_disapproval_above_many_single); 6.219 + else setHeading(voting_text_disapproval_above_many_multi); 6.220 + } else if (disapprovalCount == 2 && disapprovalIndex == 0) { 6.221 + if (count == 1) setHeading(voting_text_disapproval_above_one_single); 6.222 + else setHeading(voting_text_disapproval_above_one_multi); 6.223 + } else if (disapprovalIndex == disapprovalCount - 2) { 6.224 + if (count == 1) setHeading(voting_text_disapproval_above_last_single); 6.225 + else setHeading(voting_text_disapproval_above_last_multi); 6.226 + } else { 6.227 + if (count == 1) setHeading(voting_text_disapproval_single); 6.228 + else setHeading(voting_text_disapproval_multi); 6.229 + } 6.230 + disapprovalIndex++; 6.231 } 6.232 } 6.233 } 6.234 - if (i == sections.length) { 6.235 - var newSection = document.createElement("div"); 6.236 - var cathead = document.createElement("div"); 6.237 - cathead.setAttribute("class", "cathead"); 6.238 - newSection.appendChild(cathead); 6.239 + } 6.240 + function voting_move(element, up, dropX, dropY) { 6.241 + if (typeof(element) == "string") element = document.getElementById(element); 6.242 + var mouse = (up == null); 6.243 + var oldParent = element.parentNode; 6.244 + if (mouse) var centerY = dropY + element.clientHeight / 2; 6.245 + var approvalCount = 0; 6.246 + var disapprovalCount = 0; 6.247 + var mainDiv = document.getElementById("voting"); 6.248 + var sections = mainDiv.childNodes; 6.249 + for (var i=0; i<sections.length; i++) { 6.250 + var section = sections[i]; 6.251 + if (section.className == "approval") approvalCount++; 6.252 + if (section.className == "disapproval") disapprovalCount++; 6.253 + } 6.254 + if (mouse) { 6.255 for (var i=0; i<sections.length; i++) { 6.256 var section = sections[i]; 6.257 if ( 6.258 @@ -156,194 +120,234 @@ 6.259 section.className == "abstention" || 6.260 section.className == "disapproval" 6.261 ) { 6.262 - if (centerY < section.offsetTop + section.clientHeight / 2) { 6.263 - if (section.className == "disapproval") { 6.264 - newSection.setAttribute("class", "disapproval"); 6.265 - disapprovalCount++; 6.266 - } else { 6.267 - newSection.setAttribute("class", "approval"); 6.268 - approvalCount++; 6.269 + if ( 6.270 + centerY >= section.offsetTop && 6.271 + centerY < section.offsetTop + section.clientHeight 6.272 + ) { 6.273 + var entries = section.childNodes; 6.274 + for (var j=0; j<entries.length; j++) { 6.275 + var entry = entries[j]; 6.276 + if (entry.className == "movable") { 6.277 + if (centerY < entry.offsetTop + entry.clientHeight / 2) { 6.278 + if (element != entry) { 6.279 + oldParent.removeChild(element); 6.280 + section.insertBefore(element, entry); 6.281 + } 6.282 + break; 6.283 + } 6.284 + } 6.285 } 6.286 - mainDiv.insertBefore(newSection, section); 6.287 + if (j == entries.length) { 6.288 + oldParent.removeChild(element); 6.289 + section.appendChild(element); 6.290 + } 6.291 break; 6.292 } 6.293 } 6.294 } 6.295 if (i == sections.length) { 6.296 - newSection.setAttribute("class", "disapproval"); 6.297 - disapprovalCount++; 6.298 - mainDiv.appendChild(newSection); 6.299 + var newSection = document.createElement("div"); 6.300 + var cathead = document.createElement("div"); 6.301 + cathead.setAttribute("class", "cathead"); 6.302 + newSection.appendChild(cathead); 6.303 + for (var i=0; i<sections.length; i++) { 6.304 + var section = sections[i]; 6.305 + if ( 6.306 + section.className == "approval" || 6.307 + section.className == "abstention" || 6.308 + section.className == "disapproval" 6.309 + ) { 6.310 + if (centerY < section.offsetTop + section.clientHeight / 2) { 6.311 + if (section.className == "disapproval") { 6.312 + newSection.setAttribute("class", "disapproval"); 6.313 + disapprovalCount++; 6.314 + } else { 6.315 + newSection.setAttribute("class", "approval"); 6.316 + approvalCount++; 6.317 + } 6.318 + mainDiv.insertBefore(newSection, section); 6.319 + break; 6.320 + } 6.321 + } 6.322 + } 6.323 + if (i == sections.length) { 6.324 + newSection.setAttribute("class", "disapproval"); 6.325 + disapprovalCount++; 6.326 + mainDiv.appendChild(newSection); 6.327 + } 6.328 + oldParent.removeChild(element); 6.329 + newSection.appendChild(element); 6.330 } 6.331 - oldParent.removeChild(element); 6.332 - newSection.appendChild(element); 6.333 - } 6.334 - } else { 6.335 - var oldFound = false; 6.336 - var prevSection = null; 6.337 - var nextSection = null; 6.338 - for (var i=0; i<sections.length; i++) { 6.339 - var section = sections[i]; 6.340 - if ( 6.341 - section.className == "approval" || 6.342 - section.className == "abstention" || 6.343 - section.className == "disapproval" 6.344 - ) { 6.345 - if (oldFound) { 6.346 - nextSection = section; 6.347 - break; 6.348 - } else if (section == oldParent) { 6.349 - oldFound = true; 6.350 - } else { 6.351 - prevSection = section; 6.352 + } else { 6.353 + var oldFound = false; 6.354 + var prevSection = null; 6.355 + var nextSection = null; 6.356 + for (var i=0; i<sections.length; i++) { 6.357 + var section = sections[i]; 6.358 + if ( 6.359 + section.className == "approval" || 6.360 + section.className == "abstention" || 6.361 + section.className == "disapproval" 6.362 + ) { 6.363 + if (oldFound) { 6.364 + nextSection = section; 6.365 + break; 6.366 + } else if (section == oldParent) { 6.367 + oldFound = true; 6.368 + } else { 6.369 + prevSection = section; 6.370 + } 6.371 } 6.372 } 6.373 - } 6.374 - var create; 6.375 - if (oldParent.className == "abstention") { 6.376 - create = true; 6.377 - } else { 6.378 - create = false; 6.379 - for (var i=0; i<oldParent.childNodes.length; i++) { 6.380 - var entry = oldParent.childNodes[i]; 6.381 - if (entry.className == "movable") { 6.382 - if (entry != element) { 6.383 - create = true; 6.384 - break; 6.385 + var create; 6.386 + if (oldParent.className == "abstention") { 6.387 + create = true; 6.388 + } else { 6.389 + create = false; 6.390 + for (var i=0; i<oldParent.childNodes.length; i++) { 6.391 + var entry = oldParent.childNodes[i]; 6.392 + if (entry.className == "movable") { 6.393 + if (entry != element) { 6.394 + create = true; 6.395 + break; 6.396 + } 6.397 } 6.398 } 6.399 } 6.400 + var newSection; 6.401 + if (create) { 6.402 + newSection = document.createElement("div"); 6.403 + var cathead = document.createElement("div"); 6.404 + cathead.setAttribute("class", "cathead"); 6.405 + newSection.appendChild(cathead); 6.406 + if ( 6.407 + oldParent.className == "approval" || 6.408 + (oldParent.className == "abstention" && up) 6.409 + ) { 6.410 + newSection.setAttribute("class", "approval"); 6.411 + approvalCount++; 6.412 + } else { 6.413 + newSection.setAttribute("class", "disapproval"); 6.414 + disapprovalCount++; 6.415 + } 6.416 + if (up) { 6.417 + mainDiv.insertBefore(newSection, oldParent); 6.418 + } else { 6.419 + if (nextSection) mainDiv.insertBefore(newSection, nextSection); 6.420 + else mainDiv.appendChild(newSection); 6.421 + } 6.422 + } else { 6.423 + if (up) newSection = prevSection; 6.424 + else newSection = nextSection; 6.425 + } 6.426 + if (newSection) { 6.427 + oldParent.removeChild(element); 6.428 + if (create || up) { 6.429 + newSection.appendChild(element); 6.430 + } else { 6.431 + var inserted = false; 6.432 + for (var i=0; i<newSection.childNodes.length; i++) { 6.433 + var entry = newSection.childNodes[i]; 6.434 + if (entry.className == "movable") { 6.435 + newSection.insertBefore(element, entry); 6.436 + inserted = true; 6.437 + break; 6.438 + } 6.439 + } 6.440 + if (!inserted) newSection.appendChild(element); 6.441 + } 6.442 + } 6.443 } 6.444 - var newSection; 6.445 - if (create) { 6.446 - newSection = document.createElement("div"); 6.447 - var cathead = document.createElement("div"); 6.448 - cathead.setAttribute("class", "cathead"); 6.449 - newSection.appendChild(cathead); 6.450 + // sections = mainDiv.childNodes; 6.451 + for (i=0; i<sections.length; i++) { 6.452 + var section = sections[i]; 6.453 if ( 6.454 - oldParent.className == "approval" || 6.455 - (oldParent.className == "abstention" && up) 6.456 + (section.className == "approval" && approvalCount > 1) || 6.457 + (section.className == "disapproval" && disapprovalCount > 1) 6.458 ) { 6.459 - newSection.setAttribute("class", "approval"); 6.460 - approvalCount++; 6.461 - } else { 6.462 - newSection.setAttribute("class", "disapproval"); 6.463 - disapprovalCount++; 6.464 - } 6.465 - if (up) { 6.466 - mainDiv.insertBefore(newSection, oldParent); 6.467 - } else { 6.468 - if (nextSection) mainDiv.insertBefore(newSection, nextSection); 6.469 - else mainDiv.appendChild(newSection); 6.470 - } 6.471 - } else { 6.472 - if (up) newSection = prevSection; 6.473 - else newSection = nextSection; 6.474 - } 6.475 - if (newSection) { 6.476 - oldParent.removeChild(element); 6.477 - if (create || up) { 6.478 - newSection.appendChild(element); 6.479 - } else { 6.480 - var inserted = false; 6.481 - for (var i=0; i<newSection.childNodes.length; i++) { 6.482 - var entry = newSection.childNodes[i]; 6.483 - if (entry.className == "movable") { 6.484 - newSection.insertBefore(element, entry); 6.485 - inserted = true; 6.486 - break; 6.487 - } 6.488 + var entries = section.childNodes; 6.489 + for (var j=0; j<entries.length; j++) { 6.490 + var entry = entries[j]; 6.491 + if (entry.className == "movable") break; 6.492 } 6.493 - if (!inserted) newSection.appendChild(element); 6.494 + if (j == entries.length) { 6.495 + section.parentNode.removeChild(section); 6.496 + } 6.497 } 6.498 } 6.499 + voting_setCategoryHeadings(); 6.500 } 6.501 - // sections = mainDiv.childNodes; 6.502 - for (i=0; i<sections.length; i++) { 6.503 - var section = sections[i]; 6.504 - if ( 6.505 - (section.className == "approval" && approvalCount > 1) || 6.506 - (section.className == "disapproval" && disapprovalCount > 1) 6.507 - ) { 6.508 - var entries = section.childNodes; 6.509 - for (var j=0; j<entries.length; j++) { 6.510 - var entry = entries[j]; 6.511 - if (entry.className == "movable") break; 6.512 - } 6.513 - if (j == entries.length) { 6.514 - section.parentNode.removeChild(section); 6.515 - } 6.516 - } 6.517 + function elementDropped(element, dropX, dropY) { 6.518 + voting_move(element, null, dropX, dropY); 6.519 } 6.520 - voting_setCategoryHeadings(); 6.521 -} 6.522 -function elementDropped(element, dropX, dropY) { 6.523 - voting_move(element, null, dropX, dropY); 6.524 -} 6.525 -window.addEventListener("load", function(event) { 6.526 - voting_setCategoryHeadings(); 6.527 - var mainDiv = document.getElementById("voting"); 6.528 - var form = document.getElementById("voting_form"); 6.529 - var elements = document.getElementsByTagName("input"); 6.530 - for (var i=0; i<elements.length; i++) { 6.531 - var element = elements[i]; 6.532 - if (element.className == "voting_done") { 6.533 - element.addEventListener("click", function(event) { 6.534 - var scoringString = ""; 6.535 - var approvalCount = 0; 6.536 - var disapprovalCount = 0; 6.537 - var sections = mainDiv.childNodes; 6.538 - for (var j=0; j<sections.length; j++) { 6.539 - var section = sections[j]; 6.540 - if (section.className == "approval") approvalCount++; 6.541 - if (section.className == "disapproval") disapprovalCount++; 6.542 - } 6.543 - var approvalIndex = 0; 6.544 - var disapprovalIndex = 0; 6.545 - for (var j=0; j<sections.length; j++) { 6.546 - var section = sections[j]; 6.547 - if ( 6.548 - section.className == "approval" || 6.549 - section.className == "abstention" || 6.550 - section.className == "disapproval" 6.551 - ) { 6.552 - var score; 6.553 - if (section.className == "approval") { 6.554 - score = approvalCount - approvalIndex; 6.555 - approvalIndex++; 6.556 - } else if (section.className == "abstention") { 6.557 - score = 0; 6.558 - } else if (section.className == "disapproval") { 6.559 - score = -1 - disapprovalIndex; 6.560 - disapprovalIndex++; 6.561 - } 6.562 - var entries = section.childNodes; 6.563 - for (var k=0; k<entries.length; k++) { 6.564 - var entry = entries[k]; 6.565 - if (entry.className == "movable") { 6.566 - var id = entry.id.match(/[0-9]+/); 6.567 - var field = document.createElement("input"); 6.568 - scoringString += id + ":" + score + ";"; 6.569 + window.addEventListener("load", function(event) { 6.570 + voting_setCategoryHeadings(); 6.571 + var mainDiv = document.getElementById("voting"); 6.572 + var form = document.getElementById("voting_form"); 6.573 + var elements = document.getElementsByTagName("input"); 6.574 + for (var i=0; i<elements.length; i++) { 6.575 + var element = elements[i]; 6.576 + if (element.className == "voting_done") { 6.577 + element.addEventListener("click", function(event) { 6.578 + var scoringString = ""; 6.579 + var approvalCount = 0; 6.580 + var disapprovalCount = 0; 6.581 + var sections = mainDiv.childNodes; 6.582 + for (var j=0; j<sections.length; j++) { 6.583 + var section = sections[j]; 6.584 + if (section.className == "approval") approvalCount++; 6.585 + if (section.className == "disapproval") disapprovalCount++; 6.586 + } 6.587 + var approvalIndex = 0; 6.588 + var disapprovalIndex = 0; 6.589 + for (var j=0; j<sections.length; j++) { 6.590 + var section = sections[j]; 6.591 + if ( 6.592 + section.className == "approval" || 6.593 + section.className == "abstention" || 6.594 + section.className == "disapproval" 6.595 + ) { 6.596 + var score; 6.597 + if (section.className == "approval") { 6.598 + score = approvalCount - approvalIndex; 6.599 + approvalIndex++; 6.600 + } else if (section.className == "abstention") { 6.601 + score = 0; 6.602 + } else if (section.className == "disapproval") { 6.603 + score = -1 - disapprovalIndex; 6.604 + disapprovalIndex++; 6.605 + } 6.606 + var entries = section.childNodes; 6.607 + for (var k=0; k<entries.length; k++) { 6.608 + var entry = entries[k]; 6.609 + if (entry.className == "movable") { 6.610 + var id = entry.id.match(/[0-9]+/); 6.611 + var field = document.createElement("input"); 6.612 + scoringString += id + ":" + score + ";"; 6.613 + } 6.614 } 6.615 } 6.616 } 6.617 - } 6.618 - var fields = form.childNodes; 6.619 - for (var j=0; j<fields.length; j++) { 6.620 - var field = fields[j]; 6.621 - if (field.name == "scoring") { 6.622 - field.setAttribute("value", scoringString); 6.623 - form.submit(); 6.624 - return; 6.625 + var fields = form.childNodes; 6.626 + for (var j=0; j<fields.length; j++) { 6.627 + var field = fields[j]; 6.628 + if (field.name == "scoring") { 6.629 + field.setAttribute("value", scoringString); 6.630 + form.submit(); 6.631 + return; 6.632 + } 6.633 } 6.634 - } 6.635 - alert('Hidden input field named "scoring" not found.'); 6.636 - }, false); 6.637 + alert('Hidden input field named "scoring" not found.'); 6.638 + }, false); 6.639 + } 6.640 } 6.641 + }, false); 6.642 + function voting_moveUp(element) { 6.643 + return voting_move(element, true); 6.644 } 6.645 -}, false); 6.646 -function voting_moveUp(element) { 6.647 - return voting_move(element, true); 6.648 -} 6.649 -function voting_moveDown(element) { 6.650 - return voting_move(element, false); 6.651 -} 6.652 + function voting_moveDown(element) { 6.653 + return voting_move(element, false); 6.654 + } 6.655 + 6.656 + 6.657 +} 6.658 \ No newline at end of file