Results 1 to 2 of 2

Thread: re-initiate gAjax ticker after ajax call

  1. #1
    Join Date
    Mar 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question re-initiate gAjax ticker after ajax call

    1) Script Title: gAjax RSS Ticker

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...xrssticker.htm

    3) Describe problem:
    Hi,

    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,

    Johan

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    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:

    Code:
    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:

    Code:
    <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
    cssfeed.entries_per_page(1)
    cssfeed.init()
    
    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)
    clearTimeout(instance.rtimer)
    instance.addFeed(label, url)
    instance.init()
    }
    }
    
    </script>
    
    <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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •