Browse code

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

B Mathis authored on 06/11/2009 at 17:04:12
Showing 3 changed files
... ...
@@ -10,6 +10,7 @@ var filter_mentions = true;
10 10
 var tweet_count = 5;
11 11
 var tweet_tag = 'p';
12 12
 var twitter_div = 'twitter_status';
13
+var tweet_cookie = 'the_tweets_' + username;
13 14
 
14 15
 window.addEvent('domready',function() {
15 16
 	getTwitterStatus();
... ...
@@ -29,7 +30,7 @@ function showTweets(the_tweets, from_cookie){
29 29
 
30 30
 function getTwitterStatus(){
31 31
   $(twitter_div).set('html', 'Fetching tweets...');
32
-  if(!Cookie.read('the_tweets')) {
32
+  if(!Cookie.read(tweet_cookie)) {
33 33
   	var myTwitterGitter = new TwitterGitter(username,{
34 34
   	  count: ((!filter_mentions) ? tweet_count : 15 + tweet_count),
35 35
   		onComplete: function(tweets,user) {
... ...
@@ -37,21 +38,15 @@ function getTwitterStatus(){
37 37
   			tweets.each(function(tweet,i) {
38 38
   			  if((tweet.in_reply_to_status_id && !filter_mentions) || !tweet.in_reply_to_status_id){
39 39
   			    if(the_tweets.length == tweet_count) return;
40
+  			    tweet.text = tweet.text.replace(/\n/gi, '<br/>');
40 41
     			  the_tweets.push(tweet.text);
41 42
   				}
42 43
   			});
43
-  			Cookie.write('the_tweets',the_tweets.join('^!^!^!^!^'), { duration: 1 });
44
+  			Cookie.write(tweet_cookie,the_tweets.join('^!^!^!^!^'), { duration: 1 });
44 45
   			showTweets(the_tweets);
45 46
   		}
46 47
   	}).retrieve();
47 48
 	} else {
48
-	  showTweets(Cookie.read('the_tweets'),true);
49
+	  showTweets(Cookie.read(tweet_cookie),true);
49 50
 	}
50
-}
51
-
52
-//implement string.tweetify();
53
-String.implement({
54
-	tweetify: function() {
55
-		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>');
56
-	}
57
-});
58 51
\ No newline at end of file
52
+}
59 53
\ No newline at end of file
... ...
@@ -50,8 +50,8 @@ var TwitterGitter = new Class({
50 50
 	//format
51 51
 	linkify: function(text) {
52 52
 		//courtesy of Jeremy Parrish (rrish.org)
53
-		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>');
53
+		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>');
54 54
 	}
55 55
 });
56
-
57
-
56
+
57
+
... ...
@@ -1,8 +1,12 @@
1 1
 #twitter
2
-  font-size: 85%
2
+  font-size: 80%
3
+  +border-radius
4
+  background: #f3f3f3
5
+  padding: 5px 0
3 6
   p
4
-    +border-radius
5
-    padding: 10px 15px
6
-    margin-bottom: 15px
7
-    background: #eee
8
-    line-height: 1.625em
9 7
\ No newline at end of file
8
+    margin: 0 15px
9
+    padding: 12px 0
10
+    border-bottom: #ddd 1px dotted
11
+    line-height: 1.625em
12
+    &:last-child
13
+      border-bottom: 0
10 14
\ No newline at end of file