| author | veltr |
| Tue, 13 Nov 2012 11:46:27 +0100 | |
| changeset 42 | 48d825187d67 |
| parent 37 | db991a757015 |
| child 44 | 869410bab434 |
| permissions | -rw-r--r-- |
| 34 | 1 |
Rkns.Twitter = { |
2 |
} |
|
3 |
||
4 |
Rkns.Twitter.Search = function(_renkan, _opts) { |
|
5 |
this.renkan = _renkan; |
|
6 |
this.opts = _opts; |
|
7 |
} |
|
8 |
||
9 |
Rkns.Twitter.Search.prototype.getBgClass = function() { |
|
10 |
return "Rk-Twitter-Icon"; |
|
11 |
} |
|
| 21 | 12 |
|
| 34 | 13 |
Rkns.Twitter.Search.prototype.getSearchTitle = function() { |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
34
diff
changeset
|
14 |
return this.renkan.l10n.search_on_twitter; |
| 34 | 15 |
} |
16 |
||
17 |
Rkns.Twitter.Search.prototype.search = function(_q) { |
|
18 |
this.renkan.tabs.push( |
|
19 |
new Rkns.Twitter.Bin(this.renkan, { |
|
20 |
search: _q |
|
21 |
}) |
|
22 |
); |
|
23 |
} |
|
24 |
||
25 |
Rkns.Twitter.Bin = Rkns.Utils.inherit(Rkns._BaseBin); |
|
26 |
||
27 |
Rkns.Twitter.Bin.prototype.tweetTemplate = Rkns._.template( |
|
| 21 | 28 |
'<li class="Rk-Twitter-Tweet Rk-Bin-Item" data-uri="http://twitter.com/<%=tweet.from_user%>/status/<%=tweet.id_str%>" ' |
| 37 | 29 |
+ 'data-title="Tweet by @<%=tweet.from_user%>" data-description="<%-tweet.text%>" data-image="<%=tweet.profile_image_url%>">' |
| 21 | 30 |
+ '<img class="Rk-Twitter-TwImage" src="<%=tweet.profile_image_url%>" />' |
31 |
+ '<h4 class="Rk-Twitter-TwTitle"><a href="http://twitter.com/<%=tweet.from_user%>" target="_blank">@<%=tweet.from_user%></a> (<%=tweet.from_user_name%>)</h4>' |
|
32 |
+ '<p class="Rk-Twitter-TwDate"><%=date%></p>' |
|
33 |
+ '<p class="Rk-Twitter-TwText"><%=text%></p>' |
|
34 |
+ '<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> · ' |
|
35 |
+ '<a href="http://twitter.com/intent/tweet?in_reply_to=<%=tweet.id_str%>" target="_blank">reply</a> · ' |
|
36 |
+ '<a href="http://twitter.com/intent/retweet?tweet_id=<%=tweet.id_str%>" target="_blank">retweet</a> · ' |
|
37 |
+ '<a href="http://twitter.com/intent/favorite?tweet_id=<%=tweet.id_str%>" target="_blank">favorite</a></p></li>' |
|
38 |
); |
|
39 |
||
| 34 | 40 |
Rkns.Twitter.Bin.prototype._init = function(_renkan, _opts) { |
| 21 | 41 |
this.search = _opts.search; |
| 34 | 42 |
this.title_icon_$.addClass('Rk-Twitter-Title-Icon'); |
43 |
this.title_$.html(this.search).addClass("Rk-Twitter-Title"); |
|
| 42 | 44 |
this.refresh(); |
45 |
} |
|
46 |
||
47 |
Rkns.Twitter.Bin.prototype.refresh = function() { |
|
| 21 | 48 |
var _this = this; |
| 42 | 49 |
Rkns.$.ajax({ |
50 |
url: "http://search.twitter.com/search.json?q=" + encodeURIComponent(this.search), |
|
51 |
dataType: "jsonp", |
|
52 |
success: function(_data) { |
|
| 24 | 53 |
var _rgxp = new RegExp('('+_this.search.replace(/(\W)/g,'\\$1')+')','gi'); |
54 |
function highlight(_text) { |
|
55 |
return _text.replace(_rgxp, "<span class='searchmatch'>$1</span>"); |
|
56 |
} |
|
| 21 | 57 |
var _html = Rkns._(_data.results).map(function(_result) { |
58 |
var _entities = [], |
|
59 |
_users = _result.text.match(/@[\w_]+/gm), |
|
60 |
_lastpos = 0; |
|
61 |
if (_users) { |
|
62 |
for (var _i = 0; _i < _users.length; _i++) { |
|
63 |
var _m = _users[_i], |
|
64 |
_start = _lastpos + _result.text.substr(_lastpos).search(_m), |
|
65 |
_lastpos = _start + _m.length; |
|
66 |
_entities.push({ |
|
67 |
"text" : _m, |
|
68 |
"start" : _start, |
|
69 |
"end" : _lastpos, |
|
70 |
"link" :'<a href="http://twitter.com/' + _m.substr(1) + '" onclick="filtrerTexte(\'' + _m + '\'); return false;" target="_blank">', |
|
71 |
}); |
|
72 |
} |
|
73 |
} |
|
74 |
var _hashes = _result.text.match(/([^&]|^)#[^\s,.!?=#@&;()]+/gm), |
|
75 |
_lastpos = 0; |
|
76 |
if (_hashes) { |
|
77 |
for (var _i = 0; _i < _hashes.length; _i++) { |
|
78 |
var _m = _hashes[_i], |
|
79 |
_h = ( _m[0] == '#' ? _m : _m.substr(1) ), |
|
80 |
_start = _lastpos + _result.text.substr(_lastpos).search(_h), |
|
81 |
_lastpos = _start + _h.length; |
|
82 |
_entities.push({ |
|
83 |
"text" : _h, |
|
84 |
"start" : _start, |
|
85 |
"end" : _lastpos, |
|
86 |
"link" :'<a href="http://twitter.com/search?q=' + encodeURIComponent(_h) + '" onclick="filtrerTexte(\'' + _.escape(_h) + '\'); return false;" target="_blank">', |
|
87 |
}); |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
var _urls = _result.text.match(/(www\.|https?:\/\/)[\w./_\-]+/gim), |
|
92 |
_lastpos = 0; |
|
93 |
if (_urls) { |
|
94 |
for (var _i = 0; _i < _urls.length; _i++) { |
|
95 |
var _m = _urls[_i], |
|
96 |
_start = _lastpos + _result.text.substr(_lastpos).search(_m), |
|
97 |
_lastpos = _start + _m.length; |
|
98 |
_entities.push({ |
|
99 |
"text" : _m, |
|
100 |
"start" : _start, |
|
101 |
"end" : _lastpos, |
|
102 |
"link" :'<a href="' + _m + '" target="_blank">', |
|
103 |
}); |
|
104 |
} |
|
105 |
} |
|
106 |
_entities = Rkns._(_entities).sortBy(function(a) { return a.start }); |
|
107 |
var _lastend = 0, |
|
108 |
_text = Rkns._(_entities).map(function(_e) { |
|
| 24 | 109 |
var _txt = highlight(_result.text.substring(_lastend, _e.start)) + _e.link + highlight(_e.text) + '</a>'; |
| 21 | 110 |
_lastend = _e.end; |
111 |
return _txt; |
|
| 24 | 112 |
}).join("") + highlight(_result.text.substring(_lastend)); |
| 21 | 113 |
|
114 |
return _this.tweetTemplate({ |
|
115 |
tweet: _result, |
|
116 |
date: new Date(_result.created_at.replace(/(\+|-)/,'UTC$1')).toLocaleString(), |
|
117 |
text: _text |
|
118 |
}); |
|
119 |
}).join(""); |
|
120 |
_this.main_$.html(_html); |
|
| 26 | 121 |
_renkan.resizeBins(); |
| 21 | 122 |
} |
| 42 | 123 |
}); |
| 21 | 124 |
} |