1 // add a notice encoded as JSON into the current timeline
11 init: function(userid, replyurl, favorurl, deleteurl)
13 RealtimeUpdate._userid = userid;
14 RealtimeUpdate._replyurl = replyurl;
15 RealtimeUpdate._favorurl = favorurl;
16 RealtimeUpdate._deleteurl = deleteurl;
18 $(window).blur(function() {
19 $('#notices_primary .notice').css({
20 'border-top-color':$('#notices_primary .notice:last').css('border-top-color'),
21 'border-top-style':'dotted'
24 $('#notices_primary .notice:first').css({
25 'border-top-color':'#AAAAAA',
26 'border-top-style':'solid'
31 receive: function(data)
33 setTimeout(function() {
36 // Don't add it if it already exists
37 if ($("#notice-"+id).length > 0) {
41 var noticeItem = RealtimeUpdate.makeNoticeItem(data);
42 $("#notices_primary .notices").prepend(noticeItem);
43 $("#notices_primary .notice:first").css({display:"none"});
44 $("#notices_primary .notice:first").fadeIn(1000);
49 makeNoticeItem: function(data)
52 html = data['html'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
53 source = data['source'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
55 ni = "<li class=\"hentry notice\" id=\"notice-"+data['id']+"\">"+
56 "<div class=\"entry-title\">"+
57 "<span class=\"vcard author\">"+
58 "<a href=\""+user['profile_url']+"\" class=\"url\">"+
59 "<img src=\""+user['profile_image_url']+"\" class=\"avatar photo\" width=\"48\" height=\"48\" alt=\""+user['screen_name']+"\"/>"+
60 "<span class=\"nickname fn\">"+user['screen_name']+"</span>"+
63 "<p class=\"entry-content\">"+html+"</p>"+
65 "<div class=\"entry-content\">"+
66 "<a class=\"timestamp\" rel=\"bookmark\" href=\""+data['url']+"\" >"+
67 "<abbr class=\"published\" title=\""+data['created_at']+"\">a few seconds ago</abbr>"+
69 "<span class=\"source\">"+
71 "<span class=\"device\">"+source+"</span>"+ // may have a link
73 if (data['in_reply_to_status_id']) {
74 ni = ni+" <a class=\"response\" href=\""+data['in_reply_to_status_url']+"\">in context</a>";
78 "<div class=\"notice-options\">";
80 if (RealtimeUpdate._userid != 0) {
81 var input = $("form#form_notice fieldset input#token");
82 var session_key = input.val();
83 ni = ni+RealtimeUpdate.makeFavoriteForm(data['id'], session_key);
84 ni = ni+RealtimeUpdate.makeReplyLink(data['id'], data['user']['screen_name']);
85 if (RealtimeUpdate._userid == data['user']['id']) {
86 ni = ni+RealtimeUpdate.makeDeleteLink(data['id']);
95 makeFavoriteForm: function(id, session_key)
99 ff = "<form id=\"favor-"+id+"\" class=\"form_favor\" method=\"post\" action=\""+RealtimeUpdate._favorurl+"\">"+
101 "<legend>Favor this notice</legend>"+
102 "<input name=\"token-"+id+"\" type=\"hidden\" id=\"token-"+id+"\" value=\""+session_key+"\"/>"+
103 "<input name=\"notice\" type=\"hidden\" id=\"notice-n"+id+"\" value=\""+id+"\"/>"+
104 "<input type=\"submit\" id=\"favor-submit-"+id+"\" name=\"favor-submit-"+id+"\" class=\"submit\" value=\"Favor\" title=\"Favor this notice\"/>"+
110 makeReplyLink: function(id, nickname)
113 rl = "<a class=\"notice_reply\" href=\""+RealtimeUpdate._replyurl+"?replyto="+nickname+"\" title=\"Reply to this notice\">Reply <span class=\"notice_id\">"+id+"</span></a>";
117 makeDeleteLink: function(id)
120 delurl = RealtimeUpdate._deleteurl.replace("0000000000", id);
122 dl = "<a class=\"notice_delete\" href=\""+delurl+"\" title=\"Delete this notice\">Delete</a>";
127 addPopup: function(url, timeline, iconurl)
129 $('#notices_primary').css({'position':'relative'});
130 $('#notices_primary').prepend('<button id="realtime_timeline" title="Pop up in a window">Pop up</button>');
132 $('#realtime_timeline').css({
133 'margin':'0 0 11px 0',
134 'background':'transparent url('+ iconurl + ') no-repeat 0% 30%',
135 'padding':'0 0 0 20px',
137 'position':'absolute',
142 'color':$("a").css("color"),
143 'font-weight':'bold',
147 $('#realtime_timeline').click(function() {
150 'toolbar=no,resizable=yes,scrollbars=yes,status=yes');
156 initPopupWindow: function()
158 window.resizeTo(500, 550);
160 $('#content').css({'width':'93.5%'});
162 $('#form_notice').css({
163 'margin':'18px 0 18px 1.795%',
168 $('#form_notice label[for=notice_data-text], h1').css({'display': 'none'});
170 $('.notices li:first-child').css({'border-top-color':'transparent'});
172 $('#form_notice label[for="notice_data-attach"], #form_notice #notice_data-attach').css({'top':'0'});
174 $('#form_notice #notice_data-attach').css({