PDA

View Full Version : gAjax RSS Feeds Displayer - display more feed characters



cxcskiing
07-18-2014, 04:34 PM
1) Script Title: gAjax RSS Feeds Displayer v2.0 (hosted)

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex18/gajaxrssdisplayer.htm

Question:

What do I tweak (and where) to make a feed display more characters?

Thank you!

ddadmin
07-23-2014, 12:53 AM
For which field (ie: title or description) do you wish to display more characters? For the description field, you can show everything that's made available to you inside the RSS file by passing in the keyword "description" inside the displayoptions() function when initializing the script:


myrssvar.displayoptions("datetime label description")

For the title field, the number of characters shown is not controlled by the script and can't be altered.

cxcskiing
07-23-2014, 03:19 PM
I have this, for instance:

The Future Is Bright! (Junior Programs)
By Andy Keller – CXC Development Coach Wow! This summer has been flying by with all the camps and programs we have had going on ...

I'd like to extend the description part by one more sentence. I certainly don't need everything.. I remember changing a number (for the description field character count) somewhere in the js script, but I can't recall where..

Here is my script:


<script type="text/javascript">

var socialfeed=new gfeedfetcher("example5", "example5class", "_new")
socialfeed.addFeed("(Sport Science)", "http://cxcacademy.wordpress.com/category/sport-science/feed/atom")
socialfeed.displayoptions("label snippet") //show the specified additional fields
socialfeed.setentrycontainer("div") //Display each entry as a DIV
socialfeed.filterfeed(2, "label") //Show 6 entries, sort by label
socialfeed.onfeedload = function(){
var $ = jQuery, $firsttitle = $(this.feedcontainer).find('.titlefield').eq(0), mw = $(this.feedcontainer).children().innerWidth() - 5, $p, $r;
$.each(this.feeds, function(i, feed){
$p = $(feed.content).find('img').eq(0).css({maxWidth: mw, height: 'auto'});
$r = $p.parent('a').length? $p.parent('a') : $p;
if($r.length){return false;}
});
if($r.length){$firsttitle.before($('<div></div>').append($r));}
};
socialfeed.init() //Always call this last

</script>


I did find a thread back from 2010.. that says:

To change the 200 character limit to something else, inside the .js file, you'd change 200 below to another number:


itemdescription=itemdescription.replace(re, "").substring(0, 200)
if (itemdescription.length==200)
itemdescription+='...'

but I don't have such code lines in my .js file anymore.. I think the .js file was replaced with a new one at some point.

Thank you!

jscheuer1
07-23-2014, 03:52 PM
Sounds like you're only displaying the snippet part instead of the description. Change that (using the second example from the demo page):


var socialfeed=new gfeedfetcher("someid", "someclass", "_new")
socialfeed.addFeed("Slashdot", "http://rss.slashdot.org/Slashdot/slashdot") //Specify "label" plus URL to RSS feed
socialfeed.addFeed("Digg", "http://digg.com/rss/index.xml") //Specify "label" plus URL to RSS feed
socialfeed.displayoptions("label datetime snippet") //show the specified additional fields
socialfeed.setentrycontainer("div") //Display each entry as a DIV
socialfeed.filterfeed(6, "label") //Show 6 entries, sort by label
socialfeed.init() //Always call this last

to the description itself:


var socialfeed=new gfeedfetcher("someid", "someclass", "_new")
socialfeed.addFeed("Slashdot", "http://rss.slashdot.org/Slashdot/slashdot") //Specify "label" plus URL to RSS feed
socialfeed.addFeed("Digg", "http://digg.com/rss/index.xml") //Specify "label" plus URL to RSS feed
socialfeed.displayoptions("label datetime description") //show the specified additional fields
socialfeed.setentrycontainer("div") //Display each entry as a DIV
socialfeed.filterfeed(6, "label") //Show 6 entries, sort by label
socialfeed.init() //Always call this last

vwphillips
07-24-2014, 09:08 AM
untested but changes in red


gfeedfetcher.prototype._displayresult=function(feeds){
var rssoutput=(this.containertag[0]=="li")? "<ul>\n" : ""
gfeedfetcher._sortarray(feeds, this.sortstring)
var itemurl=[], itemtitle=[], itemlabel=[], itemdate=[], itemdescription=[]
for (var i=0; i<feeds.length; i++){
itemurl.push(feeds[i].link)
itemtitle.push('<span class="titlefield"><a href="' + feeds[i].link + '" target="' + this.linktarget + '">' + feeds[i].title + '</a></span>\n')
itemlabel.push(/label/i.test(this.showoptions)? '<span class="labelfield">'+this.feeds[i].ddlabel+'</span>\n' : "")
itemdate.push(gfeedfetcher._formatdate(feeds[i].publishedDate, this.showoptions))
var itemdescriptionsingle=/description/i.test(this.showoptions)? feeds[i].content : /snippet/i.test(this.showoptions)? feeds[i].contentSnippet : ""
itemdescriptionsingle=(itemdescriptionsingle!="")? '<span class="descriptionfield">' + itemdescriptionsingle + '</span>\n' : ""
itemdescription.push(itemdescriptionsingle)
}
// create temp object to store references to rss components, for access dynamically:
var holder={urlfield: itemurl, titlefield: itemtitle, labelfield: itemlabel, datefield: itemdate, descriptionfield: itemdescription}
var regexprules=this.regexprules
for (var i=(this.regexprules && this.regexprules.length>0? this.regexprules.length-1 : -1); i>=0; i--){ // loop thru regexprules array
if (regexprules[i][2]=="titlefield" || regexprules[i][2]=="labelfield" || regexprules[i][2]=="datefield" || regexprules[i][2]=="descriptionfield"){
var targetarray=holder[regexprules[i][2]] // reference array containing said field type (ie: itemdescription if regexprules[i][2]=="descriptionfield")
targetarray=targetarray.join('***delimiter***') // combine array elements before doing search and replace
.replace(regexprules[i][0], regexprules[i][1])
.split('***delimiter***') // revert back to array
holder[regexprules[i][2]]=targetarray
regexprules.splice(i,1) // remove this rule from regexprules
}
}
for (var t,i=0; i<feeds.length; i++){ // loop thru feeds, molding each feed entry based on template
rssoutput+= this.containertag[1] + this.outputtemplate.replace(/({title})|({url})|({label})|({date})|({description})/ig, function(m){
if (m == "{title}")
return holder.titlefield[i]
else if (m == "{url}")
return holder.urlfield[i]
else if (m == "{label}")
return holder.labelfield[i]
else if (m == "{date}")
return holder.datefield[i]
else if (m == "{description}"){
t=holder.descriptionfield[i].slice(0,200);
t+=t.length==200?'....':'';
return t;
}
}) + "</" + this.containertag[0] + ">" + "\n\n"
}
rssoutput+=(this.containertag[0]=="li")? "</ul>" : ""
for (var i=0; i<this.regexprules.length; i++){ // loop thru remaining regexprules array that target the entire feed in general (versus specific field)
rssoutput=rssoutput.replace(this.regexprules[i][0], this.regexprules[i][1])
}
this.feedcontainer.innerHTML=rssoutput
}

cxcskiing
07-25-2014, 06:03 PM
John -

I think we had enough script modifications at this point to make your suggestion above not work (( Changing snippet to description actually breaks things on the page. I've been following your suggestions posted in this thread: http://www.dynamicdrive.com/forums/showthread.php?74483-Display-Image-with-gAjax-RSS-Feeds-Displayer-v2-0

The page I'm trying to make things work on is http://cxcskiing.org/index.html

Thank you!