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'
33 receive: function(data)
35 setTimeout(function() {
38 // Don't add it if it already exists
39 if ($("#notice-"+id).length > 0) {
43 var noticeItem = RealtimeUpdate.makeNoticeItem(data);
44 $("#notices_primary .notices").prepend(noticeItem);
45 $("#notices_primary .notice:first").css({display:"none"});
46 $("#notices_primary .notice:first").fadeIn(1000);
51 makeNoticeItem: function(data)
54 html = data['html'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
55 source = data['source'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
57 ni = "<li class=\"hentry notice\" id=\"notice-"+data['id']+"\">"+
58 "<div class=\"entry-title\">"+
59 "<span class=\"vcard author\">"+
60 "<a href=\""+user['profile_url']+"\" class=\"url\">"+
61 "<img src=\""+user['profile_image_url']+"\" class=\"avatar photo\" width=\"48\" height=\"48\" alt=\""+user['screen_name']+"\"/>"+
62 "<span class=\"nickname fn\">"+user['screen_name']+"</span>"+
65 "<p class=\"entry-content\">"+html+"</p>"+
67 "<div class=\"entry-content\">"+
68 "<a class=\"timestamp\" rel=\"bookmark\" href=\""+data['url']+"\" >"+
69 "<abbr class=\"published\" title=\""+data['created_at']+"\">a few seconds ago</abbr>"+
71 "<span class=\"source\">"+
73 "<span class=\"device\">"+source+"</span>"+ // may have a link
75 if (data['in_reply_to_status_id']) {
76 ni = ni+" <a class=\"response\" href=\""+data['in_reply_to_status_url']+"\">in context</a>";
80 "<div class=\"notice-options\">";
82 if (RealtimeUpdate._userid != 0) {
83 var input = $("form#form_notice fieldset input#token");
84 var session_key = input.val();
85 ni = ni+RealtimeUpdate.makeFavoriteForm(data['id'], session_key);
86 ni = ni+RealtimeUpdate.makeReplyLink(data['id'], data['user']['screen_name']);
87 if (RealtimeUpdate._userid == data['user']['id']) {
88 ni = ni+RealtimeUpdate.makeDeleteLink(data['id']);
97 makeFavoriteForm: function(id, session_key)
101 ff = "<form id=\"favor-"+id+"\" class=\"form_favor\" method=\"post\" action=\""+RealtimeUpdate._favorurl+"\">"+
103 "<legend>Favor this notice</legend>"+
104 "<input name=\"token-"+id+"\" type=\"hidden\" id=\"token-"+id+"\" value=\""+session_key+"\"/>"+
105 "<input name=\"notice\" type=\"hidden\" id=\"notice-n"+id+"\" value=\""+id+"\"/>"+
106 "<input type=\"submit\" id=\"favor-submit-"+id+"\" name=\"favor-submit-"+id+"\" class=\"submit\" value=\"Favor\" title=\"Favor this notice\"/>"+
112 makeReplyLink: function(id, nickname)
115 rl = "<a class=\"notice_reply\" href=\""+RealtimeUpdate._replyurl+"?replyto="+nickname+"\" title=\"Reply to this notice\">Reply <span class=\"notice_id\">"+id+"</span></a>";
119 makeDeleteLink: function(id)
122 delurl = RealtimeUpdate._deleteurl.replace("0000000000", id);
124 dl = "<a class=\"notice_delete\" href=\""+delurl+"\" title=\"Delete this notice\">Delete</a>";
129 addPopup: function(url, timeline, iconurl)
131 $('#notices_primary').css({'position':'relative'});
132 $('#notices_primary').prepend('<button id="realtime_timeline" title="Pop up in a window">Pop up</button>');
134 $('#realtime_timeline').css({
135 'margin':'0 0 11px 0',
136 'background':'transparent url('+ iconurl + ') no-repeat 0% 30%',
137 'padding':'0 0 0 20px',
139 'position':'absolute',
144 'color':$("a").css("color"),
145 'font-weight':'bold',
149 $('#realtime_timeline').click(function() {
152 'toolbar=no,resizable=yes,scrollbars=yes,status=yes');
158 initPopupWindow: function()
160 window.resizeTo(500, 550);
162 $('#content').css({'width':'93.5%'});
164 $('#form_notice').css({
165 'margin':'18px 0 18px 1.795%',
170 $('#form_notice label[for=notice_data-text], h1').css({'display': 'none'});
172 $('.notices li:first-child').css({'border-top-color':'transparent'});
174 $('#form_notice label[for="notice_data-attach"], #form_notice #notice_data-attach').css({'top':'0'});
176 $('#form_notice #notice_data-attach').css({