# HG changeset patch # User Emmanuel Gil Peyrot # Date 1328021968 -3600 # Node ID 24aa8dccb1701f9972c91893151c49103a17d34f # Parent 03ef53b969bdf524353ac95f2f7597f2142c696c Make XMPP actually work. diff --git a/index.xhtml b/index.xhtml --- a/index.xhtml +++ b/index.xhtml @@ -17,6 +17,8 @@ +
+
edit:
@@ -96,7 +98,7 @@ -
+

Go ahead, edit away!

Here's a typical paragraph element

  1. and now a list
  2. with only
  3. three items
diff --git a/record.js b/record.js --- a/record.js +++ b/record.js @@ -1,5 +1,26 @@ 'use strict'; +/** Copyright (c) 2012 Emmanuel Gil Peyrot + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + var Record = function(jid, child) { this.creator = jid; this.creationDate = new Date; //FIXME: non-standard? @@ -31,7 +52,7 @@ Record.prototype = { } }, toDOM: function(records, dom) { - var element; + var element = null; if (this.parent) dom = records[this.parent].dom; @@ -61,6 +82,9 @@ Record.prototype = { case 'comment': element = document.createComment(this.chdata); break; + default: + console.log('BIG WARNING! Element type not supported.'); + return; } dom.appendChild(element); diff --git a/script2.js b/script2.js --- a/script2.js +++ b/script2.js @@ -109,15 +109,17 @@ var initiate = function(jid, sid) { }; var accept = function(sid) { - var accept = "" + + var doc = documents[sid]; + doc.empty(); + var accept = "" + "" + "" + "" + "" + - "" + documents[sid].host + "" + + "" + doc.host + "" + "" + "" + "" + @@ -293,6 +295,9 @@ conn.on('message/' + Lightstring.NS.sxe conn.send(message); break; case 'accept-state': + var initialState = doc.createState([]).map(function(element) { + return Lightstring.DOM2XML(element); + }).join(''); var message = "" + "" + "" + "" + - //TODO: support non-empty documents. + initialState + "" + "" + "" + diff --git a/sxe-document.js b/sxe-document.js --- a/sxe-document.js +++ b/sxe-document.js @@ -1,5 +1,26 @@ 'use strict'; +/** Copyright (c) 2012 Emmanuel Gil Peyrot + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + var Document = function(initiator, name, host, domId, prolog) { this.initiator = initiator; this.name = name; @@ -81,13 +102,13 @@ Document.prototype = { switch (change) { case 'new': - doc.add(jid, child); + this.add(jid, child); break; case 'set': - doc.update(jid, child); + this.update(jid, child); break; case 'remove': - doc.remove(jid, child); + this.remove(jid, child); break; case 'document-end': this.state = 'started'; @@ -95,8 +116,11 @@ Document.prototype = { } } }, - createState: function(root, parent, state) { + createState: function(state, root, parent) { + if (!root) + root = this.dom; var children = root.childNodes; + for (var i = 0; i < children.length; i++) { var child = children[i]; var element = document.createElementNS(Lightstring.NS.sxe, 'new'); @@ -116,6 +140,7 @@ Document.prototype = { //TODO: move that elsewhere, or make it prettier. var convertAttr = function(attr) { var element = document.createElementNS(Lightstring.NS.sxe, 'new'); + element.setAttributeNS(null, 'type', 'attr'); var arid = Lightstring.newId('GUID'); element.setAttributeNS(null, 'rid', arid); element.setAttributeNS(null, 'parent', rid); @@ -129,7 +154,7 @@ Document.prototype = { for (var j = 0; j < child.attributes.length; j++) convertAttr(child.attributes[j]); - state = this.createState(child, rid, state); + state = this.createState(state, child, rid); break; case 3: @@ -153,5 +178,10 @@ Document.prototype = { } } return state; + }, + empty: function() { + var children = this.dom.childNodes; + for (var i = children.length - 1; i >= 0; i--) + this.dom.removeChild(children[i]); } };