Skip to content
Browse files

Add: Abstract away the lookup operation

  • Loading branch information...
1 parent dec4c94 commit 884b207c0a06c5c8c884af98bf09b34f05945ff3 @divarvel committed Apr 20, 2012
Showing with 11 additions and 6 deletions.
  1. +11 −6 public/js/script.js
View
17 public/js/script.js
@@ -129,17 +129,22 @@ var searchfor = function(qq, pagenum) {
});
};
-var showAlbum = function(albumURI) {
- $('#result').empty();
- $('h3').text("Chargement");
+var performLookup = function(uri, extras, callback) {
$.ajax({
url: "http://ws.spotify.com/lookup/1/.json",
data: {
- 'uri': albumURI,
- 'extras': 'track'
+ 'uri': uri,
+ 'extras': extras.join(",")
},
dataType: 'json'
- }).done(function(data) {
+ }).done(callback);
+};
+
+var showAlbum = function(albumURI) {
+ $('#result').empty();
+ $('.pagination').empty();
+ $('h3').text("Chargement");
+ performLookup(albumURI, ['track'], function(data) {
$('h3').text(data.album.artist +' - '+ data.album.name);
var trackList = _.map(data.album.tracks, function(t) { return '<tr><td>' + t.name + '</td></tr>';});
$(trackList.join("")).appendTo('#result');

0 comments on commit 884b207

Please sign in to comment.
Something went wrong with that request. Please try again.