diff -r bd58970ffd16 -r b43dd87f7ffa client/js/twitter-bin.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/client/js/twitter-bin.js Fri Aug 17 18:36:12 2012 +0200
@@ -0,0 +1,89 @@
+Rkns.Bins.Twitter = Rkns.Utils.inherit(Rkns.Bins._Base);
+
+Rkns.Bins.Twitter.prototype.tweetTemplate = Rkns._.template(
+ '
'
+);
+
+Rkns.Bins.Twitter.prototype._init = function(_renkan, _opts) {
+ this.search = _opts.search;
+ this.title_$.html('Twitter: "' + this.search + '"')
+ var _this = this;
+ Rkns.$.getJSON(
+ "http://search.twitter.com/search.json?q=" + encodeURIComponent(this.search) + "&callback=?",
+ function(_data) {
+ var _html = Rkns._(_data.results).map(function(_result) {
+ var _entities = [],
+ _users = _result.text.match(/@[\w_]+/gm),
+ _lastpos = 0;
+ if (_users) {
+ for (var _i = 0; _i < _users.length; _i++) {
+ var _m = _users[_i],
+ _start = _lastpos + _result.text.substr(_lastpos).search(_m),
+ _lastpos = _start + _m.length;
+ _entities.push({
+ "text" : _m,
+ "start" : _start,
+ "end" : _lastpos,
+ "link" :'',
+ });
+ }
+ }
+ var _hashes = _result.text.match(/([^&]|^)#[^\s,.!?=#@&;()]+/gm),
+ _lastpos = 0;
+ if (_hashes) {
+ for (var _i = 0; _i < _hashes.length; _i++) {
+ var _m = _hashes[_i],
+ _h = ( _m[0] == '#' ? _m : _m.substr(1) ),
+ _start = _lastpos + _result.text.substr(_lastpos).search(_h),
+ _lastpos = _start + _h.length;
+ _entities.push({
+ "text" : _h,
+ "start" : _start,
+ "end" : _lastpos,
+ "link" :'',
+ });
+ }
+ }
+
+ var _urls = _result.text.match(/(www\.|https?:\/\/)[\w./_\-]+/gim),
+ _lastpos = 0;
+ if (_urls) {
+ for (var _i = 0; _i < _urls.length; _i++) {
+ var _m = _urls[_i],
+ _start = _lastpos + _result.text.substr(_lastpos).search(_m),
+ _lastpos = _start + _m.length;
+ _entities.push({
+ "text" : _m,
+ "start" : _start,
+ "end" : _lastpos,
+ "link" :'',
+ });
+ }
+ }
+ _entities = Rkns._(_entities).sortBy(function(a) { return a.start });
+ var _lastend = 0,
+ _text = Rkns._(_entities).map(function(_e) {
+ var _txt = _result.text.substring(_lastend, _e.start) + _e.link + _e.text + '';
+ _lastend = _e.end;
+ return _txt;
+ }).join("") + _result.text.substring(_lastend);
+
+ return _this.tweetTemplate({
+ tweet: _result,
+ date: new Date(_result.created_at.replace(/(\+|-)/,'UTC$1')).toLocaleString(),
+ text: _text
+ });
+ }).join("");
+ _this.main_$.html(_html);
+ }
+ );
+}