-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjquery.ghost-town.min.js
1 lines (1 loc) · 1.31 KB
/
jquery.ghost-town.min.js
1
(function(e){function t(t,n){this.tag=e(t).empty().data("tag");this.element=t;this.options=e.extend({},defaults,n);this.fetchTagRss()}defaults={feed:"/rss",liClass:"",aClass:"",limit:0,content:function(e){return"<strong>"+e.title+"</strong><br /><small>"+e.pubDate+"</small>"}};t.prototype.displayTagContents=function(t){var n=this,r=n.options.limit,i=n.options.liClass,s=n.options.aClass,o=n.options.content,u=0;t.forEach(function(t){if(!r||u<n.options.limit){e(n.element).append(e('<li class="'+i+'"><a class="'+s+'" href="'+t.url+'">'+o(t)+"</a></li>"))}u++});if(u==0){e(this.element).append(e('<li class="'+i+'">No posts found with tag: <strong>'+this.tag+"</strong></li>"))}};t.prototype.fetchTagRss=function(){var t=[],n=this;e.ajax({url:"/tag/"+this.tag+this.options.feed,type:"GET"}).done(function(e,t,r){var i;i=n.extractPosts(new Array(e));n.displayTagContents(i)}).fail(function(t){e(n.element).append(e('<li class="'+n.options.liClass+'">'+t.statusText+"</li>"))})};t.prototype.extractPosts=function(t){var n=[],r=[];t.forEach(function(t){r=e.merge(r,e(t).find("item"))});for(var i=0;i<r.length;i++){var s=e(r[i]);if(s.find("title").text()){n.push({title:s.find("title").text(),url:s.find("link").text(),pubDate:s.find("pubDate").text()})}}return n};e.fn.ghostTown=function(e){return this.each(function(){new t(this,e)})}})(jQuery)