Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created May 29, 2010 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkphp/418480 to your computer and use it in GitHub Desktop.
Save thinkphp/418480 to your computer and use it in GitHub Desktop.
Request.Twitter = new Class({
Extends: Request.JSONP,
options: {
url: 'http://twitter.com/statuses/user_timeline/{username}.json',
data: {
count: 5
},
linkify: true
},
initialize: function(username,options) {
this.parent(options);
this.options.url = this.options.url.substitute({username: username});
},
success: function(data,script) {
data = Array.flatten(data);
if(this.options.linkify) {
data.each(function(tweets){
tweets.text = this.linkify(tweets.text);
},this);
}
this.parent([data],script);
},
linkify: function(str){
return str.replace(/(https?:\/\/[\w\-:;?&=+.%#\/]+)/gi, '<a href="$1">$1</a>')
.replace(/(^|\W)@(\w+)/g, '$1<a href="http://twitter.com/$2">@$2</a>')
.replace(/(^|\W)#(\w+)/g, '$1#<a href="http://search.twitter.com/search?q=%23$2">$2</a>')
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment