1 var out = "tritium4-content";
2 function json_request(url,method,params,output,type)
4 new Ajax.Request("./?show="+url,
9 onSuccess: function(data)
11 var json = data.responseText.evalJSON();
14 var content = '<ul class="comment-list">';
15 for (i = 0; i < json.length; ++i)
17 if (!json[i]["retweeted_status"])
20 var author = json[i][chunk].screen_name;
21 var avatar = json[i][chunk].profile_image_url;
22 var context = parse_tweet(json[i].text);
23 var date = json[i].created_at;
25 var name = json[i][chunk].name;
26 var retweeted = false;
27 var source = json[i].source;
28 var userid = json[i][chunk].id;
32 var chunk = "retweeted_status";
33 var author = json[i][chunk]["user"].screen_name;
34 var avatar = json[i][chunk]["user"].profile_image_url;
35 var context = parse_tweet(json[i][chunk].text);
36 var date = json[i][chunk].created_at;
37 var id = json[i][chunk]["user"].id;
38 var name = json[i][chunk]["user"].name;
39 var retweeted = "<strong>RT</strong> by "+name;
40 var source = json[i][chunk].source;
41 var userid = json[i][chunk]["user"].id;
43 date = relative_time(date);
44 content += '<li class="comment comment-parent" id="comment-'+id+'">';
45 content += '<div class="comment-profile-wrapper left">';
46 content += '<div class="comment-profile">';
47 content += '<div class="comment-gravatar">';
48 content += '<img src="'+avatar+'" height="30px" width="30px" alt="" />';
50 content += '<div class="comment-author">'+author+'</div>';
53 content += '<div class="comment-content-wrapper right">';
54 content += '<div class="comment-content-wrapper-2">';
55 content += '<div class="comment-body">';
56 content += '<div class="comment-arrow"></div>';
57 content += '<div id="comment-'+id+'-date" class="post-date">';
58 content += '<div class="left">'+date+'</div>';
59 /*content += '<div class="right"></div>';*/
60 content += '<div class="clearer"> </div>';
62 content += '<div class="hr"></div>';
63 content += '<div class="comment-text">';
64 content += '<p id="comment-'+id+'-text">'+context+'</p>';
66 content += '<div class="clearer"> </div>';
70 content += '<div class="clearer"> </div>';
74 $(output).update(content);
83 function loadhome(params)
85 new Effect.Appear("loading",
87 afterFinish: function()
89 var content = json_request("home","GET",params,out,1);
90 new Effect.Fade("loading",
92 afterFinish: function()
94 $("loading").setStyle("display:none;");
103 function loadmore(what,method,params,type)
107 //from the official twitter widget, (C) 2010 twitter
108 var relative_time = function (a)
112 var a = navigator.userAgent;
114 ie: a.match(/MSIE\s([^;]*)/)
121 c = Date.parse(a.replace(/( \+)/, ' UTC$1'))
124 var e = 1000, minute = e * 60, hour = minute * 60, day = hour * 24, week = day * 7, month = day * 30, year = month * 12;
125 if (isNaN(d) || d < 0)
135 return Math.floor(d / e) + " secs ago";
143 return Math.floor(d / minute) + " mins ago";
151 return Math.floor(d / hour) + " hrs ago";
153 if (d > day && d < day * 2)
159 return Math.floor(d / day) + " days ago";
161 if (d > week && d < week * 2)
165 if (d > week && d < month)
167 return Math.floor(d / week) + " weeks ago";
169 if (d > month && d < month * 2)
175 return Math.floor(d / month) + " months ago";
177 if (d > year && d < year * 2)
183 return Math.floor(d / year) + " years ago";
187 function parse_tweet(text)
195 text = text.replace(/((https?\:\/\/)|(www\.))([^ ]+)/g,function(url)
197 return '<a target="_blank" rel="nofollow" href="'+ url +'">'+url.replace(/^www./i,'')+'</a>';
199 text = text.replace(/@([\w*]+)/g,function(user)
201 return '<a target="_blank" rel="nofollow" href="http://twitter.com/'+user+'">'+user+'</a>';
203 text = text.replace(/#([\w*]+)/g,function(tag)
205 return '<a target="_blank" rel="nofollow" href="http://search.twitter.com/search?q='+tag.replace(/#/i,'%23')+'">'+tag+'</a>';