Created
June 11, 2013 19:24
-
-
Save adesignl/5759830 to your computer and use it in GitHub Desktop.
RSS Feed Gist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// RSS Feed Reader | |
$("#feed").rss( "http://insights53.web13.hubspot.com/CMS/UI/Modules/BizBlogger/rss.aspx?tabid=1454980&moduleid=3165550&maxcount=25&u=107275&t=5b81a12cee49e9f3c3580fe7d23f0de2", { | |
limit: 3, | |
ssl: false, | |
layoutTemplate: '<div class="feed-container">{entries}</div>', | |
entryTemplate: '<div class="entry"><b><a href="{url}">{title}</a></b><p>{shortBodyPlain}</p></div>' | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(e){var d=function(a,b,c,f){this.target=a;this.url=b;this.html=[];this.effectQueue=[];this.callback=f;this.options=jQuery.extend({ssl:!1,limit:null,key:null,layoutTemplate:"<ul>{entries}</ul>",entryTemplate:'<li><a href="{url}">[{author}@{date}] {title}</a><br/>{shortBodyPlain}</li>',tokens:{},outputMode:"json",effect:"show"},c||{})};d.htmlTags="doctype html head title base link meta style script noscript body article nav aside section header footer h1-h6 hgroup address p hr pre blockquote ol ul li dl dt dd figure figcaption div table caption thead tbody tfoot tr th td col colgroup form fieldset legend label input button select datalist optgroup option textarea keygen output progress meter details summary command menu del ins img iframe embed object param video audio source canvas track map area a em strong i b u s small abbr q cite dfn sub sup time code kbd samp var mark bdi bdo ruby rt rp span br wbr".split(" "); | |
d.prototype.load=function(a){var b="http"+(this.options.ssl?"s":"")+"://ajax.googleapis.com/ajax/services/feed/load?v=1.0&output="+this.options.outputMode+"&callback=?&q="+encodeURIComponent(this.url);null!=this.options.limit&&(b+="&num="+this.options.limit);null!=this.options.key&&(b+="&key="+this.options.key);e.getJSON(b,a)};d.prototype.render=function(){var a=this;this.load(function(b){a.entries=b.responseData.feed.entries;b=a.generateHTMLForEntries();a.target.append(b.layout);0!==b.entries.length&& | |
a.appendEntriesAndApplyEffects(b.layout,b.entries);0<a.effectQueue.length?a.executeEffectQueue(a.callback):e.isFunction(a.callback)&&a.callback.call(a)})};d.prototype.appendEntriesAndApplyEffects=function(a,b){var c=this;b.forEach(function(b){b=c.wrapContent(b);"show"===c.options.effect?a.append(b):(b.css({display:"none"}),a.append(b),c.applyEffect(b,c.options.effect))})};d.prototype.generateHTMLForEntries=function(){var a=this,b={entries:[],layout:null};jQuery(this.entries).each(function(){if(a.isRelevant(this)){var c= | |
a.evaluateStringForEntry(a.options.entryTemplate,this);b.entries.push(c)}});b.layout=this.options.entryTemplate?this.wrapContent(this.options.layoutTemplate.replace("{entries}","")):this.wrapContent(b.entries.join("\n"));return b};d.prototype.wrapContent=function(a){return 0!==e.trim(a).indexOf("<")?e("<div>"+a+"</div>"):e(a)};d.prototype.applyEffect=function(a,b,c){switch(b){case "slide":a.slideDown("slow",c);break;case "slideFast":a.slideDown(c);break;case "slideSynced":this.effectQueue.push({element:a, | |
effect:"slide"});break;case "slideFastSynced":this.effectQueue.push({element:a,effect:"slideFast"})}};d.prototype.executeEffectQueue=function(a){var b=this;this.effectQueue.reverse();var c=function(){var d=b.effectQueue.pop();d?b.applyEffect(d.element,d.effect,c):a&&a()};c()};d.prototype.evaluateStringForEntry=function(a,b){var c=a,d=this;jQuery(a.match(/(\{.*?\})/g)).each(function(){var a=this.toString();c=c.replace(a,d.getValueForToken(a,b))});return c};d.prototype.isRelevant=function(a){var b= | |
this.getTokenMap(a);return this.options.filter?this.options.filterLimit&&this.options.filterLimit==this.html.length?!1:this.options.filter(a,b):!0};d.prototype.getTokenMap=function(a){return jQuery.extend({url:a.link,author:a.author,date:a.publishedDate,title:a.title,body:a.content,shortBody:a.contentSnippet,bodyPlain:function(a){a=a.content.replace(/<script[\\r\\\s\S]*<\/script>/mgi,"").replace(/<\/?[^>]+>/gi,"");for(var c=0;c<d.htmlTags.length;c++)a=a.replace(RegExp("<"+d.htmlTags[c],"gi"),""); | |
return a}(a),shortBodyPlain:a.contentSnippet.replace(/<\/?[^>]+>/gi,""),index:jQuery.inArray(a,this.entries),totalEntries:this.entries.length,teaserImage:function(a){try{return a.content.match(/(<img.*?>)/gi)[0]}catch(c){return""}}(a),teaserImageUrl:function(a){try{return a.content.match(/(<img.*?>)/gi)[0].match(/src="(.*?)"/)[1]}catch(c){return""}}(a)},this.options.tokens)};d.prototype.getValueForToken=function(a,b){var c=this.getTokenMap(b),d=a.replace(/[\{\}]/g,""),d=c[d];if("undefined"!=typeof d)return"function"== | |
typeof d?d(b,c):d;throw Error("Unknown token: "+a);};e.fn.rss=function(a,b,c){(new d(this,a,b,c)).render()}})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment