Skip to content

Instantly share code, notes, and snippets.

@micahwave
Created July 13, 2012 20:47
Show Gist options
  • Save micahwave/3107357 to your computer and use it in GitHub Desktop.
Save micahwave/3107357 to your computer and use it in GitHub Desktop.
Ad Ops
function render_tweet_text( data ) {
if( typeof data.tweets != undefined ) {
jQuery('#sponsor_content').html( format_links( data.tweets[0].text ) );
}
}
function format_links( str ) {
str = ' '+str;
str = str.replace(/((ftp|https?):\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?)/gm,'<a href="$1" target="_blank">$1</a>');
str = str.replace(/([^\w])\@([\w\-]+)/gm,'$1@<a href="http://twitter.com/$2" target="_blank">$2</a>');
str = str.replace(/([^\w])\#([\w\-]+)/gm,'$1<a href="http://twitter.com/search?q=%23$2" target="_blank">#$2</a>');
return str;
}
document.write('<div class=\"widget-sponsored-tweet\"><div class=\"title\">Sponsored Tweet</div><ul><li><a target=\"_blank\" href=\"http://www.twitter.com/bp/\"><img width=\"48\" height=\"48\" src=\"https://si0.twimg.com/profile_images/872897848/BP_Logo_jpg_normal.jpg\" border=\"0\" /></a>\n<span class=\"tweet-author\">@<a target=\"_blank\" href=\"http://www.twitter.com/bp_america/\">BP_America</span></a>\n<div class=\"tweet-content\" id=\"sponsor_content\"></div></li></ul></div>');
document.write('<script src=\"http://olympics.time.com/?feed=tweetstream&username=bp_america&callback=render_tweet_text\"><\/script>');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment