liquid_feedback_frontend

changeset 945:b865f87ea810

Work on robustification of JavaScript voting
author jbe
date Thu Nov 08 13:17:37 2012 +0100 (2012-11-08)
parents 9d82c11a93b1
children c328da62f45c
files app/main/_layout/default.html app/main/vote/list.lua static/js/dragdrop.js static/js/jsprotect.js static/js/voting.js
line diff
     1.1 --- a/app/main/_layout/default.html	Tue Nov 06 21:28:25 2012 +0100
     1.2 +++ b/app/main/_layout/default.html	Thu Nov 08 13:17:37 2012 +0100
     1.3 @@ -11,6 +11,7 @@
     1.4      <![if !IE]>
     1.5        <script type="text/javascript">jsFail = false;</script>
     1.6      <![endif]>
     1.7 +    <script type="text/javascript" src="__BASEURL__/static/js/jsprotect.js"></script>
     1.8      <script type="text/javascript" src="__BASEURL__/static/js/partialload.js"></script>
     1.9      <script type="text/javascript">var ui_tabs_active = {};</script>
    1.10    </head>
     2.1 --- a/app/main/vote/list.lua	Tue Nov 06 21:28:25 2012 +0100
     2.2 +++ b/app/main/vote/list.lua	Thu Nov 08 13:17:37 2012 +0100
     2.3 @@ -2,6 +2,7 @@
     2.4  
     2.5  local member_id = param.get("member_id", atom.integer)
     2.6  local member
     2.7 +local readonly = false
     2.8  
     2.9  local preview = param.get("preview") or param.get("preview2") == "1" and true or false
    2.10  
     3.1 --- a/static/js/dragdrop.js	Tue Nov 06 21:28:25 2012 +0100
     3.2 +++ b/static/js/dragdrop.js	Thu Nov 08 13:17:37 2012 +0100
     3.3 @@ -1,76 +1,85 @@
     3.4 -if (!jsFail) {
     3.5 +jsProtect(function() {
     3.6    window.addEventListener("load", function(event) {
     3.7 -    var originalElement;
     3.8 -    var draggedElement;
     3.9 -    var mouseX;
    3.10 -    var mouseY;
    3.11 -    var mouseOffsetX;
    3.12 -    var mouseOffsetY;
    3.13 -    var elementOffsetX;
    3.14 -    var elementOffsetY;
    3.15 -    var dropFunc;
    3.16 -    var dragElement = function(element, func) {
    3.17 -      //if (typeof(element) == "string") element = document.getElementById(element);
    3.18 -      originalElement = element;
    3.19 -      draggedElement = originalElement.cloneNode(true);
    3.20 -      originalElement.style.visibility = "hidden";
    3.21 -      draggedElement.style.margin = 0;
    3.22 -      draggedElement.style.position = "absolute";
    3.23 -      draggedElement.style.left = elementOffsetX = originalElement.offsetLeft;
    3.24 -      draggedElement.style.top  = elementOffsetY = originalElement.offsetTop;
    3.25 -      draggedElement.style.width  = originalElement.clientWidth;
    3.26 -      draggedElement.style.height = originalElement.clientHeight;
    3.27 -      draggedElement.style.backgroundColor = "#eee";
    3.28 -      draggedElement.style.opacity = 0.8;
    3.29 -      originalElement.offsetParent.appendChild(draggedElement);
    3.30 -      // workaround for wrong clientWidth and clientHeight information:
    3.31 -      draggedElement.style.width = 2*originalElement.clientWidth - draggedElement.clientWidth;
    3.32 -      draggedElement.style.height = 2*originalElement.clientHeight - draggedElement.clientHeight;
    3.33 -      mouseOffsetX = mouseX;
    3.34 -      mouseOffsetY = mouseY;
    3.35 -      dropFunc = func;
    3.36 -    };
    3.37 -    window.addEventListener("mousemove", function(event) {
    3.38 -      mouseX = event.pageX;
    3.39 -      mouseY = event.pageY;
    3.40 -      if (draggedElement) {
    3.41 -        draggedElement.style.left = elementOffsetX + mouseX - mouseOffsetX;
    3.42 -        draggedElement.style.top  = elementOffsetY + mouseY - mouseOffsetY;
    3.43 +    jsProtect(function() {
    3.44 +      var originalElement;
    3.45 +      var draggedElement;
    3.46 +      var mouseX;
    3.47 +      var mouseY;
    3.48 +      var mouseOffsetX;
    3.49 +      var mouseOffsetY;
    3.50 +      var elementOffsetX;
    3.51 +      var elementOffsetY;
    3.52 +      var dropFunc;
    3.53 +      var dragElement = function(element, func) {
    3.54 +        //if (typeof(element) == "string") element = document.getElementById(element);
    3.55 +        originalElement = element;
    3.56 +        draggedElement = originalElement.cloneNode(true);
    3.57 +        originalElement.style.visibility = "hidden";
    3.58 +        draggedElement.style.margin = 0;
    3.59 +        draggedElement.style.position = "absolute";
    3.60 +        draggedElement.style.left = elementOffsetX = originalElement.offsetLeft;
    3.61 +        draggedElement.style.top  = elementOffsetY = originalElement.offsetTop;
    3.62 +        draggedElement.style.width  = originalElement.clientWidth;
    3.63 +        draggedElement.style.height = originalElement.clientHeight;
    3.64 +        draggedElement.style.backgroundColor = "#eee";
    3.65 +        draggedElement.style.opacity = 0.8;
    3.66 +        originalElement.offsetParent.appendChild(draggedElement);
    3.67 +        // workaround for wrong clientWidth and clientHeight information:
    3.68 +        draggedElement.style.width = 2*originalElement.clientWidth - draggedElement.clientWidth;
    3.69 +        draggedElement.style.height = 2*originalElement.clientHeight - draggedElement.clientHeight;
    3.70 +        mouseOffsetX = mouseX;
    3.71 +        mouseOffsetY = mouseY;
    3.72 +        dropFunc = func;
    3.73 +      };
    3.74 +      window.addEventListener("mousemove", function(event) {
    3.75 +        jsProtect(function() {
    3.76 +          mouseX = event.pageX;
    3.77 +          mouseY = event.pageY;
    3.78 +          if (draggedElement) {
    3.79 +            draggedElement.style.left = elementOffsetX + mouseX - mouseOffsetX;
    3.80 +            draggedElement.style.top  = elementOffsetY + mouseY - mouseOffsetY;
    3.81 +          }
    3.82 +        });
    3.83 +      }, true);
    3.84 +      var mouseDrop = function(event) {
    3.85 +        jsProtect(function() {
    3.86 +          if (draggedElement) {
    3.87 +            dropFunc(
    3.88 +              originalElement,
    3.89 +              elementOffsetX + mouseX - mouseOffsetX,
    3.90 +              elementOffsetY + mouseY - mouseOffsetY
    3.91 +            );
    3.92 +            originalElement.style.visibility = '';
    3.93 +            draggedElement.parentNode.removeChild(draggedElement);
    3.94 +            originalElement = null;
    3.95 +            draggedElement = null;
    3.96 +          }
    3.97 +        });
    3.98 +      };
    3.99 +      window.addEventListener("mouseup",   mouseDrop, true);
   3.100 +      window.addEventListener("mousedown", mouseDrop, true);
   3.101 +      var elements = document.getElementsByTagName("*");
   3.102 +      for (var i=0; i<elements.length; i++) {
   3.103 +        var element = elements[i];
   3.104 +        if (element.className == "movable") {
   3.105 +          element.addEventListener("mousedown", function(event) {
   3.106 +            jsProtect(function() {
   3.107 +              event.target.style.cursor = "move";
   3.108 +              dragElement(event.currentTarget, function(element, dropX, dropY) {
   3.109 +                event.target.style.cursor = '';
   3.110 +                elementDropped(element, dropX, dropY);
   3.111 +              });
   3.112 +              event.preventDefault();
   3.113 +            });
   3.114 +          }, false);
   3.115 +        } else if (element.className == "clickable") {
   3.116 +          element.addEventListener("mousedown", function(event) {
   3.117 +            jsProtect(function() {
   3.118 +              event.stopPropagation();
   3.119 +            });
   3.120 +          }, false);
   3.121 +        }
   3.122        }
   3.123 -    }, true);
   3.124 -    var mouseDrop = function(event) {
   3.125 -      if (draggedElement) {
   3.126 -        dropFunc(
   3.127 -          originalElement,
   3.128 -          elementOffsetX + mouseX - mouseOffsetX,
   3.129 -          elementOffsetY + mouseY - mouseOffsetY
   3.130 -        );
   3.131 -        originalElement.style.visibility = '';
   3.132 -        draggedElement.parentNode.removeChild(draggedElement);
   3.133 -        originalElement = null;
   3.134 -        draggedElement = null;
   3.135 -      }
   3.136 -    };
   3.137 -    window.addEventListener("mouseup",   mouseDrop, true);
   3.138 -    window.addEventListener("mousedown", mouseDrop, true);
   3.139 -    var elements = document.getElementsByTagName("*");
   3.140 -    for (var i=0; i<elements.length; i++) {
   3.141 -      var element = elements[i];
   3.142 -      if (element.className == "movable") {
   3.143 -        element.addEventListener("mousedown", function(event) {
   3.144 -          event.target.style.cursor = "move";
   3.145 -          dragElement(event.currentTarget, function(element, dropX, dropY) {
   3.146 -            event.target.style.cursor = '';
   3.147 -            elementDropped(element, dropX, dropY);
   3.148 -          });
   3.149 -          event.preventDefault();
   3.150 -        }, false);
   3.151 -      } else if (element.className == "clickable") {
   3.152 -        element.addEventListener("mousedown", function(event) {
   3.153 -          event.stopPropagation();
   3.154 -        }, false);
   3.155 -      }
   3.156 -    }
   3.157 +    });
   3.158    }, false);
   3.159 -
   3.160 -}
   3.161 \ No newline at end of file
   3.162 +});
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/static/js/jsprotect.js	Thu Nov 08 13:17:37 2012 +0100
     4.3 @@ -0,0 +1,7 @@
     4.4 +function jsProtect(f) {
     4.5 +  if (!jsFail) try {
     4.6 +    return f();
     4.7 +  } catch (e) {
     4.8 +    jsFail = true;
     4.9 +  }
    4.10 +}
     5.1 --- a/static/js/voting.js	Tue Nov 06 21:28:25 2012 +0100
     5.2 +++ b/static/js/voting.js	Thu Nov 08 13:17:37 2012 +0100
     5.3 @@ -1,4 +1,4 @@
     5.4 -if (!jsFail) {
     5.5 +jsProtect(function() {
     5.6    voting_text_approval_single               = "Approval"
     5.7    voting_text_approval_multi                = "Approval"
     5.8    voting_text_first_preference_single       = "Approval (first preference)"
     5.9 @@ -99,57 +99,90 @@
    5.10      }
    5.11    }
    5.12    function voting_move(element, up, dropX, dropY) {
    5.13 -    if (typeof(element) == "string") element = document.getElementById(element);
    5.14 -    var mouse = (up == null);
    5.15 -    var oldParent = element.parentNode;
    5.16 -    if (mouse) var centerY = dropY + element.clientHeight / 2;
    5.17 -    var approvalCount = 0;
    5.18 -    var disapprovalCount = 0;
    5.19 -    var mainDiv = document.getElementById("voting");
    5.20 -    var sections = mainDiv.childNodes;
    5.21 -    for (var i=0; i<sections.length; i++) {
    5.22 -      var section = sections[i];
    5.23 -      if (section.className == "approval")       approvalCount++;
    5.24 -      if (section.className == "disapproval") disapprovalCount++;
    5.25 -    }
    5.26 -    if (mouse) {
    5.27 +    jsProtect(function() {
    5.28 +      if (typeof(element) == "string") element = document.getElementById(element);
    5.29 +      var mouse = (up == null);
    5.30 +      var oldParent = element.parentNode;
    5.31 +      if (mouse) var centerY = dropY + element.clientHeight / 2;
    5.32 +      var approvalCount = 0;
    5.33 +      var disapprovalCount = 0;
    5.34 +      var mainDiv = document.getElementById("voting");
    5.35 +      var sections = mainDiv.childNodes;
    5.36        for (var i=0; i<sections.length; i++) {
    5.37          var section = sections[i];
    5.38 -        if (
    5.39 -          section.className == "approval" ||
    5.40 -          section.className == "abstention" ||
    5.41 -          section.className == "disapproval"
    5.42 -        ) {
    5.43 +        if (section.className == "approval")       approvalCount++;
    5.44 +        if (section.className == "disapproval") disapprovalCount++;
    5.45 +      }
    5.46 +      if (mouse) {
    5.47 +        for (var i=0; i<sections.length; i++) {
    5.48 +          var section = sections[i];
    5.49            if (
    5.50 -            centerY >= section.offsetTop &&
    5.51 -            centerY <  section.offsetTop + section.clientHeight
    5.52 +            section.className == "approval" ||
    5.53 +            section.className == "abstention" ||
    5.54 +            section.className == "disapproval"
    5.55            ) {
    5.56 -            var entries = section.childNodes;
    5.57 -            for (var j=0; j<entries.length; j++) {
    5.58 -              var entry = entries[j];
    5.59 -              if (entry.className == "movable") {
    5.60 -                if (centerY < entry.offsetTop + entry.clientHeight / 2) {
    5.61 -                  if (element != entry) {
    5.62 -                    oldParent.removeChild(element);
    5.63 -                    section.insertBefore(element, entry);
    5.64 +            if (
    5.65 +              centerY >= section.offsetTop &&
    5.66 +              centerY <  section.offsetTop + section.clientHeight
    5.67 +            ) {
    5.68 +              var entries = section.childNodes;
    5.69 +              for (var j=0; j<entries.length; j++) {
    5.70 +                var entry = entries[j];
    5.71 +                if (entry.className == "movable") {
    5.72 +                  if (centerY < entry.offsetTop + entry.clientHeight / 2) {
    5.73 +                    if (element != entry) {
    5.74 +                      oldParent.removeChild(element);
    5.75 +                      section.insertBefore(element, entry);
    5.76 +                    }
    5.77 +                    break;
    5.78                    }
    5.79 -                  break;
    5.80                  }
    5.81                }
    5.82 +              if (j == entries.length) {
    5.83 +                oldParent.removeChild(element);
    5.84 +                section.appendChild(element);
    5.85 +              }
    5.86 +              break;
    5.87              }
    5.88 -            if (j == entries.length) {
    5.89 -              oldParent.removeChild(element);
    5.90 -              section.appendChild(element);
    5.91 -            }
    5.92 -            break;
    5.93            }
    5.94          }
    5.95 -      }
    5.96 -      if (i == sections.length) {
    5.97 -        var newSection = document.createElement("div");
    5.98 -        var cathead = document.createElement("div");
    5.99 -        cathead.setAttribute("class", "cathead");
   5.100 -        newSection.appendChild(cathead);
   5.101 +        if (i == sections.length) {
   5.102 +          var newSection = document.createElement("div");
   5.103 +          var cathead = document.createElement("div");
   5.104 +          cathead.setAttribute("class", "cathead");
   5.105 +          newSection.appendChild(cathead);
   5.106 +          for (var i=0; i<sections.length; i++) {
   5.107 +            var section = sections[i];
   5.108 +            if (
   5.109 +              section.className == "approval" ||
   5.110 +              section.className == "abstention" ||
   5.111 +              section.className == "disapproval"
   5.112 +            ) {
   5.113 +              if (centerY < section.offsetTop + section.clientHeight / 2) {
   5.114 +                if (section.className == "disapproval") {
   5.115 +                  newSection.setAttribute("class", "disapproval");
   5.116 +                  disapprovalCount++;
   5.117 +                } else {
   5.118 +                  newSection.setAttribute("class", "approval");
   5.119 +                  approvalCount++;
   5.120 +                }
   5.121 +                mainDiv.insertBefore(newSection, section);
   5.122 +                break;
   5.123 +              }
   5.124 +            }
   5.125 +          }
   5.126 +          if (i == sections.length) {
   5.127 +            newSection.setAttribute("class", "disapproval");
   5.128 +            disapprovalCount++;
   5.129 +            mainDiv.appendChild(newSection);
   5.130 +          }
   5.131 +          oldParent.removeChild(element);
   5.132 +          newSection.appendChild(element);
   5.133 +        }
   5.134 +      } else {
   5.135 +        var oldFound = false;
   5.136 +        var prevSection = null;
   5.137 +        var nextSection = null;
   5.138          for (var i=0; i<sections.length; i++) {
   5.139            var section = sections[i];
   5.140            if (
   5.141 @@ -157,195 +190,184 @@
   5.142              section.className == "abstention" ||
   5.143              section.className == "disapproval"
   5.144            ) {
   5.145 -            if (centerY < section.offsetTop + section.clientHeight / 2) {
   5.146 -              if (section.className == "disapproval") {
   5.147 -                newSection.setAttribute("class", "disapproval");
   5.148 -                disapprovalCount++;
   5.149 -              } else {
   5.150 -                newSection.setAttribute("class", "approval");
   5.151 -                approvalCount++;
   5.152 +            if (oldFound) {
   5.153 +              nextSection = section;
   5.154 +              break;
   5.155 +            } else if (section == oldParent) {
   5.156 +              oldFound = true;
   5.157 +            } else {
   5.158 +              prevSection = section;
   5.159 +            }
   5.160 +          }
   5.161 +        }
   5.162 +        var create;
   5.163 +        if (oldParent.className == "abstention") {
   5.164 +          create = true;
   5.165 +        } else {
   5.166 +          create = false;
   5.167 +          for (var i=0; i<oldParent.childNodes.length; i++) {
   5.168 +            var entry = oldParent.childNodes[i];
   5.169 +            if (entry.className == "movable") {
   5.170 +              if (entry != element) {
   5.171 +                create = true;
   5.172 +                break;
   5.173                }
   5.174 -              mainDiv.insertBefore(newSection, section);
   5.175 -              break;
   5.176              }
   5.177            }
   5.178          }
   5.179 -        if (i == sections.length) {
   5.180 -          newSection.setAttribute("class", "disapproval");
   5.181 -          disapprovalCount++;
   5.182 -          mainDiv.appendChild(newSection);
   5.183 +        var newSection;
   5.184 +        if (create) {
   5.185 +          newSection = document.createElement("div");
   5.186 +          var cathead = document.createElement("div");
   5.187 +          cathead.setAttribute("class", "cathead");
   5.188 +          newSection.appendChild(cathead);
   5.189 +          if (
   5.190 +            oldParent.className == "approval" ||
   5.191 +            (oldParent.className == "abstention" && up)
   5.192 +          ) {
   5.193 +            newSection.setAttribute("class", "approval");
   5.194 +            approvalCount++;
   5.195 +          } else {
   5.196 +            newSection.setAttribute("class", "disapproval");
   5.197 +            disapprovalCount++;
   5.198 +          }
   5.199 +          if (up) {
   5.200 +            mainDiv.insertBefore(newSection, oldParent);
   5.201 +          } else {
   5.202 +            if (nextSection) mainDiv.insertBefore(newSection, nextSection);
   5.203 +            else mainDiv.appendChild(newSection);
   5.204 +          }
   5.205 +        } else {
   5.206 +          if (up) newSection = prevSection;
   5.207 +          else newSection = nextSection;
   5.208          }
   5.209 -        oldParent.removeChild(element);
   5.210 -        newSection.appendChild(element);
   5.211 -      }
   5.212 -    } else {
   5.213 -      var oldFound = false;
   5.214 -      var prevSection = null;
   5.215 -      var nextSection = null;
   5.216 -      for (var i=0; i<sections.length; i++) {
   5.217 -        var section = sections[i];
   5.218 -        if (
   5.219 -          section.className == "approval" ||
   5.220 -          section.className == "abstention" ||
   5.221 -          section.className == "disapproval"
   5.222 -        ) {
   5.223 -          if (oldFound) {
   5.224 -            nextSection = section;
   5.225 -            break;
   5.226 -          } else if (section == oldParent) {
   5.227 -            oldFound = true;
   5.228 +        if (newSection) {
   5.229 +          oldParent.removeChild(element);
   5.230 +          if (create || up) {
   5.231 +            newSection.appendChild(element);
   5.232            } else {
   5.233 -            prevSection = section;
   5.234 -          }
   5.235 -        }
   5.236 -      }
   5.237 -      var create;
   5.238 -      if (oldParent.className == "abstention") {
   5.239 -        create = true;
   5.240 -      } else {
   5.241 -        create = false;
   5.242 -        for (var i=0; i<oldParent.childNodes.length; i++) {
   5.243 -          var entry = oldParent.childNodes[i];
   5.244 -          if (entry.className == "movable") {
   5.245 -            if (entry != element) {
   5.246 -              create = true;
   5.247 -              break;
   5.248 +            var inserted = false;
   5.249 +            for (var i=0; i<newSection.childNodes.length; i++) {
   5.250 +              var entry = newSection.childNodes[i];
   5.251 +              if (entry.className == "movable") {
   5.252 +                newSection.insertBefore(element, entry);
   5.253 +                inserted = true;
   5.254 +                break;
   5.255 +              }
   5.256              }
   5.257 +            if (!inserted) newSection.appendChild(element);
   5.258            }
   5.259          }
   5.260        }
   5.261 -      var newSection;
   5.262 -      if (create) {
   5.263 -        newSection = document.createElement("div");
   5.264 -        var cathead = document.createElement("div");
   5.265 -        cathead.setAttribute("class", "cathead");
   5.266 -        newSection.appendChild(cathead);
   5.267 +      // sections = mainDiv.childNodes;
   5.268 +      for (i=0; i<sections.length; i++) {
   5.269 +        var section = sections[i];
   5.270          if (
   5.271 -          oldParent.className == "approval" ||
   5.272 -          (oldParent.className == "abstention" && up)
   5.273 +          (section.className == "approval"    &&    approvalCount > 1) ||
   5.274 +          (section.className == "disapproval" && disapprovalCount > 1)
   5.275          ) {
   5.276 -          newSection.setAttribute("class", "approval");
   5.277 -          approvalCount++;
   5.278 -        } else {
   5.279 -          newSection.setAttribute("class", "disapproval");
   5.280 -          disapprovalCount++;
   5.281 -        }
   5.282 -        if (up) {
   5.283 -          mainDiv.insertBefore(newSection, oldParent);
   5.284 -        } else {
   5.285 -          if (nextSection) mainDiv.insertBefore(newSection, nextSection);
   5.286 -          else mainDiv.appendChild(newSection);
   5.287 -        }
   5.288 -      } else {
   5.289 -        if (up) newSection = prevSection;
   5.290 -        else newSection = nextSection;
   5.291 -      }
   5.292 -      if (newSection) {
   5.293 -        oldParent.removeChild(element);
   5.294 -        if (create || up) {
   5.295 -          newSection.appendChild(element);
   5.296 -        } else {
   5.297 -          var inserted = false;
   5.298 -          for (var i=0; i<newSection.childNodes.length; i++) {
   5.299 -            var entry = newSection.childNodes[i];
   5.300 -            if (entry.className == "movable") {
   5.301 -              newSection.insertBefore(element, entry);
   5.302 -              inserted = true;
   5.303 -              break;
   5.304 -            }
   5.305 +          var entries = section.childNodes;
   5.306 +          for (var j=0; j<entries.length; j++) {
   5.307 +            var entry = entries[j];
   5.308 +            if (entry.className == "movable") break;
   5.309            }
   5.310 -          if (!inserted) newSection.appendChild(element);
   5.311 +          if (j == entries.length) {
   5.312 +            section.parentNode.removeChild(section);
   5.313 +          }
   5.314          }
   5.315        }
   5.316 -    }
   5.317 -    // sections = mainDiv.childNodes;
   5.318 -    for (i=0; i<sections.length; i++) {
   5.319 -      var section = sections[i];
   5.320 -      if (
   5.321 -        (section.className == "approval"    &&    approvalCount > 1) ||
   5.322 -        (section.className == "disapproval" && disapprovalCount > 1)
   5.323 -      ) {
   5.324 -        var entries = section.childNodes;
   5.325 -        for (var j=0; j<entries.length; j++) {
   5.326 -          var entry = entries[j];
   5.327 -          if (entry.className == "movable") break;
   5.328 -        }
   5.329 -        if (j == entries.length) {
   5.330 -          section.parentNode.removeChild(section);
   5.331 -        }
   5.332 -      }
   5.333 -    }
   5.334 -    voting_setCategoryHeadings();
   5.335 +      voting_setCategoryHeadings();
   5.336 +    });
   5.337    }
   5.338    function elementDropped(element, dropX, dropY) {
   5.339      voting_move(element, null, dropX, dropY);
   5.340    }
   5.341    window.addEventListener("load", function(event) {
   5.342 -    voting_setCategoryHeadings();
   5.343 -    var mainDiv = document.getElementById("voting");
   5.344 -    var form = document.getElementById("voting_form");
   5.345 -    var elements = document.getElementsByTagName("input");
   5.346 -    for (var i=0; i<elements.length; i++) {
   5.347 -      var element = elements[i];
   5.348 -      if (element.className == "voting_done1" ||
   5.349 -          element.className == "voting_done2" ||
   5.350 -          element.name == "preview") {
   5.351 -        element.addEventListener("click", function(event) {
   5.352 -          if (event.target.name == "preview") {
   5.353 -            document.getElementById("preview2").value = "1";
   5.354 -          }
   5.355 -          var scoringString = "";
   5.356 -          var approvalCount = 0;
   5.357 -          var disapprovalCount = 0;
   5.358 -          var sections = mainDiv.childNodes;
   5.359 -          for (var j=0; j<sections.length; j++) {
   5.360 -            var section = sections[j];
   5.361 -            if (section.className == "approval")       approvalCount++;
   5.362 -            if (section.className == "disapproval") disapprovalCount++;
   5.363 -          }
   5.364 -          var approvalIndex = 0;
   5.365 -          var disapprovalIndex = 0;
   5.366 -          for (var j=0; j<sections.length; j++) {
   5.367 -            var section = sections[j];
   5.368 -            if (
   5.369 -              section.className == "approval"    ||
   5.370 -              section.className == "abstention"  ||
   5.371 -              section.className == "disapproval"
   5.372 -            ) {
   5.373 -              var score;
   5.374 -              if (section.className == "approval") {
   5.375 -                score = approvalCount - approvalIndex;
   5.376 -                approvalIndex++;
   5.377 -              } else if (section.className == "abstention") {
   5.378 -                score = 0;
   5.379 -              } else if (section.className == "disapproval") {
   5.380 -                score = -1 - disapprovalIndex;
   5.381 -                disapprovalIndex++;
   5.382 +    jsProtect(function() {
   5.383 +      var jsTest = true;
   5.384 +      var jsTestSuccess = false;
   5.385 +      voting_setCategoryHeadings();
   5.386 +      var mainDiv = document.getElementById("voting");
   5.387 +      var form = document.getElementById("voting_form");
   5.388 +      var elements = document.getElementsByTagName("input");
   5.389 +      for (var i=0; i<elements.length; i++) {
   5.390 +        var element = elements[i];
   5.391 +        if (element.className == "voting_done1" ||
   5.392 +            element.className == "voting_done2" ||
   5.393 +            element.name == "preview") {
   5.394 +          element.addEventListener("click", function(event) {
   5.395 +            jsProtect(function() {
   5.396 +              event.preventDefault();
   5.397 +              if (event.target.name == "preview") {
   5.398 +                document.getElementById("preview2").value = "1";
   5.399 +              }
   5.400 +              var scoringString = "";
   5.401 +              var approvalCount = 0;
   5.402 +              var disapprovalCount = 0;
   5.403 +              var sections = mainDiv.childNodes;
   5.404 +              for (var j=0; j<sections.length; j++) {
   5.405 +                var section = sections[j];
   5.406 +                if (section.className == "approval")       approvalCount++;
   5.407 +                if (section.className == "disapproval") disapprovalCount++;
   5.408                }
   5.409 -              var entries = section.childNodes;
   5.410 -              for (var k=0; k<entries.length; k++) {
   5.411 -                var entry = entries[k];
   5.412 -                if (entry.className == "movable") {
   5.413 -                  var id = entry.id.match(/[0-9]+/);
   5.414 -                  var field = document.createElement("input");
   5.415 -                  scoringString += id + ":" + score + ";";
   5.416 +              var approvalIndex = 0;
   5.417 +              var disapprovalIndex = 0;
   5.418 +              for (var j=0; j<sections.length; j++) {
   5.419 +                var section = sections[j];
   5.420 +                if (
   5.421 +                  section.className == "approval"    ||
   5.422 +                  section.className == "abstention"  ||
   5.423 +                  section.className == "disapproval"
   5.424 +                ) {
   5.425 +                  var score;
   5.426 +                  if (section.className == "approval") {
   5.427 +                    score = approvalCount - approvalIndex;
   5.428 +                    approvalIndex++;
   5.429 +                  } else if (section.className == "abstention") {
   5.430 +                    score = 0;
   5.431 +                  } else if (section.className == "disapproval") {
   5.432 +                    score = -1 - disapprovalIndex;
   5.433 +                    disapprovalIndex++;
   5.434 +                  }
   5.435 +                  var entries = section.childNodes;
   5.436 +                  for (var k=0; k<entries.length; k++) {
   5.437 +                    var entry = entries[k];
   5.438 +                    if (entry.className == "movable") {
   5.439 +                      var id = entry.id.match(/[0-9]+/);
   5.440 +                      var field = document.createElement("input");
   5.441 +                      scoringString += id + ":" + score + ";";
   5.442 +                    }
   5.443 +                  }
   5.444                  }
   5.445                }
   5.446 -            }
   5.447 -          }
   5.448 -          var fields = form.childNodes;
   5.449 -          for (var j=0; j<fields.length; j++) {
   5.450 -            var field = fields[j];
   5.451 -            if (field.name == "scoring") {
   5.452 -              field.setAttribute("value", scoringString);
   5.453 -              form.submit();
   5.454 -              return;
   5.455 -            }
   5.456 -          }
   5.457 -          alert('Hidden input field named "scoring" not found.');
   5.458 -        }, false);
   5.459 +              var fields = form.childNodes;
   5.460 +              for (var j=0; j<fields.length; j++) {
   5.461 +                var field = fields[j];
   5.462 +                if (field.name == "scoring") {
   5.463 +                  field.setAttribute("value", scoringString);
   5.464 +                  if (jsTest) {
   5.465 +                    jsTestSuccess = success;
   5.466 +                    return;
   5.467 +                  } else {
   5.468 +                    form.submit();
   5.469 +                    return;
   5.470 +                  }
   5.471 +                }
   5.472 +              }
   5.473 +              alert('Hidden input field named "scoring" not found.');
   5.474 +            });
   5.475 +          }, false);
   5.476 +        }
   5.477        }
   5.478 -    }
   5.479 +      for (var i=0; i<elements.length; i++) {
   5.480 +        var element = elements[i];
   5.481 +        if (element.className == "voting_done1") {
   5.482 +          element.click();
   5.483 +        }
   5.484 +      }
   5.485 +      jsTest = false;
   5.486 +      if (!jsTestSuccess) jsFail = true;
   5.487 +    });
   5.488    }, false);
   5.489    function voting_moveUp(element) {
   5.490      return voting_move(element, true);
   5.491 @@ -353,6 +375,4 @@
   5.492    function voting_moveDown(element) {
   5.493      return voting_move(element, false);
   5.494    }
   5.495 -
   5.496 -  
   5.497 -}
   5.498 +});

Impressum / About Us