View Full Version : re-initiate gAjax ticker after ajax call

03-14-2008, 05:35 PM
1) Script Title: gAjax RSS Ticker

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

3) Describe problem:

I use this script to provide the user of my site the possibility to add their own RSS feeds to display when they are browsing my site.
The scripts works as expected.
when the user adds and enables a new RSS feed, I use an AJAX call to update the javascript code that produces the ticker to add the newly added RSS url to the code (the URL's are stored in a mysql database and the java code is generated by a PHP script).

when the code is replaced, it keeps showing the original feeds, not the feeds specified in the code that was inserted by the ajax call.
I assume I have to re-initiate the script somehow but cannot find how to do this.
I'm using an ajax call that allows me to execute a javascript command after the call finished inserting the new code, so I probably just need to add a command here.
A workaround is refreshing the entire page but I prefer not to do this if I can do it with ajax.

Can anyone help me or give a hint on how I might be able to solve this?

thanks in advance,


03-14-2008, 09:39 PM
I assume you mean the user is adding to the already shown RSS feeds his/her own feed, instead of replacing the original with the new ones. In general, yes, this should be possible. Firstly, inside gajaxticker.js, add to two instances of the lines below with the code in red:

this.rtimer=setTimeout(function(){scrollerinstance._rotatemessage()}, this.delay)

Again, there are two of them. Then, you're ready to allow the user to dynamically add a feed into the ticker. Here's a quick demo with a button that when clicked on, adds the "Slashdot" feed as part of the ticker's rotation, on demand. Code in red is new:

<script type="text/javascript">

var cssfeed=new gfeedrssticker("example1", "example1class", 1000, "_new")
cssfeed.addFeed("CSS Drive", "http://www.cssdrive.com/index.php/news/rss_2.0/") //Specify "label" plus URL to RSS feed
cssfeed.displayoptions("date") //show the specified additional fields
cssfeed.setentrycontainer("div") //Wrap each entry with a DIV tag
cssfeed.filterfeed(2, "date") //Show 10 entries, sort by date

function adduserFeed(instance, label, url){
instance[label+'count']=(typeof instance[label+'count']=="undefined")? 1 : instance[label+'count']+1
if (instance[label+'count']==1){
if (instance.rtimer)
instance.addFeed(label, url)


<button onClick="adduserFeed(cssfeed, 'Slashdot', 'http://rss.slashdot.org/Slashdot/slashdot')">Add Slashdot</button>

Basically all the new function does is call addFeed() and init() of the original script again, doing some clean up work before hand that could mess things up if not done.