# HG changeset patch # User jbe # Date 1352377057 -3600 # Node ID b865f87ea8105c0577267fbd0bdd3b53b87b271d # Parent 9d82c11a93b11284f42858de143dc33ee0509cc4 Work on robustification of JavaScript voting diff -r 9d82c11a93b1 -r b865f87ea810 app/main/_layout/default.html --- a/app/main/_layout/default.html Tue Nov 06 21:28:25 2012 +0100 +++ b/app/main/_layout/default.html Thu Nov 08 13:17:37 2012 +0100 @@ -11,6 +11,7 @@ + diff -r 9d82c11a93b1 -r b865f87ea810 app/main/vote/list.lua --- a/app/main/vote/list.lua Tue Nov 06 21:28:25 2012 +0100 +++ b/app/main/vote/list.lua Thu Nov 08 13:17:37 2012 +0100 @@ -2,6 +2,7 @@ local member_id = param.get("member_id", atom.integer) local member +local readonly = false local preview = param.get("preview") or param.get("preview2") == "1" and true or false diff -r 9d82c11a93b1 -r b865f87ea810 static/js/dragdrop.js --- a/static/js/dragdrop.js Tue Nov 06 21:28:25 2012 +0100 +++ b/static/js/dragdrop.js Thu Nov 08 13:17:37 2012 +0100 @@ -1,76 +1,85 @@ -if (!jsFail) { +jsProtect(function() { window.addEventListener("load", function(event) { - var originalElement; - var draggedElement; - var mouseX; - var mouseY; - var mouseOffsetX; - var mouseOffsetY; - var elementOffsetX; - var elementOffsetY; - var dropFunc; - var dragElement = function(element, func) { - //if (typeof(element) == "string") element = document.getElementById(element); - originalElement = element; - draggedElement = originalElement.cloneNode(true); - originalElement.style.visibility = "hidden"; - draggedElement.style.margin = 0; - draggedElement.style.position = "absolute"; - draggedElement.style.left = elementOffsetX = originalElement.offsetLeft; - draggedElement.style.top = elementOffsetY = originalElement.offsetTop; - draggedElement.style.width = originalElement.clientWidth; - draggedElement.style.height = originalElement.clientHeight; - draggedElement.style.backgroundColor = "#eee"; - draggedElement.style.opacity = 0.8; - originalElement.offsetParent.appendChild(draggedElement); - // workaround for wrong clientWidth and clientHeight information: - draggedElement.style.width = 2*originalElement.clientWidth - draggedElement.clientWidth; - draggedElement.style.height = 2*originalElement.clientHeight - draggedElement.clientHeight; - mouseOffsetX = mouseX; - mouseOffsetY = mouseY; - dropFunc = func; - }; - window.addEventListener("mousemove", function(event) { - mouseX = event.pageX; - mouseY = event.pageY; - if (draggedElement) { - draggedElement.style.left = elementOffsetX + mouseX - mouseOffsetX; - draggedElement.style.top = elementOffsetY + mouseY - mouseOffsetY; + jsProtect(function() { + var originalElement; + var draggedElement; + var mouseX; + var mouseY; + var mouseOffsetX; + var mouseOffsetY; + var elementOffsetX; + var elementOffsetY; + var dropFunc; + var dragElement = function(element, func) { + //if (typeof(element) == "string") element = document.getElementById(element); + originalElement = element; + draggedElement = originalElement.cloneNode(true); + originalElement.style.visibility = "hidden"; + draggedElement.style.margin = 0; + draggedElement.style.position = "absolute"; + draggedElement.style.left = elementOffsetX = originalElement.offsetLeft; + draggedElement.style.top = elementOffsetY = originalElement.offsetTop; + draggedElement.style.width = originalElement.clientWidth; + draggedElement.style.height = originalElement.clientHeight; + draggedElement.style.backgroundColor = "#eee"; + draggedElement.style.opacity = 0.8; + originalElement.offsetParent.appendChild(draggedElement); + // workaround for wrong clientWidth and clientHeight information: + draggedElement.style.width = 2*originalElement.clientWidth - draggedElement.clientWidth; + draggedElement.style.height = 2*originalElement.clientHeight - draggedElement.clientHeight; + mouseOffsetX = mouseX; + mouseOffsetY = mouseY; + dropFunc = func; + }; + window.addEventListener("mousemove", function(event) { + jsProtect(function() { + mouseX = event.pageX; + mouseY = event.pageY; + if (draggedElement) { + draggedElement.style.left = elementOffsetX + mouseX - mouseOffsetX; + draggedElement.style.top = elementOffsetY + mouseY - mouseOffsetY; + } + }); + }, true); + var mouseDrop = function(event) { + jsProtect(function() { + if (draggedElement) { + dropFunc( + originalElement, + elementOffsetX + mouseX - mouseOffsetX, + elementOffsetY + mouseY - mouseOffsetY + ); + originalElement.style.visibility = ''; + draggedElement.parentNode.removeChild(draggedElement); + originalElement = null; + draggedElement = null; + } + }); + }; + window.addEventListener("mouseup", mouseDrop, true); + window.addEventListener("mousedown", mouseDrop, true); + var elements = document.getElementsByTagName("*"); + for (var i=0; i= section.offsetTop && - centerY < section.offsetTop + section.clientHeight + section.className == "approval" || + section.className == "abstention" || + section.className == "disapproval" ) { - var entries = section.childNodes; - for (var j=0; j= section.offsetTop && + centerY < section.offsetTop + section.clientHeight + ) { + var entries = section.childNodes; + for (var j=0; j 1) || + (section.className == "disapproval" && disapprovalCount > 1) ) { - newSection.setAttribute("class", "approval"); - approvalCount++; - } else { - newSection.setAttribute("class", "disapproval"); - disapprovalCount++; - } - if (up) { - mainDiv.insertBefore(newSection, oldParent); - } else { - if (nextSection) mainDiv.insertBefore(newSection, nextSection); - else mainDiv.appendChild(newSection); - } - } else { - if (up) newSection = prevSection; - else newSection = nextSection; - } - if (newSection) { - oldParent.removeChild(element); - if (create || up) { - newSection.appendChild(element); - } else { - var inserted = false; - for (var i=0; i 1) || - (section.className == "disapproval" && disapprovalCount > 1) - ) { - var entries = section.childNodes; - for (var j=0; j