tags:

views:

278

answers:

1

I've had a look at JFeed's readme and it doesn't mention anyway to get to an RSS item's image:

JFeedItem properties

* item.title
* item.link
* item.description
* item.updated
* item.id

Does anyone know a way to parse these images?

+2  A: 

Short answer "No".

There is no default jFeed support for "image" access for RSS (or "icon"/"logo" access for ATOM).

That said you could always extend the library to support feed images. For example in jrss.js you could add:

var image = jQuery('image', xml).eq(0);

this.image = new Object();
this.image.url = jQuery(image).find('url:first').text();
this.image.title = jQuery(image).find('title:first').text();
this.image.link = jQuery(image).find('link:first').text();

From an RSS feed you would then be able to access:

feed.image.url

But this only facilitates accessing the graphic for the entire feed and not individual items.

To support individual item images you would need to extend jFeed to allow it to support attributes in some way.

For example to support RSS 2.0 enclosures you could fold the attributes into elements, so you would be able to access something like:

item.enclosure.url

In jrss.js you could add something like:

jQuery('item', xml).each( function() {

    var item = new JFeedItem();

    item.title = jQuery(this).find('title').eq(0).text();
    item.link = jQuery(this).find('link').eq(0).text();
    item.description = jQuery(this).find('description').eq(0).text();
    item.updated = jQuery(this).find('pubDate').eq(0).text();
    item.id = jQuery(this).find('guid').eq(0).text();

    item.enclosure = new Object();

    var enc = jQuery(this).find('enclosure');

    item.enclosure.url = jQuery(enc).attr('url');
    item.enclosure.length = jQuery(enc).attr('length');
    item.enclosure.type = jQuery(enc).attr('type');

    feed.items.push(item);
});

I'm tired and making this up as I go along, can you tell? ;)

Mark McLaren
That all makes sense - I've had a crack at it but can't seem to access the item's thumbnail element.RSS snippet:<item> <media:thumbnail width="66" height="49" url="http://url/something.jpg"></media:thumbnail></item>jfeeditem.js:function JFeedItem() {};JFeedItem.prototype = { title: '', link: '', description: '', updated: '', id: '', thumbnailurl: ''};jrss.js:...item.id = jQuery(this).find('guid').eq(0).text(); item.thumbnailurl = jQuery(this).find('media:thumbnail').attr('url');the thumbnail property remains undefined and I can't seem to match it.
David Neale
Okay your problem looks to be namespace related. Try one of the solutions suggested here:http://stackoverflow.com/questions/128580/jquery-find-problem
Mark McLaren
super easy to implement, by the way - I'm sort of used to not diving too deep into plugin customization, so it's nice to see that this one is straight-forward enough to quickly add a few bits and pieces.
matt lohkamp