Skip to content

Instantly share code, notes, and snippets.

@jmoyers
Created March 29, 2011 05:28
Show Gist options
  • Save jmoyers/891854 to your computer and use it in GitHub Desktop.
Save jmoyers/891854 to your computer and use it in GitHub Desktop.
var tweet_li_template = _.template(
"<li><div class='tweet'>{content}</div>" +
"<div class='details'>{time} via {source}</div></li>"
);
$.getJSON("http://twitter.com/statuses/user_timeline/so_co_co.json?count=3&callback=?", function(data){
var fragments = [];
_.each( data, function(tweet){
// Linkify urls, @'s
var status = tweet.text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
return '<a href="'+url+'">'+url+'</a>';
}).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
return reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
});
var time = relative_time(parse_date(tweet.created_at));
var new_li = tweet_li_template({
content: status,
time: time,
source: tweet.source
});
fragments.push( new_li );
});
$('#tweet-list').append( fragments.join('') );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment