2 * StatusNet - a distributed open-source microblogging tool
3 * Copyright (C) 2008, StatusNet, Inc.
5 * Add a notice encoded as JSON into the current timeline
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * @author Evan Prodromou <evan@status.net>
23 * @author Sarven Capadisli <csarven@status.net>
24 * @copyright 2009 StatusNet, Inc.
25 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
26 * @link http://status.net/
38 init: function(userid, replyurl, favorurl, deleteurl)
40 RealtimeUpdate._userid = userid;
41 RealtimeUpdate._replyurl = replyurl;
42 RealtimeUpdate._favorurl = favorurl;
43 RealtimeUpdate._deleteurl = deleteurl;
47 $(window).blur(function() {
48 $('#notices_primary .notice').removeClass('mark-top');
50 $('#notices_primary .notice:first').addClass('mark-top');
52 RealtimeUpdate._updatecounter = 0;
59 receive: function(data)
63 // Don't add it if it already exists
64 if ($("#notice-"+id).length > 0) {
68 var noticeItem = RealtimeUpdate.makeNoticeItem(data);
69 $("#notices_primary .notices").prepend(noticeItem);
70 $("#notices_primary .notice:first").css({display:"none"});
71 $("#notices_primary .notice:first").fadeIn(1000);
75 RealtimeUpdate._updatecounter += 1;
76 document.title = '('+RealtimeUpdate._updatecounter+') ' + DT;
79 makeNoticeItem: function(data)
82 html = data['html'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
83 source = data['source'].replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
85 ni = "<li class=\"hentry notice\" id=\"notice-"+data['id']+"\">"+
86 "<div class=\"entry-title\">"+
87 "<span class=\"vcard author\">"+
88 "<a href=\""+user['profile_url']+"\" class=\"url\">"+
89 "<img src=\""+user['profile_image_url']+"\" class=\"avatar photo\" width=\"48\" height=\"48\" alt=\""+user['screen_name']+"\"/>"+
90 "<span class=\"nickname fn\">"+user['screen_name']+"</span>"+
93 "<p class=\"entry-content\">"+html+"</p>"+
95 "<div class=\"entry-content\">"+
96 "<a class=\"timestamp\" rel=\"bookmark\" href=\""+data['url']+"\" >"+
97 "<abbr class=\"published\" title=\""+data['created_at']+"\">a few seconds ago</abbr>"+
99 "<span class=\"source\">"+
101 "<span class=\"device\">"+source+"</span>"+ // may have a link
103 if (data['in_reply_to_status_id']) {
104 ni = ni+" <a class=\"response\" href=\""+data['in_reply_to_status_url']+"\">in context</a>";
108 "<div class=\"notice-options\">";
110 if (RealtimeUpdate._userid != 0) {
111 var input = $("form#form_notice fieldset input#token");
112 var session_key = input.val();
113 ni = ni+RealtimeUpdate.makeFavoriteForm(data['id'], session_key);
114 ni = ni+RealtimeUpdate.makeReplyLink(data['id'], data['user']['screen_name']);
115 if (RealtimeUpdate._userid == data['user']['id']) {
116 ni = ni+RealtimeUpdate.makeDeleteLink(data['id']);
125 makeFavoriteForm: function(id, session_key)
129 ff = "<form id=\"favor-"+id+"\" class=\"form_favor\" method=\"post\" action=\""+RealtimeUpdate._favorurl+"\">"+
131 "<legend>Favor this notice</legend>"+
132 "<input name=\"token-"+id+"\" type=\"hidden\" id=\"token-"+id+"\" value=\""+session_key+"\"/>"+
133 "<input name=\"notice\" type=\"hidden\" id=\"notice-n"+id+"\" value=\""+id+"\"/>"+
134 "<input type=\"submit\" id=\"favor-submit-"+id+"\" name=\"favor-submit-"+id+"\" class=\"submit\" value=\"Favor\" title=\"Favor this notice\"/>"+
140 makeReplyLink: function(id, nickname)
143 rl = "<a class=\"notice_reply\" href=\""+RealtimeUpdate._replyurl+"?replyto="+nickname+"\" title=\"Reply to this notice\">Reply <span class=\"notice_id\">"+id+"</span></a>";
147 makeDeleteLink: function(id)
150 delurl = RealtimeUpdate._deleteurl.replace("0000000000", id);
152 dl = "<a class=\"notice_delete\" href=\""+delurl+"\" title=\"Delete this notice\">Delete</a>";
157 addPopup: function(url, timeline, iconurl)
159 var NP = $('#notices_primary');
160 NP.css({'position':'relative'});
161 NP.prepend('<button id="realtime_timeline" title="Pop up in a window">Pop up</button>');
163 var RT = $('#realtime_timeline');
165 'margin':'0 0 11px 0',
166 'background':'transparent url('+ iconurl + ') no-repeat 0 30%',
167 'padding':'0 0 0 20px',
169 'position':'absolute',
174 'color':$('a').css('color'),
175 'font-weight':'bold',
178 $('#showstream #notices_primary').css({'margin-top':'18px'});
180 RT.click(function() {
183 'toolbar=no,resizable=yes,scrollbars=yes,status=yes,width=500,height=550');
189 initPopupWindow: function()
192 $('#content').css({'width':'93.5%'});
194 $('#form_notice').css({
195 'margin':'18px 0 18px 1.795%',
200 $('#form_notice label[for=notice_data-text], h1').css({'display': 'none'});
202 $('.notices li:first-child').css({'border-top-color':'transparent'});
204 $('#form_notice label[for="notice_data-attach"], #form_notice #notice_data-attach').css({'top':'0'});
206 $('#form_notice #notice_data-attach').css({
211 $('.notices .entry-title a, .notices .entry-content a').bind('click', function() {
212 window.open(this.href, '');