0

I need to make some changes to this news ticker which is based on goldyberg's jquery horizontal newsticker using Google JSAPI:

http://inetwebdesign.com/jQueryTools/tickers/horizontal-news-ticker2/horizontal-news-ticker3.html

I have two questions:

  1. How do you limit the number of words that are being pulled into the div? Right now it is too long and it wraps.

  2. How do you add the date from the rss feed to the string that is displayed?

Here is the code I believe is relevant:

     parse: function(entries) {
        var feedMarkup = '';
        feedMarkup += '<ul>';
        for (var i = 0; i < entries.length; i++) {
            feedMarkup += '<li><a target="_blank"
                    href="'+entries[i].link+'">'+entries[i].title+'</a></li>';  
        }   
        feedMarkup += '</ul>';
        $("#ticker-content").empty().append(feedMarkup).fadeIn(400);

        $('#ticker ul                  
                 li:eq(0)').show();                                                   

        current = $('#ticker ul li:eq(0)').index();
        first = 0;
        last = $('#ticker ul li').length;

Thanks in advance for your help.

Regards, umbre

umbregachoong
  • 349
  • 1
  • 7
  • 21

1 Answers1

1
  1. To limit the words, use entries[i].title
  2. To display the date, use entries[i].publishedDate, add a reference to the Datejs open-source JavaScript date library http://www.datejs.com on your HTML file and modify the provided javascript.

A demo is here: http://www.marlenynunez.com/files/jsapi/horizontal-news-ticker4.html

HTML file:

    <script type="text/javascript" src="js/date.js"></script>
    <script type="text/javascript" src="js/scripts.js"></script>

scripts.js file:

    parse: function(entries) {
        var feedMarkup = '';
        var pubDate;
        var titleText;
        var splitText;
        feedMarkup += '<ul>';
        for (var i = 0; i < entries.length; i++) {
            titleText = entries[i].title;
            splitText = titleText.substring(0,60).split(" ");
            titleText = splitText.slice(0, -1).join(" ") + '...';
            pubDate = Date.parse(String(entries[i].publishedDate)).toString('MMM dd');
            feedMarkup += '<li>'+pubDate+' | <a target="_blank" href="'+entries[i].link+'">'+titleText+'</a></li>'; 
        }   
marlenunez
  • 626
  • 4
  • 9
  • Thanks marlenunez! This is what I was looking for. I just have one more question. I need to integrate this: into js/scripts.js but so far I am not having any luck. Thanks again! – umbregachoong Mar 08 '12 at 19:48
  • Thanks again marlenunez! I used the google closure compiler and everything is cool. Check it out: http://inetwebdesign.com/jQueryTools/tickers/horizontal-news-ticker2/horizontal-news-ticker8.html. Once again thanks! – umbregachoong Mar 08 '12 at 23:44