]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Comet/updatetimeline.js
55511d35ff08485ba50849981e139549ad831ad2
[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           html = data['html'].replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>');
38
39           ni = "<li class=\"hentry notice\" id=\"notice-"+data['id']+"\">"+
40                "<div class=\"entry-title\">"+
41                "<span class=\"vcard author\">"+
42                "<a href=\""+user['profile_url']+"\" class=\"url\">"+
43                "<img src=\""+user['profile_image_url']+"\" class=\"avatar photo\" width=\"48\" height=\"48\" alt=\""+user['screen_name']+"\"/>"+
44                "<span class=\"nickname fn\">"+user['screen_name']+"</span>"+
45                "</a>"+
46                "</span>"+
47                "<p class=\"entry-content\">"+html+"</p>"+
48                "</div>"+
49                "<div class=\"entry-content\">"+
50                "<dl class=\"timestamp\">"+
51                "<dt>Published</dt>"+
52                "<dd>"+
53                "<a rel=\"bookmark\" href=\""+data['url']+"\" >"+
54                "<abbr class=\"published\" title=\""+data['created_at']+"\">a few seconds ago</abbr>"+
55                "</a> "+
56                "</dd>"+
57                "</dl>"+
58                "<dl class=\"device\">"+
59                "<dt>From</dt> "+
60                "<dd>"+data['source']+"</dd>"+
61                "</dl>"+
62                "</div>"+
63                "<div class=\"notice-options\">"+
64                "</div>"+
65                "</li>";
66           return ni;
67      }
68 }();
69