tags:

views:

346

answers:

0

I am using Yahoo pipes to create a feed for a website. I cobbled together from examples online a decent rss feed reader, then I started adding bells and whistles to it. I get a visual error when I click the next link to quickly. Also there seems to be a script error that happens on ie8, but I don't use it so I cannot verify. It looks like the code can be "tightened" up a little.

<script type="text/javascript">
    $(document).ready(function() {
        var pipe_url = 'http://pipes.yahoo.com/pipes/pipe.run?_id=312bf74508cda2e458115acdc85685aa&amp;_render=json&amp;_callback=?';
        $.getJSON(pipe_url, function(data) {
            $(data.value.items).each(function(index, item) {
                var item_title = '<h4><a href="' + item.link + '">' + item.title + '</a></h4>';
                var item_date = '<h5>' + item.pubDate + '</h5>';
                var item_desc = '<p class="desc">' + item.description + '</p>';
                var item_link = '<p class="read-more"><a href="' + item.link + '">read more</a></p>';
                var item_html = '<div class="rss-item">' + item_title + item_date + item_desc + item_link + '</div>';
                $('#rssdata div.rss-items').append(item_html);
            });
            $('#rssdata .loading').fadeOut();
            $('#rssdata .rss-items').slideDown();
            $('#rssdata .rss-items .rss-item:gt(0)').hide();
            $('#rssdata .rss-items .rss-item:eq(0)').addClass("current");
            // $(".prev").addClass("noshow");
        });

        $('.next').click(function() {
            nextItem();
        });

        $('.prev').click(function() {
            prevItem();
        });

        // autoplay;
        var autoplay = true;

        $('#rssdata').mouseover(function() {
            autoplay = false;
            $(".feeds").addClass("hilite");
        }).mouseout(function() {
            autoplay = true;
            $(".feeds").removeClass("hilite");
        });

        setInterval(function() {
            if (autoplay) {
                nextItem();
            }
        },
        9000);

        function nextItem() {
            $("#rssdata .rss-items .current").next().slideDown('slow');
            $("#rssdata .rss-items .current").next().addClass("current");
            $("#rssdata .rss-items .current:first").hide();
            $("#rssdata .rss-items .current:first").removeClass('current');
            if (!$("#rssdata .rss-items .current").get(0)) {
                // maybe disable span link?
                $("#rssdata .rss-items .current:eq(0)").removeClass("current");
                $('#rssdata .rss-items .rss-item:eq(0)').addClass("current");
                nextItem();
            }
            return false;
        }

        function prevItem() {
            $("#rssdata .rss-items .current").prev().slideDown('slow');
            $("#rssdata .rss-items .current").prev().addClass("current");
            $("#rssdata .rss-items .current:last").hide();
            $("#rssdata .rss-items .current:last").removeClass('current');
            if (!$('#rssdata .rss-items .current').get(0)) {
                // maybe disable span link?
                $('#rssdata .rss-items .rss-item:eq(0)').addClass("current");
                $("#rssdata .rss-items .current").slideDown('slow');
            }
            return false;
        }
    });


    // end RSS reader code

</script>