himanshuc (owner)

Fork Of

Revisions

gist: 233047 Download_button fork
public
Public Clone URL: git://gist.github.com/233047.git
Embed All Files: show embed
Request.Twitter.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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.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>');
}
 
});