now twitter handles linking better, and replaces endlines with <br> tags

This commit is contained in:
B Mathis 2009-11-06 11:04:12 -06:00
parent e062eaa7a4
commit d2a23f60e9
3 changed files with 19 additions and 20 deletions

View File

@ -10,6 +10,7 @@ var filter_mentions = true;
var tweet_count = 5; var tweet_count = 5;
var tweet_tag = 'p'; var tweet_tag = 'p';
var twitter_div = 'twitter_status'; var twitter_div = 'twitter_status';
var tweet_cookie = 'the_tweets_' + username;
window.addEvent('domready',function() { window.addEvent('domready',function() {
getTwitterStatus(); getTwitterStatus();
@ -29,7 +30,7 @@ function showTweets(the_tweets, from_cookie){
function getTwitterStatus(){ function getTwitterStatus(){
$(twitter_div).set('html', 'Fetching tweets...'); $(twitter_div).set('html', 'Fetching tweets...');
if(!Cookie.read('the_tweets')) { if(!Cookie.read(tweet_cookie)) {
var myTwitterGitter = new TwitterGitter(username,{ var myTwitterGitter = new TwitterGitter(username,{
count: ((!filter_mentions) ? tweet_count : 15 + tweet_count), count: ((!filter_mentions) ? tweet_count : 15 + tweet_count),
onComplete: function(tweets,user) { onComplete: function(tweets,user) {
@ -37,21 +38,15 @@ function getTwitterStatus(){
tweets.each(function(tweet,i) { tweets.each(function(tweet,i) {
if((tweet.in_reply_to_status_id && !filter_mentions) || !tweet.in_reply_to_status_id){ if((tweet.in_reply_to_status_id && !filter_mentions) || !tweet.in_reply_to_status_id){
if(the_tweets.length == tweet_count) return; if(the_tweets.length == tweet_count) return;
tweet.text = tweet.text.replace(/\n/gi, '<br/>');
the_tweets.push(tweet.text); the_tweets.push(tweet.text);
} }
}); });
Cookie.write('the_tweets',the_tweets.join('^!^!^!^!^'), { duration: 1 }); Cookie.write(tweet_cookie,the_tweets.join('^!^!^!^!^'), { duration: 1 });
showTweets(the_tweets); showTweets(the_tweets);
} }
}).retrieve(); }).retrieve();
} else { } else {
showTweets(Cookie.read('the_tweets'),true); showTweets(Cookie.read(tweet_cookie),true);
} }
} }
//implement string.tweetify();
String.implement({
tweetify: function() {
return this.replace(/(https?:\/\/\S+)/gi,'<a href="$1">$1</a>').replace(/(^|\s)@(\w+)/g,'$1<a href="http://twitter.com/$2">@$2</a>').replace(/(^|\s)#(\w+)/g,'$1<a href="http://search.twitter.com/search?q=%23$2">#$2</a>');
}
});

View File

@ -50,7 +50,7 @@ var TwitterGitter = new Class({
//format //format
linkify: function(text) { linkify: function(text) {
//courtesy of Jeremy Parrish (rrish.org) //courtesy of Jeremy Parrish (rrish.org)
return text.replace(/(https?:\/\/\S+)/gi,'<a href="$1">$1</a>').replace(/(^|\s)@(\w+)/g,'$1<a href="http://twitter.com/$2">@$2</a>').replace(/(^|\s)#(\w+)/g,'$1#<a href="http://search.twitter.com/search?q=%23$2">$2</a>'); return text.replace(/(https?:\/\/\S+)/gi,'<a href="$1">$1</a>').replace(/(^|\s)@(\w+)/g,'$1<a href="http://twitter.com/$2">@$2</a>').replace(/(^|\s)#(\w+)/g,'$1<a href="http://search.twitter.com/search?q=%23$2">#$2</a>');
} }
}); });

View File

@ -1,8 +1,12 @@
#twitter #twitter
font-size: 85% font-size: 80%
+border-radius
background: #f3f3f3
padding: 5px 0
p p
+border-radius margin: 0 15px
padding: 10px 15px padding: 12px 0
margin-bottom: 15px border-bottom: #ddd 1px dotted
background: #eee
line-height: 1.625em line-height: 1.625em
&:last-child
border-bottom: 0