annotate atom.js @ 15:5149a856d9dd default tip

Fix hybrid mode.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 03 Nov 2011 17:28:49 -0700
parents 03be0717d3f8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 'use strict';
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2
14
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
3 if (typeof window === 'undefined') {
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
4 var Element = require('ltx').Element;
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
5 var JID = require('./jid');
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
6 var ns = require('./ns');
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
7 var config = require('./configuration');
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
8
8
461a24a5a788 Silent errors when testing if we are server- or client-side.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
9 var document = {};
461a24a5a788 Silent errors when testing if we are server- or client-side.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
10
461a24a5a788 Silent errors when testing if we are server- or client-side.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
11 document.createElementNS = function(ns, name) {
461a24a5a788 Silent errors when testing if we are server- or client-side.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
12 return new Element(name, {xmlns: ns});
461a24a5a788 Silent errors when testing if we are server- or client-side.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
13 };
461a24a5a788 Silent errors when testing if we are server- or client-side.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
14
461a24a5a788 Silent errors when testing if we are server- or client-side.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
15 document.createTextNode = function(text) {
461a24a5a788 Silent errors when testing if we are server- or client-side.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
16 return text;
461a24a5a788 Silent errors when testing if we are server- or client-side.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
17 };
461a24a5a788 Silent errors when testing if we are server- or client-side.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7
diff changeset
18
14
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
19 Element.prototype.getAttributeNS = function(ns, name) {
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
20 // TODO: use the namespace.
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
21 return this.attrs[name];
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
22 };
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
23
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
24 Element.prototype.setAttributeNS = function(ns, name, value) {
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
25 // TODO: use the namespace.
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
26 this.attrs[name] = value;
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
27 };
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
28
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
29 Element.prototype.cloneNode = function(depth) {
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
30 // XXX
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
31 return this;
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
32 };
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
33
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
34 Element.prototype.appendChild = function(child) {
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
35 if (typeof child === 'string')
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
36 this.t(child);
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
37 else
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
38 this.cnode(child);
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
39 };
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
40
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
41 Element.prototype.getElementsByTagNameNS = function(ns, name) {
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
42 return this.getChildren(name, ns);
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
43 };
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
44
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
45 Element.prototype.__defineGetter__('textContent', function() {
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
46 return this.getText();
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
47 });
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
48
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
49 Element.prototype.__defineGetter__('firstChild', function() {
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
50 return this.children[0];
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
51 });
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
52
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
53 Element.prototype.__defineGetter__('childNodes', function() {
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
54 return this.children;
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
55 });
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
56 }
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
57
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
58 var atomParser = function(item) {
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 var toDate = function(atom) {
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
60 var d = new Date;
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
61
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 if (!atom)
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
63 return d;
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
65 try {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
66 var last = atom.getElementsByTagNameNS(ns.atom, 'updated')[0].textContent;
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
67 } catch (e) {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
68 try {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
69 var last = atom.getElementsByTagNameNS(ns.atom, 'published')[0].textContent;
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
70 } catch (e) {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
71 return d;
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
72 }
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 }
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 // var d = new Date(last); // FIXME: don't work in obsolete browsers
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76 d.set8601(last);
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78 return d;
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 };
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
81 var toHTML = function(item, date) {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
82 var atom = item.payload;
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
83
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 var article = document.createElementNS(ns.xhtml, 'article');
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85
14
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
86 article.setAttributeNS(ns.e, 'id', item.id);
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87 var d8601 = date.to8601();
5
4d7a67349089 Finish the changing of name to Eldonilo.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 2
diff changeset
88 article.setAttributeNS(ns.e, 'date', d8601);
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 var aside = document.createElementNS(ns.xhtml, 'aside');
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91 article.appendChild(aside);
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
93 try {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
94 var atomTitle = atom.getElementsByTagNameNS(ns.atom, 'title')[0].textContent;
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95 var title = document.createElementNS(ns.xhtml, 'h2');
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96 title.appendChild(document.createTextNode(atomTitle));
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97 article.appendChild(title);
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
98 } catch (e) {
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99 }
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101 var footer = document.createElementNS(ns.xhtml, 'footer');
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
102
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
103 try {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
104 var atomAuthor = atom.getElementsByTagNameNS(ns.atom, 'author')[0];
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
105 try {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
106 var atomName = atomAuthor.getElementsByTagNameNS(ns.atom, 'name')[0].textContent;
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
107 } catch (e) {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
108 }
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
109
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
110 var cite = document.createElementNS(ns.xhtml, 'cite');
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
111 try {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
112 var atomURI = atomAuthor.getElementsByTagNameNS(ns.atom, 'uri')[0].textContent;
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
113 var a = document.createElementNS(ns.xhtml, 'a');
14
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
114 a.setAttributeNS(null, 'href', atomURI);
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
115 var atomJID = new JID;
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
116 atomJID.uri = atomURI;
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
117
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
118 a.appendChild(document.createTextNode(atomName? atomName: atomJID.bare));
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
119 cite.appendChild(a);
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
120
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
121 var img = document.createElementNS(ns.xhtml, 'img');
14
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
122 img.setAttributeNS(null, 'src', config.avatarRoot + atomJID.bare);
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
123 aside.appendChild(img);
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
124 } catch (e) {
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
125 cite.appendChild(document.createTextNode(atomName));
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
126 }
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
127
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
128 footer.appendChild(document.createTextNode('By '));
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
129 footer.appendChild(cite);
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
130
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
131 try {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
132 var atomEmail = atomAuthor.getElementsByTagNameNS(ns.atom, 'email')[0].textContent;
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
133 footer.appendChild(document.createTextNode(' ('));
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
134 var a = document.createElementNS(ns.xhtml, 'a');
14
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
135 a.setAttributeNS(null, 'href', 'mailto:' + atomEmail);
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
136 a.appendChild(document.createTextNode('email'));
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
137 footer.appendChild(a);
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
138 footer.appendChild(document.createTextNode(')'));
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
139 } catch (e) {
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
140 }
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
141
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
142 article.appendChild(footer);
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
143 } catch (e) {
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
144 }
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
145
14
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
146 var time = document.createElementNS(ns.xhtml, 'time');
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
147 time.setAttributeNS(null, 'datetime', d8601);
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
148 time.appendChild(document.createTextNode(date.getRelative()));
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
149 footer.appendChild(document.createTextNode(', '));
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
150 footer.appendChild(time);
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
151
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
152 try {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
153 var atomSummary = atomAuthor.getElementsByTagNameNS(ns.atom, 'summary')[0].textContent;
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
154 var p = document.createElementNS(ns.xhtml, 'p');
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
155 p.appendChild(document.createTextNode(atomSummary));
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
156 article.appendChild(p);
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
157 } catch (e) {
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
158 }
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
159
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
160 try {
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
161 var atomContent = atom.getElementsByTagNameNS(ns.atom, 'content')[0];
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
162 var contentType = atomContent.getAttributeNS(null, 'type');
7
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
163 if (/^text$/.test(contentType)) {
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
164 var p = document.createElementNS(ns.xhtml, 'p');
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
165 p.appendChild(document.createTextNode(atomContent.textContent));
7
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
166 article.appendChild(p);
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
167 } else if (/^html$/.test(contentType)) {
14
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
168 if (!article.insertAdjacentHTML)
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
169 article.appendChild(document.createTextNode('Inline HTML inclusion not yet supported server-side.'));
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
170 else
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
171 article.insertAdjacentHTML('beforeend', atomContent.textContent); // FIXME: could be not-well-formed.
7
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
172 } else if (/^xhtml$/.test(contentType)) {
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
173 var div = atomContent.firstChild;
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
174 var children = div.childNodes;
14
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
175 for (var i=0; i<children.length; i++) {
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
176 var child = children[i];
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
177 if (typeof child === 'string')
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
178 article.appendChild(child);
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
179 else
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
180 article.appendChild(child.cloneNode(true));
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
181 }
7
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
182 } else {
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
183 var contentSrc = atomContent.getAttributeNS(null, 'src');
7
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
184 if (contentSrc) {
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
185 if (/^image\//.test(contentType)) {
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
186 var img = document.createElementNS(ns.xhtml, 'img');
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
187 img.setAttributeNS(null, 'src', contentSrc);
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
188 article.appendChild(img);
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
189 } else if (/^audio\//.test(contentType)) {
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
190 var audio = document.createElementNS(ns.xhtml, 'audio');
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
191 audio.setAttributeNS(null, 'src', contentSrc);
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
192 audio.setAttributeNS(null, 'controls', '');
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
193 article.appendChild(audio);
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
194 } else if (/^video\//.test(contentType)) {
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
195 var video = document.createElementNS(ns.xhtml, 'video');
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
196 video.setAttributeNS(null, 'src', contentSrc);
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
197 video.setAttributeNS(null, 'controls', '');
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
198 article.appendChild(video);
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
199 } else {
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
200 var a = document.createElementNS(ns.xhtml, 'a');
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
201 a.setAttributeNS(null, 'href', contentSrc);
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
202 article.appendChild(a);
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
203 }
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
204 }
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
205 }
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
206 } catch (e) {
7
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
207 }
7ab6b48122af Add support for content in Atom and improve published display.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 5
diff changeset
208
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
209 var atomLinks = atom.getElementsByTagNameNS(ns.atom, 'link');
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
210 for (var i in atomLinks) {
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
211 var atomLink = atomLinks[i];
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
212
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
213 if (atomLink.getAttributeNS(null, 'rel') !== 'replies')
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
214 continue;
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
215
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
216 if (atomLink.getAttributeNS(null, 'title') !== 'comments')
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
217 continue;
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
218
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
219 var href = new JID;
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
220 href.uri = atomLink.getAttributeNS(null, 'href');
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
221
14
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
222 var a = document.createElementNS(ns.xhtml, 'a');
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
223 a.setAttributeNS(null, 'href', '?jid=' + href.bare + ';node=' + href.query.node);
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
224 a.appendChild(document.createTextNode('Comments'));
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
225 article.appendChild(a);
0
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
226 }
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
227
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
228 return article;
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
229 };
f62b5c395a48 Initial commit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
230
13
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
231 this.xml = item.payload;
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
232 this.date = toDate(item.payload);
161d4ea1c3f8 Migration of the client-side to XMPP.js instead of Strophe.js.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 10
diff changeset
233 this.html = toHTML(item, this.date);
14
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
234 };
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
235
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
236 if (typeof parsers !== 'undefined')
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
237 parsers[ns.atom] = atomParser;
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
238 else if (typeof module !== 'undefined')
03be0717d3f8 Use the same code for client- and server-side Atom parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 13
diff changeset
239 module.exports = atomParser;