Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-19-2011, 12:18 PM   PM User | #1
danskkr
New to the CF scene

 
Join Date: May 2011
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
danskkr is an unknown quantity at this point
Javascript RSS feeder

I've tried asking this elsewhere but without much success. I'm a html/css developer with little programming skills who has been saddled with making a javascript rss feed script work. I feel that that the solution is probably pretty simple for a javascript guru but it eludes me.

Ok, so I've got an html web page with a list of RSS items which are generated by a seperate javascript file called gfeedfetcher. Gfeedfetcher creates an array with each RSS item's title, date and description and wraps each one in a <li> </li>. All well and good. The problem is I need to move the description to different DIV (div id="itempage"> on the page, outside of the gfeedfetcher <ul>. So when the user clicks on an itemtitle, it takes them to div#itempage, where hopefully, the description for that item has been dynamically added with javascript..

As I see it, I thought I could use the [i] variable generated on each pass through the array as an ID for each item and then match the itemtitle and itemdescriptions with matching IDs somehow. But even just writing this out I'm starting to think I'm going to need some kind of global array or database (its an iphone webapp, so I could make use of html5 client side storage) which can then be called from a jquery click event on the HTML page.

But I'm sure there must be a way without having to resort to databases...

Code:
gfeedfetcher.prototype._displayresult=function(feeds){
	var rssoutput=(this.itemcontainer=="<li>")? "<ul class='edgetoedge'>\n" : ""
	gfeedfetcher._sortarray(feeds, this.sortstring)
	for (var i=0; i<feeds.length; i++){
		//var itemtitle="<a rel=\"nofollow\" href=\"" + feeds[i].link + "\" target=\"" + this.linktarget + "\" class=\"titlefield\">" + feeds[i].title + "</a>"
			var itemtitle="<a href=#itempage>" + i + feeds[i].title + "</a>"
			var inputid = i;
			var itemlabel=/label/i.test(this.showoptions)? '<span class="labelfield">'+this.feeds[i].ddlabel+'</span>' : " "
			var itemdate=gfeedfetcher._formatdate(feeds[i].publishedDate, this.showoptions)
		
	for (var j= 0; j<feeds.length; j++) {		
		if(inputid == j)
		{
		var itemdescription=/description/i.test(this.showoptions)? "<br />"+ j +feeds[i].content : /snippet/i.test(this.showoptions)? "<br />" +feeds[i].contentSnippet  : ""	
		//alert(itemdescription)
		}
	}	
	rssoutput+=this.itemcontainer + itemtitle + " " + itemlabel + " " + itemdate + "\n" + this.itemcontainer.replace("<", "</") + "\n\n"
	}
	rssoutput+=(this.itemcontainer=="<li>")? "</ul>" : ""	
	this.feedcontainer.innerHTML=rssoutput
	document.getElementById(itembox).innerHTML=itemdescription

}

Apologies for the longwinded explanation....!
danskkr is offline   Reply With Quote
Old 05-19-2011, 05:18 PM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
i would simply memorize the incoming object to a global, and build a unique ID for each item when it arrives. you can then pass that id to an HTML event handler that paints the description into the "view" div.

without seeing the whole code i can't give you any snips, but it's a simple concept.

it would be easier to build the html using dom methods instead of strings: the advantage being that you don't need globals to code events; you can simply tell it to innerHTML the right variable on-demand, rather than pass a key to a global function...
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Users who have thanked rnd me for this post:
danskkr (05-20-2011)
Old 05-20-2011, 10:04 AM   PM User | #3
danskkr
New to the CF scene

 
Join Date: May 2011
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
danskkr is an unknown quantity at this point
Nice one, thanks.

I thought it seems simple but i never seem to get anywhere. I guess part of it is that I was trying to call a click event from a different page and link it to an array on the js file.

I did think there might be a way of building into the function above, if I could somehow incorporate this

Code:
document.getElementById(itembox).innerHTML=itemdescription
into this as a click event

Code:
var itemtitle="<a href=#itempage>" + i + feeds[i].title + "</a>"
Do you have any nice links you point me to to show me some of these DOM methods?
danskkr is offline   Reply With Quote
Reply

Bookmarks

Tags
array, gfeedfetcher, javascript, rss

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:22 AM.


Advertisement
Log in to turn off these ads.