Permalink
Browse files

Disqus support

Config:
* to get your user_id (quickly): go to disqus.com, log in, open the
developer console and type: `context.auth.user_id`
* you need to create and app and add the public key as an setting

User user_id = 1 for demo (this is the one hinted at in the
documentation).
  • Loading branch information...
1 parent 096021f commit e8ce5d947f5b1751e98d5d49bfcc4af41349508c @arminrosu committed Dec 30, 2012
Showing with 63 additions and 0 deletions.
  1. +1 −0 css/lifestream.css
  2. BIN src/favicons/disqus.png
  3. +62 −0 src/services/disqus.js
View
Oops, something went wrong.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,62 @@
+(function($) {
+$.fn.lifestream.feeds.disqus = function( config, callback ) {
+
+ var template = $.extend({},
+ {
+ post: 'commented on <a href="${url}">${thread.title}</a>',
+ thread_like: 'liked <a href="${url}">${thread.title}</a>'
+ },
+ config.template),
+
+ parseDisqus = function( input ) {
+ var output = [], i = 0, j, item;
+
+ if(input) {
+ j = input.length;
+ for( ; i<j; i++) {
+ item = input[i];
+
+ // replies to your comments are included by default
+ if (item.type !== 'reply') {
+ output.push({
+ date: new Date( item.createdAt ),
+ config: config,
+ html: $.tmpl( template[item.type], item.object )
+ });
+ }
+ }
+ }
+
+ return output;
+ };
+
+ $.ajax({
+ url: "https://disqus.com/api/3.0/users/listActivity.json",
+ data: {
+ user: config.user,
+ api_key: config.key
+ },
+ dataType: 'jsonp',
+ success: function( data ) {
+ if (data.code === 2) {
+ callback([]);
+
+ // log error to console if not on IE
+ if (console && console.error) {
+ console.error('Error loading Disqus stream.', data.response);
+ }
+ return;
+ } else {
+ callback(parseDisqus(data.response));
+ }
+ }
+ });
+
+ // Expose the template.
+ // We use this to check which templates are available
+ return {
+ "template" : template
+ };
+
+};
+})(jQuery);

0 comments on commit e8ce5d9

Please sign in to comment.