123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- /* 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 = $("<div class='album'><div class='front'><img src='" + albums[i].art + "'><div class='alpha'></div></div><div class='back'><h2>" + albums[i].artist + "</h2><h1>" + albums[i].name + "</h1><h3>" + albums[i].played + " tracks played</h3></div></div>");
- 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"
- });
|