Mercurial > eldonilo > barbecue
comparison 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 |
comparison
equal
deleted
inserted
replaced
5:03ef53b969bd | 6:24aa8dccb170 |
---|---|
1 'use strict'; | 1 'use strict'; |
2 | |
3 /** Copyright (c) 2012 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | |
4 * | |
5 * Permission is hereby granted, free of charge, to any person obtaining a copy | |
6 * of this software and associated documentation files (the "Software"), to | |
7 * deal in the Software without restriction, including without limitation the | |
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
9 * sell copies of the Software, and to permit persons to whom the Software is | |
10 * furnished to do so, subject to the following conditions: | |
11 * | |
12 * The above copyright notice and this permission notice shall be included in | |
13 * all copies or substantial portions of the Software. | |
14 * | |
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
21 * IN THE SOFTWARE. | |
22 */ | |
2 | 23 |
3 var Document = function(initiator, name, host, domId, prolog) { | 24 var Document = function(initiator, name, host, domId, prolog) { |
4 this.initiator = initiator; | 25 this.initiator = initiator; |
5 this.name = name; | 26 this.name = name; |
6 this.host = host; | 27 this.host = host; |
79 var child = elements[i]; | 100 var child = elements[i]; |
80 var change = child.localName; | 101 var change = child.localName; |
81 | 102 |
82 switch (change) { | 103 switch (change) { |
83 case 'new': | 104 case 'new': |
84 doc.add(jid, child); | 105 this.add(jid, child); |
85 break; | 106 break; |
86 case 'set': | 107 case 'set': |
87 doc.update(jid, child); | 108 this.update(jid, child); |
88 break; | 109 break; |
89 case 'remove': | 110 case 'remove': |
90 doc.remove(jid, child); | 111 this.remove(jid, child); |
91 break; | 112 break; |
92 case 'document-end': | 113 case 'document-end': |
93 this.state = 'started'; | 114 this.state = 'started'; |
94 break; | 115 break; |
95 } | 116 } |
96 } | 117 } |
97 }, | 118 }, |
98 createState: function(root, parent, state) { | 119 createState: function(state, root, parent) { |
120 if (!root) | |
121 root = this.dom; | |
99 var children = root.childNodes; | 122 var children = root.childNodes; |
123 | |
100 for (var i = 0; i < children.length; i++) { | 124 for (var i = 0; i < children.length; i++) { |
101 var child = children[i]; | 125 var child = children[i]; |
102 var element = document.createElementNS(Lightstring.NS.sxe, 'new'); | 126 var element = document.createElementNS(Lightstring.NS.sxe, 'new'); |
103 var rid = Lightstring.newId('GUID'); | 127 var rid = Lightstring.newId('GUID'); |
104 element.setAttributeNS(null, 'rid', rid); | 128 element.setAttributeNS(null, 'rid', rid); |
114 state.push(element); | 138 state.push(element); |
115 | 139 |
116 //TODO: move that elsewhere, or make it prettier. | 140 //TODO: move that elsewhere, or make it prettier. |
117 var convertAttr = function(attr) { | 141 var convertAttr = function(attr) { |
118 var element = document.createElementNS(Lightstring.NS.sxe, 'new'); | 142 var element = document.createElementNS(Lightstring.NS.sxe, 'new'); |
143 element.setAttributeNS(null, 'type', 'attr'); | |
119 var arid = Lightstring.newId('GUID'); | 144 var arid = Lightstring.newId('GUID'); |
120 element.setAttributeNS(null, 'rid', arid); | 145 element.setAttributeNS(null, 'rid', arid); |
121 element.setAttributeNS(null, 'parent', rid); | 146 element.setAttributeNS(null, 'parent', rid); |
122 if (attr.namespaceURI) | 147 if (attr.namespaceURI) |
123 element.setAttributeNS(null, 'ns', attr.namespaceURI); | 148 element.setAttributeNS(null, 'ns', attr.namespaceURI); |
127 }; | 152 }; |
128 | 153 |
129 for (var j = 0; j < child.attributes.length; j++) | 154 for (var j = 0; j < child.attributes.length; j++) |
130 convertAttr(child.attributes[j]); | 155 convertAttr(child.attributes[j]); |
131 | 156 |
132 state = this.createState(child, rid, state); | 157 state = this.createState(state, child, rid); |
133 break; | 158 break; |
134 | 159 |
135 case 3: | 160 case 3: |
136 element.setAttributeNS(null, 'type', 'text'); | 161 element.setAttributeNS(null, 'type', 'text'); |
137 element.setAttributeNS(null, 'chdata', child.textContent); | 162 element.setAttributeNS(null, 'chdata', child.textContent); |
151 state.push(element); | 176 state.push(element); |
152 break; | 177 break; |
153 } | 178 } |
154 } | 179 } |
155 return state; | 180 return state; |
181 }, | |
182 empty: function() { | |
183 var children = this.dom.childNodes; | |
184 for (var i = children.length - 1; i >= 0; i--) | |
185 this.dom.removeChild(children[i]); | |
156 } | 186 } |
157 }; | 187 }; |