annotate sxe-document.js @ 9:d3b37bbb2b88 default tip master

Support multiple participants.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 02 Feb 2012 16:37:28 +0100
parents 7b2ca4d5af6d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 'use strict';
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2
6
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
3 /** Copyright (c) 2012 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
4 *
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
6 * of this software and associated documentation files (the "Software"), to
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
7 * deal in the Software without restriction, including without limitation the
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
9 * sell copies of the Software, and to permit persons to whom the Software is
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
10 * furnished to do so, subject to the following conditions:
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
11 *
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
12 * The above copyright notice and this permission notice shall be included in
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
13 * all copies or substantial portions of the Software.
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
14 *
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
21 * IN THE SOFTWARE.
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
22 */
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
23
5
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 var Document = function(initiator, name, host, domId, prolog) {
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 this.initiator = initiator;
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 this.name = name;
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 this.host = host;
8
7b2ca4d5af6d Add a resend-whole-state button and make it works.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6
diff changeset
28 this.participants = {};
5
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 this.prolog = prolog || 'data:application/xhtml+xml,%3C%3Fxml%20version%3D%271.0%27%3F%3E%0A%3C%21DOCTYPE%20html%3E%0A';
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 this.state = 'not-started';
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32 this.records = {};
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 this.dom = document.getElementById(domId);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 };
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36 Document.prototype = {
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 add: function(jid, child) {
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38 var record = new Record(jid, child);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 if (record.rid in this.records)
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 console.log('duplicate new');
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43 this.records[record.rid] = record;
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 record.toDOM(this.records, this.dom);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 },
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46 update: function(jid, child) {
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 var target = child.getAttributeNS(null, 'target');
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 if (!(target in this.records))
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 return; // Ignore it.
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52 var record = this.records[target];
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 console.log(record, child);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 child.setAttributeNS(null, 'rid', target);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56 var version = +child.getAttributeNS(null, 'version');
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57 if (this.state === 'getting-state')
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 record.version = version;
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 else
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60 record.version++;
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 if (record.version === version) {
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63 var type = child.getAttributeNS(null, 'type');
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 if (type === 'text' || type === 'attr' || type === 'comment') {
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 var chdata = child.getAttributeNS(null, 'chdata');
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66 var replacefrom = +child.getAttributeNS(null, 'replacefrom');
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 var replacen = +child.getAttributeNS(null, 'replacen');
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 if (chdata && replacefrom && replacen) {
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69 var string = record.chdata.substr(0, replacefrom);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 string += chdata;
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71 string += record.chdata.substr(replacefrom + replacen);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 child.removeAttributeNS(null, 'replacefrom');
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 child.removeAttributeNS(null, 'replacen');
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 child.setAttributeNS(null, 'chdata', string);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 }
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76 }
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77 record.update(jid, child);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78 record.toDOM(this.records, this.dom);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 } else
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 ; // Not sure I understand correctly.
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81 },
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
82 remove: function(jid, child) {
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
83 var rid = child.getAttributeNS(null, 'target');
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 this.records[rid].remove(this.records);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85 delete this.records[rid];
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86 },
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87 processState: function(jid, elements) {
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 var i = 0;
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89 var first = elements[0];
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 if (first.localName === 'document-begin') {
8
7b2ca4d5af6d Add a resend-whole-state button and make it works.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6
diff changeset
91 /*if (this.state !== 'not-started')
7b2ca4d5af6d Add a resend-whole-state button and make it works.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6
diff changeset
92 return;*/ //TODO: the session has already started.
5
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93 i = 1;
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
94 this.prolog = first.getAttributeNS(null, 'prolog');
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95 this.state = 'getting-session';
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96 }
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98 //TODO: if the session isn’t started, should ignore changes?
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100 for (; i < elements.length; i++) {
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101 var child = elements[i];
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
102 var change = child.localName;
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
103
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
104 switch (change) {
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
105 case 'new':
6
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
106 this.add(jid, child);
5
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
107 break;
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
108 case 'set':
6
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
109 this.update(jid, child);
5
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
110 break;
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
111 case 'remove':
6
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
112 this.remove(jid, child);
5
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
113 break;
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
114 case 'document-end':
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
115 this.state = 'started';
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
116 break;
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
117 }
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
118 }
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
119 },
6
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
120 createState: function(state, root, parent) {
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
121 if (!root)
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
122 root = this.dom;
5
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
123 var children = root.childNodes;
6
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
124
5
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
125 for (var i = 0; i < children.length; i++) {
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
126 var child = children[i];
8
7b2ca4d5af6d Add a resend-whole-state button and make it works.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6
diff changeset
127 var element = document.createElementNS(Lightstring.ns['sxe'], 'new');
5
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
128 var rid = Lightstring.newId('GUID');
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
129 element.setAttributeNS(null, 'rid', rid);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
130
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
131 if (parent)
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
132 element.setAttributeNS(null, 'parent', parent);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
133
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
134 switch (child.nodeType) {
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
135 case 1:
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
136 element.setAttributeNS(null, 'type', 'element');
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
137 element.setAttributeNS(null, 'ns', child.namespaceURI);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
138 element.setAttributeNS(null, 'name', child.localName);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
139 state.push(element);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
140
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
141 //TODO: move that elsewhere, or make it prettier.
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
142 var convertAttr = function(attr) {
8
7b2ca4d5af6d Add a resend-whole-state button and make it works.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 6
diff changeset
143 var element = document.createElementNS(Lightstring.ns['sxe'], 'new');
6
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
144 element.setAttributeNS(null, 'type', 'attr');
5
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
145 var arid = Lightstring.newId('GUID');
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
146 element.setAttributeNS(null, 'rid', arid);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
147 element.setAttributeNS(null, 'parent', rid);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
148 if (attr.namespaceURI)
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
149 element.setAttributeNS(null, 'ns', attr.namespaceURI);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
150 element.setAttributeNS(null, 'name', attr.localName);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
151 element.setAttributeNS(null, 'chdata', attr.textContent);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
152 state.push(element);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
153 };
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
154
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
155 for (var j = 0; j < child.attributes.length; j++)
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
156 convertAttr(child.attributes[j]);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
157
6
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
158 state = this.createState(state, child, rid);
5
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
159 break;
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
160
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
161 case 3:
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
162 element.setAttributeNS(null, 'type', 'text');
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
163 element.setAttributeNS(null, 'chdata', child.textContent);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
164 state.push(element);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
165 break;
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
166
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
167 case 7:
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
168 element.setAttributeNS(null, 'type', 'processinginstruction');
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
169 element.setAttributeNS(null, 'pitarget', child.target);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
170 element.setAttributeNS(null, 'pidata', child.data);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
171 state.push(element);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
172 break;
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
173
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
174 case 8:
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
175 element.setAttributeNS(null, 'type', 'comment');
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
176 element.setAttributeNS(null, 'chdata', child.textContent);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
177 state.push(element);
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
178 break;
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
179 }
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
180 }
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
181 return state;
6
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
182 },
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
183 empty: function() {
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
184 var children = this.dom.childNodes;
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
185 for (var i = children.length - 1; i >= 0; i--)
24aa8dccb170 Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
186 this.dom.removeChild(children[i]);
5
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
187 }
03ef53b969bd Add XMPP support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
188 };