Skip to content

Instantly share code, notes, and snippets.

@djacobs djacobs/gist:383542 forked from btrott/gist:383188
Created Apr 29, 2010

Embed
What would you like to do?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Activity widget</title>
</head>
<body>
<ul id="note-list"></ul>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="mustache.js"></script>
<script>
var assetId = '6a00d83451c82369e2013480356a71970c';
var data = [];
var allLoaded = 0;
var ul = $( '#note-list' );
var templates = {
reblog: '<li><a href="{{profilePageUrl}}"><img class="avatar" src="{{avatarUrl}}" alt="{{displayName}}" /></a><span class="action"><a href="{{profilePageUrl}}" title="{{displayName}}">{{displayName}}</a> reblogged this</li>',
favorite: '<li><a href="{{profilePageUrl}}"><img class="avatar" src="{{avatarUrl}}" alt="{{displayName}}" /></a><span class="action"><a href="{{profilePageUrl}}" title="{{displayName}}">{{displayName}}</a> liked this</li>',
comment: '<li><a href="{{profilePageUrl}}"><img class="avatar" src="{{avatarUrl}}" alt="{{displayName}}" /></a><span class="action"><a href="{{profilePageUrl}}" title="{{displayName}}">{{displayName}}</a> replied: {{commentText}}</li>'
};
$( document ).ready( function() {
$.each( [ 'favorites', 'reblogs', 'comments' ], function( index, meth ) {
$.getJSON(
'http://api.typepad.com/assets/' + assetId + '/' + meth + '.js?callback=?',
{ 'max-results': 50 },
function( res ) {
$.each( res.entries, function( index, entry ) {
data.push( entry );
} );
if ( ++allLoaded == 3 ) {
loaded();
}
}
);
} );
} );
function loaded () {
data.sort( function( a, b ) {
return ( a.published < b.published ) ? -1 : ( a.published > b.published ) ? 1 : 0;
} );
$.each( data, function( index, val ) {
var view, template;
console.log( val );
if ( val.objectTypes == undefined ) {
// Favorite
template = templates.favorite;
view = {
profilePageUrl: val.author.profilePageUrl,
displayName: val.author.displayName,
avatarUrl: val.author.avatarLink.urlTemplate.replace( '{spec}', '20si' )
}
} else if ( val.objectTypes[0].match( /Comment/ ) ) {
// Comment
template = templates.comment;
view = {
profilePageUrl: val.author.profilePageUrl,
displayName: val.author.displayName,
avatarUrl: val.author.avatarLink.urlTemplate.replace( '{spec}', '20si' ),
commentText: val.content
};
} else {
// Reblog
template = templates.reblog;
view = {
profilePageUrl: val.author.profilePageUrl,
displayName: val.author.displayName,
avatarUrl: val.author.avatarLink.urlTemplate.replace( '{spec}', '20si' )
};
}
ul.append( Mustache.to_html( template, view ) );
} );
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.