|
21
|
1 |
Rkns.Bins.Twitter = Rkns.Utils.inherit(Rkns.Bins._Base); |
|
|
2 |
|
|
|
3 |
Rkns.Bins.Twitter.prototype.tweetTemplate = Rkns._.template( |
|
|
4 |
'<li class="Rk-Twitter-Tweet Rk-Bin-Item" data-uri="http://twitter.com/<%=tweet.from_user%>/status/<%=tweet.id_str%>" ' |
|
|
5 |
+ 'data-title="Tweet by @<%=tweet.from_user%>" data-description="<%-tweet.text%>">' |
|
|
6 |
+ '<img class="Rk-Twitter-TwImage" src="<%=tweet.profile_image_url%>" />' |
|
|
7 |
+ '<h4 class="Rk-Twitter-TwTitle"><a href="http://twitter.com/<%=tweet.from_user%>" target="_blank">@<%=tweet.from_user%></a> (<%=tweet.from_user_name%>)</h4>' |
|
|
8 |
+ '<p class="Rk-Twitter-TwDate"><%=date%></p>' |
|
|
9 |
+ '<p class="Rk-Twitter-TwText"><%=text%></p>' |
|
|
10 |
+ '<p class="Rk-Twitter-TwActions"><a class="Rk-Twitter-TwAction" href="http://twitter.com/<%=tweet.from_user%>/status/<%=tweet.id_str%>" target="_blank">show original</a> · ' |
|
|
11 |
+ '<a href="http://twitter.com/intent/tweet?in_reply_to=<%=tweet.id_str%>" target="_blank">reply</a> · ' |
|
|
12 |
+ '<a href="http://twitter.com/intent/retweet?tweet_id=<%=tweet.id_str%>" target="_blank">retweet</a> · ' |
|
|
13 |
+ '<a href="http://twitter.com/intent/favorite?tweet_id=<%=tweet.id_str%>" target="_blank">favorite</a></p></li>' |
|
|
14 |
); |
|
|
15 |
|
|
|
16 |
Rkns.Bins.Twitter.prototype._init = function(_renkan, _opts) { |
|
|
17 |
this.search = _opts.search; |
|
|
18 |
this.title_$.html('Twitter: "' + this.search + '"') |
|
|
19 |
var _this = this; |
|
|
20 |
Rkns.$.getJSON( |
|
|
21 |
"http://search.twitter.com/search.json?q=" + encodeURIComponent(this.search) + "&callback=?", |
|
|
22 |
function(_data) { |
|
|
23 |
var _html = Rkns._(_data.results).map(function(_result) { |
|
|
24 |
var _entities = [], |
|
|
25 |
_users = _result.text.match(/@[\w_]+/gm), |
|
|
26 |
_lastpos = 0; |
|
|
27 |
if (_users) { |
|
|
28 |
for (var _i = 0; _i < _users.length; _i++) { |
|
|
29 |
var _m = _users[_i], |
|
|
30 |
_start = _lastpos + _result.text.substr(_lastpos).search(_m), |
|
|
31 |
_lastpos = _start + _m.length; |
|
|
32 |
_entities.push({ |
|
|
33 |
"text" : _m, |
|
|
34 |
"start" : _start, |
|
|
35 |
"end" : _lastpos, |
|
|
36 |
"link" :'<a href="http://twitter.com/' + _m.substr(1) + '" onclick="filtrerTexte(\'' + _m + '\'); return false;" target="_blank">', |
|
|
37 |
}); |
|
|
38 |
} |
|
|
39 |
} |
|
|
40 |
var _hashes = _result.text.match(/([^&]|^)#[^\s,.!?=#@&;()]+/gm), |
|
|
41 |
_lastpos = 0; |
|
|
42 |
if (_hashes) { |
|
|
43 |
for (var _i = 0; _i < _hashes.length; _i++) { |
|
|
44 |
var _m = _hashes[_i], |
|
|
45 |
_h = ( _m[0] == '#' ? _m : _m.substr(1) ), |
|
|
46 |
_start = _lastpos + _result.text.substr(_lastpos).search(_h), |
|
|
47 |
_lastpos = _start + _h.length; |
|
|
48 |
_entities.push({ |
|
|
49 |
"text" : _h, |
|
|
50 |
"start" : _start, |
|
|
51 |
"end" : _lastpos, |
|
|
52 |
"link" :'<a href="http://twitter.com/search?q=' + encodeURIComponent(_h) + '" onclick="filtrerTexte(\'' + _.escape(_h) + '\'); return false;" target="_blank">', |
|
|
53 |
}); |
|
|
54 |
} |
|
|
55 |
} |
|
|
56 |
|
|
|
57 |
var _urls = _result.text.match(/(www\.|https?:\/\/)[\w./_\-]+/gim), |
|
|
58 |
_lastpos = 0; |
|
|
59 |
if (_urls) { |
|
|
60 |
for (var _i = 0; _i < _urls.length; _i++) { |
|
|
61 |
var _m = _urls[_i], |
|
|
62 |
_start = _lastpos + _result.text.substr(_lastpos).search(_m), |
|
|
63 |
_lastpos = _start + _m.length; |
|
|
64 |
_entities.push({ |
|
|
65 |
"text" : _m, |
|
|
66 |
"start" : _start, |
|
|
67 |
"end" : _lastpos, |
|
|
68 |
"link" :'<a href="' + _m + '" target="_blank">', |
|
|
69 |
}); |
|
|
70 |
} |
|
|
71 |
} |
|
|
72 |
_entities = Rkns._(_entities).sortBy(function(a) { return a.start }); |
|
|
73 |
var _lastend = 0, |
|
|
74 |
_text = Rkns._(_entities).map(function(_e) { |
|
|
75 |
var _txt = _result.text.substring(_lastend, _e.start) + _e.link + _e.text + '</a>'; |
|
|
76 |
_lastend = _e.end; |
|
|
77 |
return _txt; |
|
|
78 |
}).join("") + _result.text.substring(_lastend); |
|
|
79 |
|
|
|
80 |
return _this.tweetTemplate({ |
|
|
81 |
tweet: _result, |
|
|
82 |
date: new Date(_result.created_at.replace(/(\+|-)/,'UTC$1')).toLocaleString(), |
|
|
83 |
text: _text |
|
|
84 |
}); |
|
|
85 |
}).join(""); |
|
|
86 |
_this.main_$.html(_html); |
|
|
87 |
} |
|
|
88 |
); |
|
|
89 |
} |