summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--proto.js101
1 files changed, 57 insertions, 44 deletions
diff --git a/proto.js b/proto.js
index 2d5e9c0..c57e133 100644
--- a/proto.js
+++ b/proto.js
@@ -106,72 +106,85 @@ try {
socket_lm.onopen = function() {
document.getElementById("wslm_status").style.backgroundColor = "#40ff40";
document.getElementById("wslm_status").textContent = " websocket connection opened ";
- document.getElementById("box").style.display = "none";
+ // document.getElementById("box").style.display = "none";
}
socket_lm.onmessage = function got_packet(msg) {
document.getElementById("wslm_lastmsg").textContent = msg.data;
- /*
- m = '';
- escape = false;
- for(i = 0; i < msg.data.length; i++) {
- if(msg.data[i] == '\\' && escape == false) {
- escape = true;
- continue;
- }
- if(escape) m += msg.data[i];
- else {
- if(m += msg.data[i])
+
+ var msgs = new Array();
+ var idx = 0;
+ msgs[idx] = '';
+ var c = 0;
+ var instring = false;
+ for(c = 0; c < msg.data.length; c++) {
+ if(msg.data[c] == '"' && c > 0 && msg.data[c - 1] != '\\') instring = !instring;
+ if(msg.data[c] == ';' && instring == false) {
+ idx++;
+ msgs[idx] = '';
}
+ if(msg.data[c] != ';' || instring == true) msgs[idx] += msg.data[c];
}
- j = m.split(';');
- */
- j = msg.data.split(';');
+
f = 0;
- while (f < j.length - 1) {
- i = j[f].split(' ');
- if (i[0] == 'd') {
- ctx.strokeStyle = i[1];
- ctx.beginPath();
- ctx.moveTo(+(i[2]), +(i[3]));
- ctx.lineTo(+(i[4]), +(i[5]));
- ctx.stroke();
- }
- else if (i[0] == 'c') {
- ctx.strokeStyle = i[1];
- ctx.beginPath();
- ctx.arc(+(i[2]), +(i[3]), +(i[4]), 0, Math.PI*2, true);
- ctx.stroke();
+ while (f < msgs.length - 1) {
+ var msg = new Array();
+ instring = false;
+ idx = 0;
+ msg[idx] = '';
+ for(c = 0; c < msgs[f].length; c++) {
+ if(msgs[f][c] == '"' && c > 0 && msgs[f][c - 1] != '\\') {
+ instring = !instring;
+ continue;
+ }
+ if(msgs[f][c] == ' ' && instring == false) {
+ msg[idx] = msg[idx].replace("\\\\","\\").replace("\\\"","\"");
+ idx++;
+ msg[idx] = '';
+ }
+ if(msgs[f][c] != ' ' || instring == true) msg[idx] += msgs[f][c];
}
- else if (i[0] == "del") {
- var task = document.getElementById("task_" + i[1]);
-// task.style.display = "none";
+
+ var cmd = msg[0];
+
+ if(cmd == "del") {
+ var id = msg[1];
+ var task = document.getElementById("task_" + id);
document.body.removeChild(task);
}
- else if (i[0] == "move") {
- var task = document.getElementById("task_" + i[1]);
- task.style.left = i[2] + "px";
- task.style.top = i[3] + "px";
+ else if(cmd == "move") {
+ var id = msg[1];
+ var left = msg[2];
+ var top = msg[3];
+ var task = document.getElementById("task_" + id);
+ task.style.left = left + "px";
+ task.style.top = top + "px";
}
- else if (i[0] == "add") {
+ else if(cmd == "add") {
+ var id = msg[1];
+ var title = msg[2];
+ var description = msg[3];
+ var left = msg[4];
+ var top = msg[5];
+
var task = document.createElement("div");
task.name = "task";
- task.setAttribute("class", "task");
- task.id = "task_" + i[1];
+ task.setAttribute("class", "task");
+ task.id = "task_" + id;
- var taskText = document.createTextNode(i[2] + ": " + i[3] + " :" + task.id);
+ var taskText = document.createTextNode(title + ": " + description + " :" + task.id);
task.appendChild(taskText);
task.style.position = "absolute";
- task.style.left = i[4] + "px";
- task.style.top = i[5] + "px";
- task.setAttribute("onMouseDown", "dragged = '" + i[1] + "';");
+ task.style.left = left + "px";
+ task.style.top = top + "px";
+ task.setAttribute("onMouseDown", "dragged = '" + id + "';");
var dlButton = document.createElement("input");
dlButton.type = "button";
dlButton.value = "Remove";
// dlButton.onclick = "deleteTask(document.getElementById(" + task.id + ").id";
- dlButton.setAttribute("onclick", "deleteTask(" + i[1] +")");
+ dlButton.setAttribute("onclick", "deleteTask(" + id +")");
task.appendChild(dlButton);
document.body.appendChild(task);