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)
35 // 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);
48 makeNoticeItem: function(data)
51 html = data['html'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
52 source = data['source'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
54 ni = "<li class=\"hentry notice\" id=\"notice-"+data['id']+"\">"+
55 "<div class=\"entry-title\">"+
56 "<span class=\"vcard author\">"+
57 "<a href=\""+user['profile_url']+"\" class=\"url\">"+
58 "<img src=\""+user['profile_image_url']+"\" class=\"avatar photo\" width=\"48\" height=\"48\" alt=\""+user['screen_name']+"\"/>"+
59 "<span class=\"nickname fn\">"+user['screen_name']+"</span>"+
62 "<p class=\"entry-content\">"+html+"</p>"+
64 "<div class=\"entry-content\">"+
65 "<a class=\"timestamp\" rel=\"bookmark\" href=\""+data['url']+"\" >"+
66 "<abbr class=\"published\" title=\""+data['created_at']+"\">a few seconds ago</abbr>"+
68 "<span class=\"source\">"+
70 "<span class=\"device\">"+source+"</span>"+ // may have a link
72 if (data['in_reply_to_status_id']) {
73 ni = ni+" <a class=\"response\" href=\""+data['in_reply_to_status_url']+"\">in context</a>";
77 "<div class=\"notice-options\">";
79 if (RealtimeUpdate._userid != 0) {
80 var input = $("form#form_notice fieldset input#token");
81 var session_key = input.val();
82 ni = ni+RealtimeUpdate.makeFavoriteForm(data['id'], session_key);
83 ni = ni+RealtimeUpdate.makeReplyLink(data['id'], data['user']['screen_name']);
84 if (RealtimeUpdate._userid == data['user']['id']) {
85 ni = ni+RealtimeUpdate.makeDeleteLink(data['id']);
94 makeFavoriteForm: function(id, session_key)
98 ff = "<form id=\"favor-"+id+"\" class=\"form_favor\" method=\"post\" action=\""+RealtimeUpdate._favorurl+"\">"+
100 "<legend>Favor this notice</legend>"+
101 "<input name=\"token-"+id+"\" type=\"hidden\" id=\"token-"+id+"\" value=\""+session_key+"\"/>"+
102 "<input name=\"notice\" type=\"hidden\" id=\"notice-n"+id+"\" value=\""+id+"\"/>"+
103 "<input type=\"submit\" id=\"favor-submit-"+id+"\" name=\"favor-submit-"+id+"\" class=\"submit\" value=\"Favor\" title=\"Favor this notice\"/>"+
109 makeReplyLink: function(id, nickname)
112 rl = "<a class=\"notice_reply\" href=\""+RealtimeUpdate._replyurl+"?replyto="+nickname+"\" title=\"Reply to this notice\">Reply <span class=\"notice_id\">"+id+"</span></a>";
116 makeDeleteLink: function(id)
119 delurl = RealtimeUpdate._deleteurl.replace("0000000000", id);
121 dl = "<a class=\"notice_delete\" href=\""+delurl+"\" title=\"Delete this notice\">Delete</a>";
126 addPopup: function(url, timeline, iconurl)
128 $('#content').prepend('<button id="realtime_timeline" title="Pop up in a window">Pop up</button>');
130 $('#realtime_timeline').css({
131 'margin':'0 0 18px 0',
132 'background':'transparent url('+ iconurl + ') no-repeat 0% 30%',
133 'padding':'0 0 0 20px',
138 'color':$("a").css("color"),
139 'font-weight':'bold',
143 $('#realtime_timeline').click(function() {
146 'toolbar=no,resizable=yes,scrollbars=yes,status=yes');
152 initPopupWindow: function()
154 window.resizeTo(500, 550);
156 $('#content').css({'width':'93.5%'});
158 $('#form_notice').css({
159 'margin':'18px 0 18px 1.795%',
164 $('#form_notice label[for=notice_data-text], h1').css({'display': 'none'});
166 $('.notices li:first-child').css({'border-top-color':'transparent'});
168 $('#form_notice label[for="notice_data-attach"], #form_notice #notice_data-attach').css({'top':'0'});
170 $('#form_notice #notice_data-attach').css({