Domanda

Sto cercando di personalizzare questo script in modo che invece di recenti tracce di un utente che visualizzerà artisti preferiti di un utente.

Questo è quello che sono venuto su con, tuttavia non funziona sorta. Ho pensato che sarebbe stato facile cambiare gli attributi del mangime, ma ovviamente non ...

(function($){
$.fn.lastFM = function(options) {

var defaults = {
number: 10,
username: 'willblackmore',
apikey: '96e0589327a3f120074f74dbc8ec6443',
artSize: 'medium',
noart: 'images/noartwork.gif',
onComplete: function(){}
},
settings = $.extend({}, defaults, options);



var lastUrl = 'http://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user='+settings.username+'&api_key='+settings.apikey+'+'&limit='+settings.number+'&format=json&callback=?';
var $this = $(this);

var container = $this.html();

$this.children(':first').remove();

if(settings.artSize == 'small'){imgSize = 0}
if(settings.artSize == 'medium'){imgSize = 1}
if(settings.artSize == 'large'){imgSize = 2}

this.each(function() {

$.getJSON(lastUrl, function(data){ 
 $.each(data.topartists.artist, function(i, item){

 if(item.image[1]['#text'] == ''){
  art = settings.noart;
 }else{
  art = stripslashes(item.image[imgSize]['#text']);
 }

 url = stripslashes(item.url);
 song = item.name;
 artist = item.playcount['#text'];
 album = item.streamable['#text'];

 $this.append(container);

 var $current = $this.children(':eq('+i+')');

 $current.find('[class=lfm_song]').append(song);
 $current.find('[class=lfm_artist]').append(artist);
 $current.find('[class=lfm_album]').append(album);
 $current.find('[class=lfm_art]').append("<img src='"+art+"' alt='Artwork for "+album+"'/>");
 $current.find('a').attr('href', url).attr('title', 'Listen to '+song+' on Last.FM').attr('target', '_blank');

 //callback
 if(i==(settings.number-1)){
  settings.onComplete.call(this);
 }

  });
 });
});
};

 //Clean up the URL's
 function stripslashes( str ) {  
return (str+'').replace(/\0/g, '0').replace(/\\([\\'"])/g, '$1');
}
})(jQuery);`

Tutte le idee? Grazie.

È stato utile?

Soluzione

Hai concencated l'URL sbagliato. Questo è valido:

var lastUrl = 'http://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=' + settings.username + '&api_key=' + settings.apikey + '&limit=' + settings.number + '&format=json&callback=?';

Non sono sicuro che si risolve il problema in quanto non ha fornito dettagli sufficienti (errori, ecc).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top