/**
* Pinboard recent bookmarks feed. Modified from:
* Github activity feed.
*
* Graeme Sutherland, July 2012.
*
* Uses .json activity from github to show public commits.
* Requires jQuery and underscore.js
*
*/
var PinboardActivity = (function($, _) {
// {"u":"http://www.h-online.com/developer/news/item/SubGit-1-0-stress-free-Subversion-to-Git-migration-1717931.html","d":"SubGit 1.0: \"stress-free\" Subversion to Git migration - The H Developer: News and Features","n":"RT @_doherty: This could be fun at work: #git #svn","dt":"2012-09-28T23:48:20Z","a":"doy","t":["git","svn"]}
var
self = {},
default_template = '
\
<%= d %> \
<% if (n) { %> \
\
<%= n %> \
<% } %> \
<% if (t.length > 1 || (t.length == 1 && t[0] != "")) { %> \
tags: \
<% _.each(t, function (item) { %> \
<%= item %> \
<% }); %> \
<% } %> \
';
/**
* Fill in activity into selector from public events for username,
* with optional template selector tmpl_selector.
*/
self.show_activity = function (username, selector, tmpl_selector) {
var
url = 'https://feeds.pinboard.in/json/v1/u:' + username + '/?count=5&cb=?',
template = $(tmpl_selector).html() || default_template,
compiled = _.template(template),
current_date = '',
$current_list;
$.getJSON(url, {}, function (data) {
$.each(data, function(index, commit) {
var date = commit.dt.substring(0, 10);
if (date != current_date) {
if (current_date) {
var $new_item = $('');
$new_item.append('' + current_date + '
');
var $div = $('');
$div.append($current_list);
$new_item.append($div);
$(selector).append($new_item);
}
$current_list = $('');
current_date = date;
}
var $action = $(compiled(commit));
if (index % 2) {
$action.addClass('odd')
}
$current_list.append($action);
});
var $new_item = $('');
$new_item.append('' + current_date + '
');
var $div = $('');
$div.append($current_list);
$new_item.append($div);
$(selector).append($new_item);
});
};
return self;
}(jQuery, _));