Skip to content

Instantly share code, notes, and snippets.

@tehmaze
Forked from appden/Request.Twitter.js
Created January 8, 2011 17:52
Show Gist options
  • Save tehmaze/771026 to your computer and use it in GitHub Desktop.
Save tehmaze/771026 to your computer and use it in GitHub Desktop.
Request.Twitter = new Class({
Extends: Request.JSONP,
options: {
linkify: true,
url: '/twitter/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) Array.each(data[0], function(tweet){
tweet.text = 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)
return text.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>');
}
});
@tehmaze
Copy link
Author

tehmaze commented Jan 9, 2011

New version, made it MooTools 1.3 compatible (without compatibility).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment