Skip to content

Instantly share code, notes, and snippets.

@didxga
Forked from assertchris/Request.RSS.js
Created March 5, 2011 17:49
Show Gist options
  • Save didxga/856541 to your computer and use it in GitHub Desktop.
Save didxga/856541 to your computer and use it in GitHub Desktop.
/*
---
license: MIT-style
authors: [Christopher Pitt]
...
*/
(function(){
var template =
'<div class="item">'+
'<div class="title">{title}</div>'+
'<div class="link">{link}</div>'+
'<div class="date">{date}</div>'+
'<div class="description">{description}</div>'+
'</div>';
Request.RSS = new Class({
'Extends': Request,
'initialize': function (container, options) {
this.parent(options);
this.container = document.id(container);
},
'success': function (text, xml) {
var root = xml.getElementsByTagName('channel')[0],
items = root.getElementsByTagName('item');
if (this.container != null) {
this.container.empty();
Array.each(items, function (item) {
var elements = {
'title': item.getElementsByTagName('title')[0],
'link': item.getElementsByTagName('link')[0],
'pubDate': item.getElementsByTagName('pubDate')[0],
'description': item.getElementsByTagName('description')[0]
};
var temp = new Element('div', {
'html': elements.description != null ? elements.description.get('text') : ''
});
this.container.innerHTML += (template || this.options.template).substitute({
'title': elements.title != null ? elements.title.get('text') : '',
'link': elements.link != null ? elements.link.get('text') : '',
'pubDate': elements.pubDate != null ? elements.pubDate.get('text') : '',
'description': temp.get('text')
});
temp.destroy();
Array.each(elements, function (element, key) {
delete elements[key];
});
}.bind(this));
}
this.onSuccess(items, xml);
}
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment