content/js/feeds.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
----- ----- function format_date(d){ return $.timeago(Date.parse(d)); } function get_json_data(uri, options){ $.getJSON(uri, function(data){ var list = $("<ul></ul>"); for (var i=0; i<options.max; i++){ switch(options.element){ case "#backtype": var item = backtype_entry(data.comments[i]) break; case "#delicious": var item = delicious_entry(data[i]) break; case "#twitter": var item = twitter_entry(data[i]) break; case "#github": var item = github_entry(data.commits[i], options.repo) break; } item.appendTo(list); } list.appendTo(options.element).fadeIn(1000); }); } function backtype_entry(comment){ var c = $("<li></li>").addClass('feed-item'); var dt = $("<span></span>").addClass('feed-item-date').html(format_date(comment.comment.date+" GMT")+":"); var tx = $("<span>» </span>").addClass('feed-item-text').append($('<a></a>').attr('href', comment.comment.url).html(comment.post.title)); c.append(dt); c.append(tx); return c } function twitter_entry(tweet){ var it = $("<li></li>").addClass('feed-item'); var content = tweet.text .replace(/^h3rald:/, '') .replace(/((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?)/g, '<a href="$1">$1</a>') .replace(/@([a-zA-Z1-9_]*)/g, '<a href="http://www.twitter.com/$1">@$1</a>') .replace(/#([a-zA-Z1-9_]*)/g, '<a href="http://www.twitter.com/search?q=%23$1">#$1</a>') var dt = $("<span></span>").addClass('feed-item-date').html(format_date(tweet.created_at)+":"); var tx = $("<span>» </span>").addClass('feed-item-text').html(content); it.append(dt); it.append(tx); return it } function delicious_entry(bookmark){ var it = $("<li></li>").addClass('feed-item'); var content = "<a href='"+bookmark.u+"'>"+bookmark.d+"</a>"; content += "<br />tags: "; var categories = Array(); for (i=0; i<bookmark.t.length; i++) { categories[i] = "<a href='http://delicious.com/h3rald/"+bookmark.t[i]+"'>"+bookmark.t[i]+"</a>"; } content += categories.join(', ').replace(/ $/, ''); var dt = $("<span></span>").addClass('feed-item-date').html(format_date(bookmark.dt)+":"); var tx = $("<span>» </span>").addClass('feed-item-text').html(content); it.append(dt); it.append(tx); return it } function github_entry(commit, repo){ var it = $("<li></li>").addClass('commit-data'); var dt = $("<span></span>").addClass('commit-date').html(format_date(commit.committed_date)+" · "); var link = $("<span></span><br />").addClass('commit-link').append($('<a></a>').attr('href', commit.url).html("View")); var tx = $("<span></span>").addClass('commit-text').html(commit.message .replace(/(closes) #(\d+)/ig, "$1 <a href='http://github.com/h3rald/"+repo+"/issues/#issue/$2'>#$2</a>")+"<br />"); it.append(tx); it.append(dt); it.append(link); return it } // http://api.backtype.com/user/h3rald/comments.json?key=47bf0031e3a18a598b85&html=1 function display_opinions(max){ get_json_data("/data/opinions.json", {max: max, element: '#backtype'}) } // http://twitter.com/status/user_timeline/h3rald.json function display_tweets(max){ get_json_data("/data/tweets.json", {max: max, element: '#twitter'}) } // http://feeds.delicious.com/v2/json/h3rald function display_bookmarks(max){ get_json_data("/data/bookmarks.json", {max: max, element: '#delicious'}) } /* http://github.com/api/v2/json/commits/list/h3rald/concatenative/master http://github.com/api/v2/json/commits/list/h3rald/redbook/master http://github.com/api/v2/json/commits/list/h3rald/glyph/master http://github.com/api/v2/json/commits/list/h3rald/stash/master http://github.com/api/v2/json/commits/list/h3rald/rawline/master http://github.com/api/v2/json/commits/list/h3rald/h3rald/master */ function display_commits(max, repo) { get_json_data("/data/"+repo+".json", {max: max, element: '#github', repo: repo}) } |