alciregi / centos / centos.org

Forked from centos/centos.org a year ago
Clone

Blame static/assets/js/FeedEk.js

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

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

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

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