Mercurial > eldonilo > barbecue
diff sxe-document.js @ 6:24aa8dccb170
Make XMPP actually work.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 31 Jan 2012 15:59:28 +0100 |
parents | 03ef53b969bd |
children | 7b2ca4d5af6d |
line wrap: on
line diff
--- a/sxe-document.js +++ b/sxe-document.js @@ -1,5 +1,26 @@ 'use strict'; +/** Copyright (c) 2012 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> + * + * 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]); } };