summaryrefslogtreecommitdiff
path: root/plugins/Comet/updatetimeline.js
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-04-26 15:42:07 -0400
committerEvan Prodromou <evan@controlyourself.ca>2009-04-26 15:42:07 -0400
commitdf677cb9c123b58100f677141ab46ddea55a2415 (patch)
tree29c3df03c701c404639f15f42bc560107f34cf9d /plugins/Comet/updatetimeline.js
parent068f6801cc59488bfc50ef399a2a4d22b1b7e9c2 (diff)
parent781341d91fd4c7406d8687e7828ab86f9696cf66 (diff)
Merge branch 'cometplugin' into 0.7.x
Diffstat (limited to 'plugins/Comet/updatetimeline.js')
-rw-r--r--plugins/Comet/updatetimeline.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/plugins/Comet/updatetimeline.js b/plugins/Comet/updatetimeline.js
new file mode 100644
index 000000000..c6eefb447
--- /dev/null
+++ b/plugins/Comet/updatetimeline.js
@@ -0,0 +1,67 @@
+// update the local timeline from a Comet server
+//
+
+var updater = function()
+{
+ var _cometd;
+
+ return {
+ init: function(server, timeline)
+ {
+ _cometd = $.cometd; // Uses the default Comet object
+ _cometd.setLogLevel('debug');
+ _cometd.init(server);
+ _cometd.subscribe(timeline, receive);
+ $(window).unload(leave);
+ }
+ }
+
+ function leave()
+ {
+ _cometd.disconnect();
+ }
+
+ function receive(message)
+ {
+ var noticeItem = makeNoticeItem(message.data);
+ $("#notices_primary .notices").prepend(noticeItem, true);
+ $("#notices_primary .notice:first").css({display:"none"});
+ $("#notices_primary .notice:first").fadeIn(2500);
+ NoticeHover();
+ NoticeReply();
+ }
+
+ function makeNoticeItem(data)
+ {
+ user = data['user'];
+ ni = "<li class=\"hentry notice\" id=\"notice-"+data['id']+"\">"+
+ "<div class=\"entry-title\">"+
+ "<span class=\"vcard author\">"+
+ "<a href=\""+user['profile_url']+"\" class=\"url\">"+
+ "<img src=\""+user['profile_image_url']+"\" class=\"avatar photo\" width=\"48\" height=\"48\" alt=\""+user['screen_name']+"\"/>"+
+ "<span class=\"nickname fn\">"+user['screen_name']+"</span>"+
+ "</a>"+
+ "</span>"+
+ "<p class=\"entry-content\">"+data['text']+"</p>"+
+ "</div>"+
+ "<div class=\"entry-content\">"+
+ "<dl class=\"timestamp\">"+
+ "<dt>Published</dt>"+
+ "<dd>"+
+ "<a rel=\"bookmark\" href=\""+data['url']+"\" >"+
+ "<abbr class=\"published\" title=\""+data['created_at']+"\">a few seconds ago</abbr>"+
+ "</a> "+
+ "</dd>"+
+ "</dl>"+
+ "<dl class=\"device\">"+
+ "<dt>From</dt> "+
+ "<dd>"+data['source']+"</dd>"+
+ "</dl>"+
+ "</div>"+
+ "<div class=\"notice-options\">"+
+ "</div>"+
+ "</li>";
+ return ni;
+ }
+}();
+