annotate stanza.js @ 107:704ce44c1a22

Add several properties to the Lightstring.Stanza object
author Sonny Piers <sonny@fastmail.net>
date Thu, 28 Jun 2012 12:51:04 +0200
parents c06ec02217ee
children 5cb4733c5189
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
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
19
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
20 /**
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
21 * @constructor Creates a new Stanza object.
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
22 * @param {String|Object} [aStanza] The XML or DOM content of the stanza
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
23 * @memberOf Lightstring
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
24 */
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
25 Lightstring.Stanza = function(aStanza) {
106
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 29
diff changeset
26 if (typeof aStanza === 'string')
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 29
diff changeset
27 this.el = Lightstring.parse(aStanza);
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 29
diff changeset
28 else if (aStanza instanceof Element)
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 29
diff changeset
29 this.el = aStanza;
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 29
diff changeset
30 else
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 29
diff changeset
31 this.el = null;//TODO error
29
1e6d2ca2daae Adds a Lightstring.Stanza object and use it.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
32 };
106
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 29
diff changeset
33 Lightstring.Stanza.prototype.toString = function() {
c06ec02217ee many changes
Sonny Piers <sonny@fastmail.net>
parents: 29
diff changeset
34 return Lightstring.serialize(this.el);
107
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
35 };
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
36
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
37 Object.defineProperty(Lightstring.Stanza.prototype, "from", {
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
38 get : function(){
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
39 return this.el.getAttribute('from');
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
40 },
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
41 // set : function(newValue){ bValue = newValue; },
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
42 enumerable : true,
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
43 configurable : true
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
44 });
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
45 Object.defineProperty(Lightstring.Stanza.prototype, "name", {
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
46 get : function(){
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
47 return this.el.localName;
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
48 },
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
49 // set : function(newValue){ bValue = newValue; },
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
50 enumerable : true,
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
51 configurable : true
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
52 });
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
53 Object.defineProperty(Lightstring.Stanza.prototype, "id", {
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
54 get : function(){
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
55 return this.el.getAttribute('id');
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
56 },
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
57 // set : function(newValue){ bValue = newValue; },
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
58 enumerable : true,
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
59 configurable : true
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
60 });
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
61 Object.defineProperty(Lightstring.Stanza.prototype, "to", {
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
62 get : function(){
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
63 return this.el.getAttribute('to');
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
64 },
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
65 // set : function(newValue){ bValue = newValue; },
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
66 enumerable : true,
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
67 configurable : true
704ce44c1a22 Add several properties to the Lightstring.Stanza object
Sonny Piers <sonny@fastmail.net>
parents: 106
diff changeset
68 });