1 $(document).ready(function() {
2 if (!$(document).getUrlParam('realtime')) {
3 $('#site_nav_local_views .current a').append('<button id="realtime_timeline" title="Pop this tab">↗</button>');
5 $('#realtime_timeline').css({
6 'margin':'2px 0 0 11px',
7 'background':'transparent url('+$('address .url')[0].href+'/plugins/Realtime/icon_external.gif) no-repeat 45% 45%',
8 'text-indent':'-9999px',
18 $('#realtime_timeline').click(function() {
19 window.open($(this).parent('a').attr('href')+'?realtime=1',
20 $(this).parent('a').attr('title'),
21 'toolbar=no,resizable=yes,scrollbars=yes,status=yes');
27 window.resizeTo(575, 640);
28 address = $('address');
29 content = $('#content');
30 $('body').html(address);
32 $('body').append(content);
33 $('#content').css({'width':'92%'});
37 // add a notice encoded as JSON into the current timeline
47 init: function(userid, replyurl, favorurl, deleteurl)
49 RealtimeUpdate._userid = userid;
50 RealtimeUpdate._replyurl = replyurl;
51 RealtimeUpdate._favorurl = favorurl;
52 RealtimeUpdate._deleteurl = deleteurl;
55 receive: function(data)
59 // Don't add it if it already exists
61 if ($("#notice-"+id).length > 0) {
65 var noticeItem = RealtimeUpdate.makeNoticeItem(data);
66 $("#notices_primary .notices").prepend(noticeItem, true);
67 $("#notices_primary .notice:first").css({display:"none"});
68 $("#notices_primary .notice:first").fadeIn(1000);
72 makeNoticeItem: function(data)
75 html = data['html'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
76 source = data['source'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
78 ni = "<li class=\"hentry notice\" id=\"notice-"+data['id']+"\">"+
79 "<div class=\"entry-title\">"+
80 "<span class=\"vcard author\">"+
81 "<a href=\""+user['profile_url']+"\" class=\"url\">"+
82 "<img src=\""+user['profile_image_url']+"\" class=\"avatar photo\" width=\"48\" height=\"48\" alt=\""+user['screen_name']+"\"/>"+
83 "<span class=\"nickname fn\">"+user['screen_name']+"</span>"+
86 "<p class=\"entry-content\">"+html+"</p>"+
88 "<div class=\"entry-content\">"+
89 "<a class=\"timestamp\" rel=\"bookmark\" href=\""+data['url']+"\" >"+
90 "<abbr class=\"published\" title=\""+data['created_at']+"\">a few seconds ago</abbr>"+
92 "<span class=\"source\">"+
94 "<span class=\"device\">"+source+"</span>"+ // may have a link
96 if (data['in_reply_to_status_id']) {
97 ni = ni+" <a class=\"response\" href=\""+data['in_reply_to_status_url']+"\">in context</a>";
101 "<div class=\"notice-options\">";
103 if (RealtimeUpdate._userid != 0) {
104 var input = $("form#form_notice fieldset input#token");
105 var session_key = input.val();
106 ni = ni+RealtimeUpdate.makeFavoriteForm(data['id'], session_key);
107 ni = ni+RealtimeUpdate.makeReplyLink(data['id'], data['user']['screen_name']);
108 if (RealtimeUpdate._userid == data['user']['id']) {
109 ni = ni+RealtimeUpdate.makeDeleteLink(data['id']);
118 makeFavoriteForm: function(id, session_key)
122 ff = "<form id=\"favor-"+id+"\" class=\"form_favor\" method=\"post\" action=\""+RealtimeUpdate._favorurl+"\">"+
124 "<legend>Favor this notice</legend>"+
125 "<input name=\"token-"+id+"\" type=\"hidden\" id=\"token-"+id+"\" value=\""+session_key+"\"/>"+
126 "<input name=\"notice\" type=\"hidden\" id=\"notice-n"+id+"\" value=\""+id+"\"/>"+
127 "<input type=\"submit\" id=\"favor-submit-"+id+"\" name=\"favor-submit-"+id+"\" class=\"submit\" value=\"Favor\" title=\"Favor this notice\"/>"+
133 makeReplyLink: function(id, nickname)
136 rl = "<a class=\"notice_reply\" href=\""+RealtimeUpdate._replyurl+"?replyto="+nickname+"\" title=\"Reply to this notice\">Reply <span class=\"notice_id\">"+id+"</span></a>";
140 makeDeleteLink: function(id)
143 delurl = RealtimeUpdate._deleteurl.replace("0000000000", id);
145 dl = "<a class=\"notice_delete\" href=\""+delurl+"\" title=\"Delete this notice\">Delete</a>";