comparison atom.js @ 7:7ab6b48122af

Add support for content in Atom and improve published display.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 02 Nov 2011 09:35:46 -0700
parents 4d7a67349089
children 461a24a5a788
comparison
equal deleted inserted replaced
6:29becdd02dea 7:7ab6b48122af
82 var p = document.createElementNS(ns.xhtml, 'p'); 82 var p = document.createElementNS(ns.xhtml, 'p');
83 p.appendChild(document.createTextNode(atomSummary)); 83 p.appendChild(document.createTextNode(atomSummary));
84 article.appendChild(p); 84 article.appendChild(p);
85 } 85 }
86 86
87 var atomContent = atom.getChild('content');
88 if (atomContent) {
89 var contentType = atomContent.getAttribute('type');
90 if (/^text$/.test(contentType)) {
91 var p = document.createElementNS(ns.xhtml, 'p');
92 p.appendChild(document.createTextNode(atomContent.getText()));
93 article.appendChild(p);
94 } else if (/^html$/.test(contentType)) {
95 article.insertAdjacentHTML('beforeend', atomContent.getText()); // FIXME: could be not-well-formed.
96 } else if (/^xhtml$/.test(contentType)) {
97 // TODO: use a better xml2json lib that allow to json2xml
98 /*var div = atomContent.getChild();
99 article.appendChild(div.innerXml());*/
100 } else {
101 var contentSrc = atomContent.getAttribute('src');
102 if (contentSrc) {
103 if (/^image\//.test(contentType)) {
104 var img = document.createElementNS(ns.xhtml, 'img');
105 img.setAttributeNS(null, 'src', contentSrc);
106 article.appendChild(img);
107 } else if (/^audio\//.test(contentType)) {
108 var audio = document.createElementNS(ns.xhtml, 'audio');
109 audio.setAttributeNS(null, 'src', contentSrc);
110 audio.setAttributeNS(null, 'controls', '');
111 article.appendChild(audio);
112 } else if (/^video\//.test(contentType)) {
113 var video = document.createElementNS(ns.xhtml, 'video');
114 video.setAttributeNS(null, 'src', contentSrc);
115 video.setAttributeNS(null, 'controls', '');
116 article.appendChild(video);
117 } else {
118 var a = document.createElementNS(ns.xhtml, 'a');
119 a.setAttributeNS(null, 'href', contentSrc);
120 article.appendChild(a);
121 }
122 }
123 }
124 }
125
87 var atomLinks = atom.getChildren('link'); 126 var atomLinks = atom.getChildren('link');
88 for (var i in atomLinks) { 127 for (var i in atomLinks) {
89 var atomLink = atomLinks[i]; 128 var atomLink = atomLinks[i];
90 129
91 if (atomLink['@rel'] !== 'replies') 130 if (atomLink['@rel'] !== 'replies')