/* * FeedEk jQuery RSS/ATOM Feed Plugin v2.0 * http://jquery-plugins.net/FeedEk/FeedEk.html https://github.com/enginkizil/FeedEk * Author : Engin KIZIL http://www.enginkizil.com */ (function ($) { $.fn.FeedEk = function (opt) { var def = $.extend({ FeedUrl: "http://rss.cnn.com/rss/edition.rss", MaxCount: 5, ShowDesc: true, ShowPubDate: true, CharacterLimit: 0, TitleLinkTarget: "_blank", DateFormat: "", DateFormatLang:"en" }, opt); var id = $(this).attr("id"), i, s = "",dt; $("#" + id).empty().append(''); $.ajax({ url: "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=" + def.MaxCount + "&output=json&q=" + encodeURIComponent(def.FeedUrl) + "&hl=en&callback=?", dataType: "json", success: function (data) { $("#" + id).empty(); $.each(data.responseData.feed.entries, function (e, item) { s += '
  • ' + item.title + "
    "; if (def.ShowPubDate){ dt= new Date(item.publishedDate); if ($.trim(def.DateFormat).length > 0) { try { moment.lang(def.DateFormatLang); s += '
    ' + moment(dt).format(def.DateFormat) + "
    "; } catch (e){s += '
    ' + dt.toLocaleDateString() + "
    ";} } else { s += '
    ' + dt.toLocaleDateString() + "
    "; } } if (def.ShowDesc) { if (def.DescCharacterLimit > 0 && item.content.length > def.DescCharacterLimit) { s += '
    ' + item.content.substr(0, def.DescCharacterLimit) + "...
    "; } else { s += '
    ' + item.content + "
    "; } } }); $("#" + id).append('"); } }); }; })(jQuery);