1 // add a notice encoded as JSON into the current timeline
12 init: function(userid, replyurl, favorurl, deleteurl)
14 RealtimeUpdate._userid = userid;
15 RealtimeUpdate._replyurl = replyurl;
16 RealtimeUpdate._favorurl = favorurl;
17 RealtimeUpdate._deleteurl = deleteurl;
21 $(window).blur(function() {
22 $('#notices_primary .notice').css({
23 'border-top-color':$('#notices_primary .notice:last').css('border-top-color'),
24 'border-top-style':'dotted'
27 $('#notices_primary .notice:first').css({
28 'border-top-color':'#AAAAAA',
29 'border-top-style':'solid'
32 RealtimeUpdate._updatecounter = 0;
39 receive: function(data)
41 setTimeout(function() {
44 // Don't add it if it already exists
45 if ($("#notice-"+id).length > 0) {
49 var noticeItem = RealtimeUpdate.makeNoticeItem(data);
50 $("#notices_primary .notices").prepend(noticeItem);
51 $("#notices_primary .notice:first").css({display:"none"});
52 $("#notices_primary .notice:first").fadeIn(1000);
55 RealtimeUpdate._updatecounter += 1;
56 document.title = '('+RealtimeUpdate._updatecounter+') ' + DT;
60 makeNoticeItem: function(data)
63 html = data['html'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
64 source = data['source'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
66 ni = "<li class=\"hentry notice\" id=\"notice-"+data['id']+"\">"+
67 "<div class=\"entry-title\">"+
68 "<span class=\"vcard author\">"+
69 "<a href=\""+user['profile_url']+"\" class=\"url\">"+
70 "<img src=\""+user['profile_image_url']+"\" class=\"avatar photo\" width=\"48\" height=\"48\" alt=\""+user['screen_name']+"\"/>"+
71 "<span class=\"nickname fn\">"+user['screen_name']+"</span>"+
74 "<p class=\"entry-content\">"+html+"</p>"+
76 "<div class=\"entry-content\">"+
77 "<a class=\"timestamp\" rel=\"bookmark\" href=\""+data['url']+"\" >"+
78 "<abbr class=\"published\" title=\""+data['created_at']+"\">a few seconds ago</abbr>"+
80 "<span class=\"source\">"+
82 "<span class=\"device\">"+source+"</span>"+ // may have a link
84 if (data['in_reply_to_status_id']) {
85 ni = ni+" <a class=\"response\" href=\""+data['in_reply_to_status_url']+"\">in context</a>";
89 "<div class=\"notice-options\">";
91 if (RealtimeUpdate._userid != 0) {
92 var input = $("form#form_notice fieldset input#token");
93 var session_key = input.val();
94 ni = ni+RealtimeUpdate.makeFavoriteForm(data['id'], session_key);
95 ni = ni+RealtimeUpdate.makeReplyLink(data['id'], data['user']['screen_name']);
96 if (RealtimeUpdate._userid == data['user']['id']) {
97 ni = ni+RealtimeUpdate.makeDeleteLink(data['id']);
106 makeFavoriteForm: function(id, session_key)
110 ff = "<form id=\"favor-"+id+"\" class=\"form_favor\" method=\"post\" action=\""+RealtimeUpdate._favorurl+"\">"+
112 "<legend>Favor this notice</legend>"+
113 "<input name=\"token-"+id+"\" type=\"hidden\" id=\"token-"+id+"\" value=\""+session_key+"\"/>"+
114 "<input name=\"notice\" type=\"hidden\" id=\"notice-n"+id+"\" value=\""+id+"\"/>"+
115 "<input type=\"submit\" id=\"favor-submit-"+id+"\" name=\"favor-submit-"+id+"\" class=\"submit\" value=\"Favor\" title=\"Favor this notice\"/>"+
121 makeReplyLink: function(id, nickname)
124 rl = "<a class=\"notice_reply\" href=\""+RealtimeUpdate._replyurl+"?replyto="+nickname+"\" title=\"Reply to this notice\">Reply <span class=\"notice_id\">"+id+"</span></a>";
128 makeDeleteLink: function(id)
131 delurl = RealtimeUpdate._deleteurl.replace("0000000000", id);
133 dl = "<a class=\"notice_delete\" href=\""+delurl+"\" title=\"Delete this notice\">Delete</a>";
138 addPopup: function(url, timeline, iconurl)
140 $('#notices_primary').css({'position':'relative'});
141 $('#notices_primary').prepend('<button id="realtime_timeline" title="Pop up in a window">Pop up</button>');
143 $('#realtime_timeline').css({
144 'margin':'0 0 11px 0',
145 'background':'transparent url('+ iconurl + ') no-repeat 0% 30%',
146 'padding':'0 0 0 20px',
148 'position':'absolute',
153 'color':$("a").css("color"),
154 'font-weight':'bold',
158 $('#realtime_timeline').click(function() {
161 'toolbar=no,resizable=yes,scrollbars=yes,status=yes');
167 initPopupWindow: function()
169 window.resizeTo(500, 550);
171 $('#content').css({'width':'93.5%'});
173 $('#form_notice').css({
174 'margin':'18px 0 18px 1.795%',
179 $('#form_notice label[for=notice_data-text], h1').css({'display': 'none'});
181 $('.notices li:first-child').css({'border-top-color':'transparent'});
183 $('#form_notice label[for="notice_data-attach"], #form_notice #notice_data-attach').css({'top':'0'});
185 $('#form_notice #notice_data-attach').css({