diff options
-rw-r--r-- | web/nms.gathering.org/ping.html | 1 | ||||
-rw-r--r-- | web/nms.gathering.org/ping.js | 52 |
2 files changed, 28 insertions, 25 deletions
diff --git a/web/nms.gathering.org/ping.html b/web/nms.gathering.org/ping.html index 3aea383..44d6d89 100644 --- a/web/nms.gathering.org/ping.html +++ b/web/nms.gathering.org/ping.html @@ -14,6 +14,7 @@ var switches_url = "/switches-json.pl"; var ping_url = "/ping-json.pl"; var draw_linknets = true; + var can_edit = true; </script> <script type="text/javascript" src="ping.js"></script> </body> diff --git a/web/nms.gathering.org/ping.js b/web/nms.gathering.org/ping.js index 3b99257..73aced3 100644 --- a/web/nms.gathering.org/ping.js +++ b/web/nms.gathering.org/ping.js @@ -196,35 +196,37 @@ function create_switch(switchnum, sysname, x, y, zorder, width, height) { var dragging_switch = null; var delta_x = null, delta_y = null; -document.onmousedown = function(e) { - var switchnum = e.target.getAttribute("data-switchnum"); - if (switchnum === null) { - return; +if (can_edit) { + document.onmousedown = function(e) { + var switchnum = e.target.getAttribute("data-switchnum"); + if (switchnum === null) { + return; + } + dragging_switch = switchnum; + delta_x = parseInt(e.target.style.left.replace("px", "")) - e.clientX; + delta_y = parseInt(e.target.style.top.replace("px", "")) - e.clientY; } - dragging_switch = switchnum; - delta_x = parseInt(e.target.style.left.replace("px", "")) - e.clientX; - delta_y = parseInt(e.target.style.top.replace("px", "")) - e.clientY; -} -document.onmousemove = function(e) { - if (dragging_switch === null) { - return; + document.onmousemove = function(e) { + if (dragging_switch === null) { + return; + } + switches[dragging_switch].style.left = (e.clientX + delta_x) + 'px'; + switches[dragging_switch].style.top = (e.clientY + delta_y) + 'px'; } - switches[dragging_switch].style.left = (e.clientX + delta_x) + 'px'; - switches[dragging_switch].style.top = (e.clientY + delta_y) + 'px'; -} -document.onmouseup = function(e) { - if (dragging_switch === null) { - return; - } - var x = e.clientX + delta_x - map.getBoundingClientRect().top; - var y = e.clientY + delta_y - map.getBoundingClientRect().left; + document.onmouseup = function(e) { + if (dragging_switch === null) { + return; + } + var x = e.clientX + delta_x - map.getBoundingClientRect().top; + var y = e.clientY + delta_y - map.getBoundingClientRect().left; - var request = new XMLHttpRequest(); - request.open('POST', '/change-switch-pos.pl', true); - request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); - request.send("switch=" + dragging_switch + "&x=" + x + "&y=" + y); + var request = new XMLHttpRequest(); + request.open('POST', '/change-switch-pos.pl', true); + request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); + request.send("switch=" + dragging_switch + "&x=" + x + "&y=" + y); - dragging_switch = null; + dragging_switch = null; + } } |