jasonbrooks / centos / centos.org

Forked from centos/centos.org 5 years ago
Clone

Blame assets/js/FeedEk.js

545090
/*
545090
* FeedEk jQuery RSS/ATOM Feed Plugin v3.0 with YQL API
545090
* http://jquery-plugins.net/FeedEk/FeedEk.html  https://github.com/enginkizil/FeedEk
545090
* Author : Engin KIZIL http://www.enginkizil.com   
545090
*/
545090

545090
(function ($) {
545090
    $.fn.FeedEk = function (opt) {
545090
        var def = $.extend({
545090
            MaxCount: 5,
545090
            ShowDesc: true,
545090
            ShowPubDate: true,
545090
            DescCharacterLimit: 0,
545090
            TitleLinkTarget: "_blank",
545090
            DateFormat: "",
545090
            DateFormatLang:"en"
545090
        }, opt);
545090
        
545090
        var id = $(this).attr("id"), i, s = "", dt;
545090
        $("#" + id).empty();
545090
        if (def.FeedUrl == undefined) return;       
545090
        $("#" + id).append('');
545090

545090
        var YQLstr = 'SELECT channel.item FROM feednormalizer WHERE output="rss_2.0" AND url ="' + def.FeedUrl + '" LIMIT ' + def.MaxCount;
545090

545090
        $.ajax({
545090
            url: "https://query.yahooapis.com/v1/public/yql?q=" + encodeURIComponent(YQLstr) + "&format=json&diagnostics=false&callback=?",
545090
            dataType: "json",
545090
            success: function (data) {
545090
                $("#" + id).empty();
545090
                if (!(data.query.results.rss instanceof Array)) {
545090
                    data.query.results.rss = [data.query.results.rss];
545090
                }
545090
                $.each(data.query.results.rss, function (e, itm) {
545090
                    s += '
  • ';
  • 545090
                        
    
    545090
                        if (def.ShowPubDate){
    
    545090
                            dt = new Date(itm.channel.item.pubDate);
    
    545090
                            s += '
    ';
    545090
                            if ($.trim(def.DateFormat).length > 0) {
    
    545090
                                try {
    
    545090
                                    moment.lang(def.DateFormatLang);
    
    545090
                                    s += moment(dt).format(def.DateFormat);
    
    545090
                                }
    
    545090
                                catch (e){s += dt.toLocaleDateString();}                            
    
    545090
                            }
    
    545090
                            else {
    
    545090
                                s += dt.toLocaleDateString();
    
    545090
                            }
    
    545090
                            s += '';
    
    545090
                        }
    
    545090
                        if (def.ShowDesc) {
    
    545090
                            s += '
    ';
    545090
                             if (def.DescCharacterLimit > 0 && itm.channel.item.description.length > def.DescCharacterLimit) {
    
    545090
                                 // Patches upstream FeedEK to correctly
    
    545090
                                 // handle HTML tags embedded in the
    
    545090
                                 // description text. 
    
    545090
                                var d = $(itm.channel.item.description).text();
    
    545090
                                s += d.substring(0, def.DescCharacterLimit) + '...';
    
    545090
                            }
    
    545090
                            else {
    
    545090
                                s += itm.channel.item.description;
    
    545090
                             }
    
    545090
                             s += '';
    
    545090
                        }
    
    545090
                    });
    
    545090
                    $("#" + id).append('
      ' + s + '
    ');
    545090
                }
    
    545090
            });
    
    545090
        };
    
    545090
    })(jQuery);
    
    545090