-
Notifications
You must be signed in to change notification settings - Fork 0
/
yrss.min.js
4 lines (3 loc) · 2.94 KB
/
yrss.min.js
1
2
3
4
/* YRSS 1.1.5 */
/* Copyright (c) 2018 Mark Hillard - MIT License */
!function(e){"use strict";e.fn.yrss=function(r,a,i){return a=e.extend({ssl:!1,limit:10,reverse:!1,cache:!0,maxage:3600,showerror:!0,errormsg:"",tags:!1,date:!0,dateformat:"default",titletag:"h4",content:!0,image:!1,snippet:!0,snippetlimit:120,linktarget:"_self",logging:!1},a),this.each(function(n,o){var s="";if(a.ssl&&(s="s"),e(o).hasClass("rss-feed")||e(o).addClass("rss-feed"),!r)return!1;var l="http"+s+"://query.yahooapis.com/v1/public/yql?q="+encodeURIComponent('select * from feed where url="'+r+'"');a.limit&&(l+=" limit "+a.limit),a.reverse&&(l+=" | reverse()"),a.cache&&(l+="&_maxage="+a.maxage),l+="&format=json",e.getJSON(l,function(r,n,s){if("success"===n)t(o,r,a),e.isFunction(i)&&i.call(this,e(o));else if("error"===n||"parsererror"===n){if(!a.showerror)return!1;var l;l=""!==a.errormsg?a.errormsg:s,e(o).html('<div class="rss-error"><p>'+l+"</p></div>")}})})};var t=function(t,r,a){var i=r.query.results.item;if(e.isArray(i)||(i=[i]),a.logging&&(console.log("Object Data:"),console.log(r),console.log("Entry Array:"),console.log(i)),!i)return!1;var n,o="";e.each(i,function(t){var r,n,s,l=i[t];if(l.category){if(e.isArray(l.category))r=Object.keys(l.category).map(function(e){return""!==l.category[e].domain?l.category[e].domain+":"+l.category[e].content:l.category[e].content});else if("object"===e.type(l.category)){var c=l.category.domain,g=l.category.content;r=""!==l.category.domain?c+":"+g:g}else r=l.category;r=r.toString().toLowerCase().replace(/ /g,"-").replace(/,/g," ")}if(l.pubDate){var d=new Date(l.pubDate);if("default"===a.dateformat)n=(d.getMonth()+1).toString()+"/"+d.getDate().toString()+"/"+d.getFullYear();else if("spellmonth"===a.dateformat){n=["January","February","March","April","May","June","July","August","September","October","November","December"][d.getMonth()]+" "+d.getDate().toString()+", "+d.getFullYear()}else"localedate"===a.dateformat?n=d.toLocaleDateString():"localedatetime"===a.dateformat&&(n=d.toLocaleDateString()+" "+d.toLocaleTimeString())}(o+='<div class="entry-wrapper"',a.tags&&l.category&&(o+='data-tag="'+r+'"'),o+='><div class="entry-title"><'+a.titletag+'><a href="'+l.link+'">'+l.title+"</a></"+a.titletag+"></div>",a.date&&n&&(o+='<div class="entry-date">'+n+"</div>"),a.content)&&(s=l.description?e.trim(l.description):e.trim(l.encoded),o+='<div class="entry-content">'+s+"</div>");o+="</div>"}),n=e(o),a.content&&e.each(n,function(){if(a.image){var t=e(this).find("img").first();0!==t.length?(e(this).prepend('<div class="entry-image">'),e(this).find(".entry-image").append(t).nextAll().wrapAll('<div class="entry-text"></div>')):e(this).children().wrapAll('<div class="entry-text"></div>')}else e(this).find("img").remove();if(a.snippet){var r=e(this).find(".entry-content"),i=e(r).text().length;r.text(function(e,t){return 0===i?"":0!==i&&i<=a.snippetlimit?t:t.substring(0,a.snippetlimit)+" ..."})}}),e(t).append(n),e("a",t).attr("target",a.linktarget)}}(jQuery);