diff options
author | B Mathis <brandon@imathis.com> | 2009-10-30 00:31:02 -0500 |
---|---|---|
committer | B Mathis <brandon@imathis.com> | 2009-10-30 00:31:02 -0500 |
commit | 5c736f5eb03d7b51defe27ac027124557c4c7a3b (patch) | |
tree | f2ad356f733a6b359360422209cba95d8197c817 /source/javascripts/twitter.js | |
parent | 80a70068ed7fda704c769e123c77bb8c78c7d9a3 (diff) | |
download | my_new_personal_website-5c736f5eb03d7b51defe27ac027124557c4c7a3b.tar.xz my_new_personal_website-5c736f5eb03d7b51defe27ac027124557c4c7a3b.zip |
added twitter feed to sidebar, moved to compass-edge gem
Diffstat (limited to 'source/javascripts/twitter.js')
-rw-r--r-- | source/javascripts/twitter.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/source/javascripts/twitter.js b/source/javascripts/twitter.js new file mode 100644 index 00000000..b78b8de1 --- /dev/null +++ b/source/javascripts/twitter.js @@ -0,0 +1,57 @@ +// +// The Octopress Twitter Feed is based on the following work: +// Valerio's javascript framework Mootools: Mootools.net +// David Walsh's Twitter Gitter plugin: http://davidwalsh.name/mootools-twitter-plugin +// Aaron Newton’s JSONP plugin: http://clientcide.com/js +// + +var username = 'imathis'; +var filter_mentions = true; +var tweet_count = 5; +var tweet_tag = 'p'; +var twitter_div = 'twitter_status'; + +window.addEvent('domready',function() { + getTwitterStatus(); +}); + +function showTweets(the_tweets, from_cookie){ + if(from_cookie){ + the_tweets = the_tweets.split('^!^!^!^!^'); + } + $(twitter_div).set('html', ''); + the_tweets.each(function(tweet){ + new Element(tweet_tag,{ + html: tweet + }).inject(twitter_div); + }); +} + +function getTwitterStatus(){ + $(twitter_div).set('html', 'Fetching tweets...'); + if(!Cookie.read('the_tweets')) { + var myTwitterGitter = new TwitterGitter(username,{ + count: ((!filter_mentions) ? tweet_count : 15 + tweet_count), + onComplete: function(tweets,user) { + the_tweets = Array(); + tweets.each(function(tweet,i) { + if((tweet.in_reply_to_status_id && !filter_mentions) || !tweet.in_reply_to_status_id){ + if(the_tweets.length == tweet_count) return; + the_tweets.push(tweet.text); + } + }); + Cookie.write('the_tweets',the_tweets.join('^!^!^!^!^'), { duration: 1 }); + showTweets(the_tweets); + } + }).retrieve(); + } else { + showTweets(Cookie.read('the_tweets'),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>'); + } +});
\ No newline at end of file |