-
-
Save cheeaun/189637 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Request.Twitter = new Class({ | |
Extends: Request.JSONP, | |
options: { | |
linkify: true, | |
url: 'http://twitter.com/statuses/user_timeline/{term}.json', | |
data: { | |
count: 5 | |
} | |
}, | |
initialize: function(term, options){ | |
this.parent(options); | |
this.options.url = this.options.url.substitute({term: term}); | |
}, | |
success: function(data, script){ | |
if (this.options.linkify) data.each(function(tweet){ | |
tweet.formattedText = this.linkify(tweet.text); | |
}, this); | |
if (data[0]) this.options.data.since_id = data[0].id; // keep subsequent calls newer | |
this.parent(data, script); | |
}, | |
linkify: function(text){ | |
// modified from TwitterGitter by David Walsh (davidwalsh.name) | |
// courtesy of Jeremy Parrish (rrish.org) | |
// slightly modified again to be more accurate (cheeaun) | |
return text.replace(/(https?:\/\/[\w\-:;?&=+.%#\/]+)/gi, '<a href="$1">$1</a>') | |
.replace(/\B@([_a-z0-9]{1,15})/ig, '<a href="http://twitter.com/$1">@$1</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