/* https://github.com/alexcash/jQuery.last.fm */
(function( $ ) {
$.fn.lfm = function(options){
var settings = $.extend({
APIkey: null,
User: null,
Behavior: "hover",
limit: 20,
period: "3month" // overall | 7day | 1month | 3month | 6month | 12month
}, options);
var url = "http://ws.audioscrobbler.com/2.0/?method=user.gettopalbums&user=" + settings.User + "&period=" + settings.period + "&api_key=" + settings.APIkey + "&format=json&limit=" + settings.limit +"&callback=?";
var albums = [];
function isLoaded (albumElement) {
for (var i = 0; i < albums.length; i++){
var markup = $("
" + albums[i].artist + "
" + albums[i].name + "
" + albums[i].played + " tracks played
");
albumElement.append(markup);
}
if (settings.Behavior == "hover") {
albumElement.find('.album').hover(function(){
$(this).addClass('flip');
},function(){
$(this).removeClass('flip');
});
} else {
$(document).bind('click', function (e) {
$('.flip').removeClass('flip');
});
albumElement.find('.album').click(function(e){
e.stopPropagation();
if($('.flip')[0] === this){
$(this).removeClass('flip');
} else {
$('.flip').removeClass('flip');
$(this).addClass('flip');
}
});
}
}
return this.each(function(){
var $this = $(this);
$.getJSON( url, function(data){
$(data.topalbums.album).each(function(){
albums.push ({
name: this.name,
artist: this.artist.name,
played: this.playcount,
art: this.image[this.image.length-1]["#text"]
});
});
isLoaded($this);
});
});
};
})( jQuery );
$('.albums').lfm({
APIkey: "e12ea1d0253898ee9a93edfe42ffdeab",
User: "windhamdavid",
Behavior: "hover",
limit: 100,
period: "3month"
});