]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Realtime/realtimeupdate.js
Merge branch '0.8.x' of git://gitorious.org/~brion/statusnet/brion-fixes into 0.8.x
[quix0rs-gnu-social.git] / plugins / Realtime / realtimeupdate.js
1 // add a notice encoded as JSON into the current timeline
2 //
3 // TODO: i18n
4
5 RealtimeUpdate = {
6      _userid: 0,
7      _replyurl: '',
8      _favorurl: '',
9      _deleteurl: '',
10
11      init: function(userid, replyurl, favorurl, deleteurl)
12      {
13         RealtimeUpdate._userid = userid;
14         RealtimeUpdate._replyurl = replyurl;
15         RealtimeUpdate._favorurl = favorurl;
16         RealtimeUpdate._deleteurl = deleteurl;
17      },
18
19      receive: function(data)
20      {
21           id = data.id;
22
23           // Don't add it if it already exists
24           //
25           if ($("#notice-"+id).length > 0) {
26                return;
27           }
28
29           var noticeItem = RealtimeUpdate.makeNoticeItem(data);
30           $("#notices_primary .notices").prepend(noticeItem, true);
31           $("#notices_primary .notice:first").css({display:"none"});
32           $("#notices_primary .notice:first").fadeIn(1000);
33           NoticeReply();
34      },
35
36      makeNoticeItem: function(data)
37      {
38           user = data['user'];
39           html = data['html'].replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&quot;/g,'"');
40           source = data['source'].replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&quot;/g,'"');
41
42           ni = "<li class=\"hentry notice\" id=\"notice-"+data['id']+"\">"+
43                "<div class=\"entry-title\">"+
44                "<span class=\"vcard author\">"+
45                "<a href=\""+user['profile_url']+"\" class=\"url\">"+
46                "<img src=\""+user['profile_image_url']+"\" class=\"avatar photo\" width=\"48\" height=\"48\" alt=\""+user['screen_name']+"\"/>"+
47                "<span class=\"nickname fn\">"+user['screen_name']+"</span>"+
48                "</a>"+
49                "</span>"+
50                "<p class=\"entry-content\">"+html+"</p>"+
51                "</div>"+
52                "<div class=\"entry-content\">"+
53                "<a class=\"timestamp\" rel=\"bookmark\" href=\""+data['url']+"\" >"+
54                "<abbr class=\"published\" title=\""+data['created_at']+"\">a few seconds ago</abbr>"+
55                "</a> "+
56                "<span class=\"source\">"+
57                "from "+
58                 "<span class=\"device\">"+source+"</span>"+ // may have a link
59                "</span>";
60           if (data['in_reply_to_status_id']) {
61                ni = ni+" <a class=\"response\" href=\""+data['in_reply_to_status_url']+"\">in context</a>";
62           }
63
64           ni = ni+"</div>"+
65             "<div class=\"notice-options\">";
66
67           if (RealtimeUpdate._userid != 0) {
68                var input = $("form#form_notice fieldset input#token");
69                var session_key = input.val();
70                ni = ni+RealtimeUpdate.makeFavoriteForm(data['id'], session_key);
71                ni = ni+RealtimeUpdate.makeReplyLink(data['id'], data['user']['screen_name']);
72                if (RealtimeUpdate._userid == data['user']['id']) {
73                     ni = ni+RealtimeUpdate.makeDeleteLink(data['id']);
74                }
75           }
76
77           ni = ni+"</div>"+
78                "</li>";
79           return ni;
80      },
81
82      makeFavoriteForm: function(id, session_key)
83      {
84           var ff;
85
86           ff = "<form id=\"favor-"+id+"\" class=\"form_favor\" method=\"post\" action=\""+RealtimeUpdate._favorurl+"\">"+
87                 "<fieldset>"+
88                "<legend>Favor this notice</legend>"+
89                "<input name=\"token-"+id+"\" type=\"hidden\" id=\"token-"+id+"\" value=\""+session_key+"\"/>"+
90                "<input name=\"notice\" type=\"hidden\" id=\"notice-n"+id+"\" value=\""+id+"\"/>"+
91                "<input type=\"submit\" id=\"favor-submit-"+id+"\" name=\"favor-submit-"+id+"\" class=\"submit\" value=\"Favor\" title=\"Favor this notice\"/>"+
92                 "</fieldset>"+
93                "</form>";
94           return ff;
95      },
96
97      makeReplyLink: function(id, nickname)
98      {
99           var rl;
100           rl = "<a class=\"notice_reply\" href=\""+RealtimeUpdate._replyurl+"?replyto="+nickname+"\" title=\"Reply to this notice\">Reply <span class=\"notice_id\">"+id+"</span></a>";
101           return rl;
102         },
103
104      makeDeleteLink: function(id)
105      {
106           var dl, delurl;
107           delurl = RealtimeUpdate._deleteurl.replace("0000000000", id);
108
109           dl = "<a class=\"notice_delete\" href=\""+delurl+"\" title=\"Delete this notice\">Delete</a>";
110
111           return dl;
112      },
113
114      addPopup: function(url, timeline, iconurl)
115      {
116          $('#content').prepend('<button id="realtime_timeline" title="Realtime window">Realtime</button>');
117  
118          $('#realtime_timeline').css({
119              'margin':'0 0 18px 0',
120              'background':'transparent url('+ iconurl + ') no-repeat 0% 30%',
121              'padding':'0 0 0 20px',
122              'display':'block',
123              'float':'right',
124              'border':'none',
125              'cursor':'pointer',
126              'color':$("a").css("color"),
127              'font-weight':'bold',
128              'font-size':'1em'
129          });
130  
131          $('#realtime_timeline').click(function() {
132              window.open(url,
133                          timeline,
134                          'toolbar=no,resizable=yes,scrollbars=yes,status=yes');
135  
136              return false;
137          });
138      },
139
140      initPopupWindow: function()
141      {
142          window.resizeTo(575, 640);
143          $('address').hide();
144          $('#content').css({'width':'92%'});
145      }
146 }
147