annotate stanza.js @ 109:cd1f57661439 default tip

Fix files permissions.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 01 Aug 2012 23:18:03 +0200
parents 5cb4733c5189
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
1 'use strict';
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
2
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
3 /**
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
4 Copyright (c) 2011, Sonny Piers <sonny at fastmail dot net>
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
5
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
6 Permission to use, copy, modify, and/or distribute this software for any
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
7 purpose with or without fee is hereby granted, provided that the above
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
8 copyright notice and this permission notice appear in all copies.
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
9
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
17 */
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
18
108
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
19 (function() {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
20
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
21 if (typeof define !== 'undefined') {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
22 define(function() {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
23 return {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
24 'stanza': Stanza,
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
25 'presence': Presence,
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
26 'iq': IQ,
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
27 'message': Message,
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
28 'doc': doc,
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
29 };
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
30 });
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
31 }
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
32 else {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
33 Lightstirng.Stanza = Stanza;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
34 Lightstirng.Presence = Presence;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
35 Lightstirng.IQ = IQ;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
36 Lightstirng.Message = Message;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
37 Lightstirng.doc = doc;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
38 }
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
39
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
40 /**
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
41 * @private
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
42 */
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
43 var doc = document.implementation.createDocument(null, 'dummy', null);
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
44 /**
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
45 * @private
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
46 */
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
47 var parser = new DOMParser();
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
48 /**
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
49 * @private
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
50 */
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
51 var serializer = new XMLSerializer();
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
52 /**
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
53 * @function Transforms a XML string to a DOM object.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
54 * @param {String} aString XML string.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
55 * @return {Object} Domified XML.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
56 */
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
57 var parse = function(aString) {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
58 var el = parser.parseFromString(aString, 'text/xml').documentElement;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
59 if (el.tagName === 'parsererror')
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
60 ;//do something
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
61 return el;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
62 };
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
63 /**
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
64 * @function Transforms a DOM object to a XML string.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
65 * @param {Object} aString DOM object.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
66 * @return {String} Stringified DOM.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
67 */
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
68 var serialize = function(aElement) {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
69 var string = null;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
70 try {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
71 string = serializer.serializeToString(aElement);
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
72 }
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
73 catch (e) {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
74 //TODO: error
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
75 }
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
76 finally {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
77 return string;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
78 };
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
79 };
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
80
29
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
81
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
82 /**
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
83 * @constructor Creates a new Stanza object.
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
84 * @param {String|Object} [aStanza] The XML or DOM content of the stanza
108
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
85 */
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
86 var Stanza = function(aStanza) {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
87 this.createEl(aStanza);
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
88 };
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
89 /**
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
90 * @constructor Creates a new Message stanza object.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
91 * @param {String|Object} [aStanza] The XML or DOM content of the stanza
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
92 */
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
93 var Message = function(aStanza) {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
94 if ((typeof aStanza === 'object') && (!(aStanza instanceof Element)))
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
95 aStanza.name = 'message';
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
96 this.createEl(aStanza);
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
97 };
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
98 Message.prototype = Stanza.prototype;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
99 /**
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
100 * @constructor Creates a new IQ stanza object.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
101 * @param {String|Object} [aStanza] The XML or DOM content of the stanza
29
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
102 */
108
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
103 var IQ = function(aStanza) {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
104 if ((typeof aStanza === 'object') && (!(aStanza instanceof Element)))
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
105 aStanza.name = 'iq';
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
106 this.createEl(aStanza);
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
107 };
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
108 IQ.prototype = Stanza.prototype;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
109 /**
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
110 * @constructor Creates a new Presence stanza object.
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
111 * @param {String|Object} [aStanza] The XML or DOM content of the stanza
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
112 */
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
113 var Presence = function(aStanza) {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
114 if ((typeof aStanza === 'object') && (!(aStanza instanceof Element)))
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
115 aStanza.name = 'presence';
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
116 this.createEl(aStanza);
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
117 };
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
118 Presence.prototype = Stanza.prototype;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
119 Stanza.prototype.createEl = function(aStanza) {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
120 if (typeof aStanza === 'string') {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
121 this.el = parse(aStanza);
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
122 }
106
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 29
diff changeset
123 else if (aStanza instanceof Element)
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 29
diff changeset
124 this.el = aStanza;
108
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
125 else if (typeof aStanza === 'object') {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
126 var el = doc.createElement(aStanza.name);
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
127 this.el = el;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
128 delete aStanza.name;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
129 for (var i in aStanza) {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
130 this[i] = aStanza[i];
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
131 }
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
132 }
106
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 29
diff changeset
133 else
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 29
diff changeset
134 this.el = null;//TODO error
29
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
135 };
108
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
136 Stanza.prototype.toString = function() {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
137 return serialize(this.el);
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
138 };
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
139 Stanza.prototype.reply = function(aProps) {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
140 var props = aProps || {};
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
141
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
142 props.name = this.name;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
143 var reply = new Stanza(props);
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
144
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
145 if (this.from)
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
146 reply.to = this.from;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
147
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
148
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
149 if (reply.name !== 'iq')
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
150 return reply;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
151
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
152 if (this.id)
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
153 reply.id = this.id;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
154
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
155 reply.type = 'result';
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
156
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
157 return reply;
107
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
158 };
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
159
108
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
160 //from attribute
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
161 Object.defineProperty(Stanza.prototype, "from", {
107
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
162 get : function(){
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
163 return this.el.getAttribute('from');
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
164 },
108
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
165 set : function(aString) {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
166 this.el.setAttribute('from', aString);
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
167 },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
168 enumerable : true,
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
169 configurable : true
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
170 });
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
171 //stanza tag name
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
172 Object.defineProperty(Stanza.prototype, "name", {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
173 get : function(){
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
174 return this.el.localName;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
175 },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
176 //FIXME
107
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
177 // set : function(newValue){ bValue = newValue; },
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
178 enumerable : true,
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
179 configurable : true
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
180 });
108
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
181 //id attribute
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
182 Object.defineProperty(Stanza.prototype, "id", {
107
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
183 get : function(){
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
184 return this.el.getAttribute('id');
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
185 },
108
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
186 set : function(aString) {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
187 this.el.setAttribute('id', aString);
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
188 },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
189 enumerable : true,
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
190 configurable : true
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
191 });
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
192 //to attribute
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
193 Object.defineProperty(Stanza.prototype, "to", {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
194 get : function(){
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
195 return this.el.getAttribute('to');
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
196 },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
197 set : function(aString) {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
198 this.el.setAttribute('to', aString);
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
199 },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
200 enumerable : true,
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
201 configurable : true
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
202 });
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
203 //type attribute
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
204 Object.defineProperty(Stanza.prototype, "type", {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
205 get : function(){
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
206 return this.el.getAttribute('type');
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
207 },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
208 set : function(aString) {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
209 this.el.setAttribute('type', aString);
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
210 },
107
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
211 enumerable : true,
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
212 configurable : true
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
213 });
108
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
214 //body
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
215 Object.defineProperty(Stanza.prototype, "body", {
107
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
216 get : function(){
108
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
217 var bodyEl = this.el.querySelector('body').textContent;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
218 if (!bodyEl)
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
219 return null;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
220 else
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
221 return bodyEl.textContent;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
222 },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
223 set : function(aString) {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
224 var bodyEl = this.el.querySelector('body');
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
225 if (!bodyEl) {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
226 bodyEl = doc.createElement('body');
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
227 bodyEl = this.el.appendChild(bodyEl);
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
228 }
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
229 bodyEl.textContent = aString;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
230 },
107
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
231 enumerable : true,
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
232 configurable : true
108
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
233 });
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
234 //subject
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
235 Object.defineProperty(Stanza.prototype, "subject", {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
236 get : function(){
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
237 var subjectEl = this.el.querySelector('subject').textContent;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
238 if (!subjectEl)
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
239 return null;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
240 else
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
241 return subjectEl.textContent;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
242 },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
243 set : function(aString) {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
244 var subjectEl = this.el.querySelector('subject');
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
245 if (!subjectEl) {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
246 subjectEl = doc.createElement('subject');
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
247 subjectEl = this.el.appendChild(subjectEl);
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
248 }
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
249 subjectEl.textContent = aString;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
250 },
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
251 enumerable : true,
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
252 configurable : true
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
253 });
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
254 Stanza.prototype.replyWithSubscribed = function(aProps) {
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
255 var reply = this.reply(aProps);
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
256 reply.type = 'subscribed';
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
257
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
258 return reply;
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
259 };
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
260
5cb4733c5189 many api changes
Sonny Piers <sonny@fastmail.net>
parents: 107
diff changeset
261 })();