summaryrefslogtreecommitdiffhomepage
path: root/html/whiteboard.js
diff options
context:
space:
mode:
Diffstat (limited to 'html/whiteboard.js')
-rw-r--r--html/whiteboard.js27
1 files changed, 23 insertions, 4 deletions
diff --git a/html/whiteboard.js b/html/whiteboard.js
index 58023fe..3e09621 100644
--- a/html/whiteboard.js
+++ b/html/whiteboard.js
@@ -48,6 +48,26 @@ function on_getfile(data, rev, pos)
textAreaSetPos("board", pos);
}
+function on_getdiff(diff, rev)
+{
+ if (rev != revision + 1)
+ alert("Revision skipped: " + rev + " after " + revision);
+
+ var board = document.getElementById("board");
+
+ var old_version_ptr = allocateUTF8(board.value);
+ var diff_ptr = allocateUTF8(new XMLSerializer().serializeToString(diff));
+ var new_version_ptr = Module._diff_apply(old_version_ptr, diff_ptr);
+ var data = UTF8ToString(new_version_ptr);
+ board.value = data;
+ _free(old_version_ptr);
+ _free(new_version_ptr);
+ _free(diff_ptr);
+
+ revision = rev;
+ baseline = data;
+}
+
function on_getpos(pos)
{
textAreaSetPos("board", pos);
@@ -88,6 +108,9 @@ function on_message(e) {
on_getfile(xmlDocument.getElementsByTagName("data")[0].textContent,
parseInt(xmlDocument.getElementsByTagName("revision")[0].textContent),
parseInt(xmlDocument.getElementsByTagName("pos")[0].textContent));
+ } else if (type == "getdiff") {
+ on_getdiff(xmlDocument.getElementsByTagName("diff")[0],
+ parseInt(xmlDocument.getElementsByTagName("revision")[0].textContent));
} else if (type == "getpos") {
on_getpos(parseInt(xmlDocument.getElementsByTagName("pos")[0].textContent));
} else if (type == "modify") {
@@ -216,10 +239,6 @@ function on_input()
idElement.appendChild(document.createTextNode(get_id()));
requestElement.appendChild(idElement);
- var dataElement = xmlDocument.createElement("data");
- dataElement.appendChild(document.createTextNode(document.getElementById("board").value));
- requestElement.appendChild(dataElement);
-
baseline_candidate = document.getElementById("board").value;
var revisionElement = xmlDocument.createElement("baserev");