]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Comet/updatetimeline.js
add live updating for tag pages
[quix0rs-gnu-social.git] / plugins / Comet / updatetimeline.js
1 // update the local timeline from a Comet server
2 //
3
4 var updater = function()
5 {
6      var _cometd;
7
8      return {
9           init: function(server, timeline)
10           {
11                _cometd = $.cometd; // Uses the default Comet object
12                _cometd.setLogLevel('debug');
13                _cometd.init(server);
14                _cometd.subscribe(timeline, receive);
15                $(window).unload(leave);
16           }
17      }
18
19      function leave()
20      {
21           _cometd.disconnect();
22      }
23
24      function receive(message)
25      {
26           var noticeItem = makeNoticeItem(message.data);
27           $("#notices_primary .notices").prepend(noticeItem, true);
28           $("#notices_primary .notice:first").css({display:"none"});
29           $("#notices_primary .notice:first").fadeIn(2500);
30           NoticeHover();
31           NoticeReply();
32      }
33
34      function makeNoticeItem(data)
35      {
36           user = data['user'];
37           ni = "<li class=\"hentry notice\" id=\"notice-"+data['id']+"\">"+
38                "<div class=\"entry-title\">"+
39                "<span class=\"vcard author\">"+
40                "<a href=\""+user['profile_url']+"\" class=\"url\">"+
41                "<img src=\""+user['profile_image_url']+"\" class=\"avatar photo\" width=\"48\" height=\"48\" alt=\""+user['screen_name']+"\"/>"+
42                "<span class=\"nickname fn\">"+user['screen_name']+"</span>"+
43                "</a>"+
44                "</span>"+
45                "<p class=\"entry-content\">"+data['text']+"</p>"+
46                "</div>"+
47                "<div class=\"entry-content\">"+
48                "<dl class=\"timestamp\">"+
49                "<dt>Published</dt>"+
50                "<dd>"+
51                "<a rel=\"bookmark\" href=\""+data['url']+"\" >"+
52                "<abbr class=\"published\" title=\""+data['created_at']+"\">a few seconds ago</abbr>"+
53                "</a> "+
54                "</dd>"+
55                "</dl>"+
56                "<dl class=\"device\">"+
57                "<dt>From</dt> "+
58                "<dd>"+data['source']+"</dd>"+
59                "</dl>"+
60                "</div>"+
61                "<div class=\"notice-options\">"+
62                "</div>"+
63                "</li>";
64           return ni;
65      }
66 }();
67