]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Realtime/realtimeupdate.js
make RealtimePlugin work correctly
[quix0rs-gnu-social.git] / plugins / Realtime / realtimeupdate.js
1 // add a notice encoded as JSON into the current timeline
2 //
3
4 RealtimeUpdate = {
5
6      receive: function(message)
7      {
8           id = data.id;
9
10           // Don't add it if it already exists
11
12           if ($("#notice-"+id).length > 0) {
13                return;
14           }
15
16           var noticeItem = RealtimeUpdate.makeNoticeItem(data);
17           $("#notices_primary .notices").prepend(noticeItem, true);
18           $("#notices_primary .notice:first").css({display:"none"});
19           $("#notices_primary .notice:first").fadeIn(1000);
20           NoticeHover();
21           NoticeReply();
22      }
23
24      makeNoticeItem: function(data)
25      {
26           user = data['user'];
27           html = data['html'].replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&quot;/g,'"');
28           source = data['source'].replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&quot;/g,'"');
29
30           ni = "<li class=\"hentry notice\" id=\"notice-"+data['id']+"\">"+
31                "<div class=\"entry-title\">"+
32                "<span class=\"vcard author\">"+
33                "<a href=\""+user['profile_url']+"\" class=\"url\">"+
34                "<img src=\""+user['profile_image_url']+"\" class=\"avatar photo\" width=\"48\" height=\"48\" alt=\""+user['screen_name']+"\"/>"+
35                "<span class=\"nickname fn\">"+user['screen_name']+"</span>"+
36                "</a>"+
37                "</span>"+
38                "<p class=\"entry-content\">"+html+"</p>"+
39                "</div>"+
40                "<div class=\"entry-content\">"+
41                "<dl class=\"timestamp\">"+
42                "<dt>Published</dt>"+
43                "<dd>"+
44                "<a rel=\"bookmark\" href=\""+data['url']+"\" >"+
45                "<abbr class=\"published\" title=\""+data['created_at']+"\">a few seconds ago</abbr>"+
46                "</a> "+
47                "</dd>"+
48                "</dl>"+
49                "<dl class=\"device\">"+
50                "<dt>From</dt> "+
51                "<dd>"+source+"</dd>"+ // may have a link, I think
52                "</dl>";
53
54           if (data['in_reply_to_status_id']) {
55                ni = ni+" <dl class=\"response\">"+
56                     "<dt>To</dt>"+
57                     "<dd>"+
58                     "<a href=\""+data['in_reply_to_status_url']+"\" rel=\"in-reply-to\">in reply to</a>"+
59                     "</dd>"+
60                     "</dl>";
61           }
62
63           ni = ni+"</div>"+
64                "<div class=\"notice-options\">";
65
66           if (_userid != 0) {
67                var input = $("form#form_notice fieldset input#token");
68                var session_key = input.val();
69                ni = ni+RealtimeUpdate.makeFavoriteForm(data['id'], session_key);
70                ni = ni+RealtimeUpdate.makeReplyLink(data['id'], data['user']['screen_name']);
71                if (_userid == data['user']['id']) {
72                     ni = ni+RealtimeUpdate.makeDeleteLink(data['id']);
73                }
74           }
75
76           ni = ni+"</div>"+
77                "</li>";
78           return ni;
79      }
80
81      makeFavoriteForm: function(id, session_key)
82      {
83           var ff;
84
85           ff = "<form id=\"favor-"+id+"\" class=\"form_favor\" method=\"post\" action=\""+_favorurl+"\">"+
86                "<fieldset>"+
87                "<legend>Favor this notice</legend>"+ // XXX: i18n
88                "<input name=\"token-"+id+"\" type=\"hidden\" id=\"token-"+id+"\" value=\""+session_key+"\"/>"+
89                "<input name=\"notice\" type=\"hidden\" id=\"notice-n"+id+"\" value=\""+id+"\"/>"+
90                "<input type=\"submit\" id=\"favor-submit-"+id+"\" name=\"favor-submit-"+id+"\" class=\"submit\" value=\"Favor\" title=\"Favor this notice\"/>"+
91                "</fieldset>"+
92                "</form>";
93           return ff;
94      }
95
96      makeReplyLink: function(id, nickname)
97      {
98           var rl;
99           rl = "<dl class=\"notice_reply\">"+
100                "<dt>Reply to this notice</dt>"+
101                "<dd>"+
102                "<a href=\""+_replyurl+"?replyto="+nickname+"\" title=\"Reply to this notice\">Reply <span class=\"notice_id\">"+id+"</span>"+
103                "</a>"+
104                "</dd>"+
105                "</dl>";
106           return rl;
107      }
108
109      makeDeleteLink: function(id)
110      {
111           var dl, delurl;
112           delurl = _deleteurl.replace("0000000000", id);
113
114           dl = "<dl class=\"notice_delete\">"+
115                "<dt>Delete this notice</dt>"+
116                "<dd>"+
117                "<a href=\""+delurl+"\" title=\"Delete this notice\">Delete</a>"+
118                "</dd>"+
119                "</dl>";
120
121           return dl;
122      }
123 };
124