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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
/*
Plugin: TwitterGitter
Author: David Walsh
Website: http://davidwalsh.name
Date: 2/21/2009
*/
var TwitterGitter = new Class({
//implements
Implements: [Options,Events],
//options
options: {
count: 2,
sinceID: 1,
link: true,
onRequest: $empty,
onComplete: $empty
},
//initialization
initialize: function(username,options) {
//set options
this.setOptions(options);
this.info = {};
this.username = username;
},
//get it!
retrieve: function() {
new JsonP('http://twitter.com/statuses/user_timeline/' + this.username + '.json',{
data: {
count: this.options.count,
since_id: this.options.sinceID
},
onRequest: this.fireEvent('request'),
onComplete: function(data) {
//linkify?
if(this.options.link) {
data.each(function(tweet) { tweet.text = this.linkify(tweet.text); },this);
}
//complete!
this.fireEvent('complete',[data,data[0].user]);
}.bind(this)
}).request();
return this;
},
//format
linkify: function(text) {
//courtesy of Jeremy Parrish (rrish.org)
return text.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>');
}
});
|