-
Notifications
You must be signed in to change notification settings - Fork 1
/
dir_rg-random-cover.js
40 lines (33 loc) · 1.22 KB
/
dir_rg-random-cover.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var app = angular.module('recordGrader');
var rrs = require('random-record-sleeve');
rrs.setCredentials('CXDjOnwBOBrUIPVjpbMh', 'NyFFxQoZSxbmiqWQYwZTKDGQQMJwuUtX');
app.directive('rgRandomCover', ['$http', function($http) {
return {
restrict: 'A',
scope: {
discogsCredentials: '=',
discogsListId: '=?',
fallback: '=?'
},
link: function($scope, $elem, $attr) {
if($elem[0].nodeName !== 'IMG') throw new Error('This directive can only be used on a <img> tag.');
var FALLBACK_URI = 'dj_krush_milight.jpg';
var FALLBACK_TITLE = 'MiLight (1996)';
$scope.discogsListId = $scope.discogsListId || 2056; // Defaults to "Most Popular Albums" list
function updateImage(src, title, alt) {
if(!src) throw new Error('Empty source.');
$elem.attr('src', src);
if(title) $elem.attr('title', title);
if(alt) $elem.attr('alt', alt);
}
var sleeve = rrs.getSleeve({
size150: true
}).then(function(res) {
updateImage(res.url, res.title+' ('+res.year+')');
}).catch(function(err) {
console.log('••• err', err);
});
//updateImage(sleeve, res.data.title+' ('+res.data.year+')');
}
}
}]);