-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
86 lines (74 loc) · 2.14 KB
/
index.html
File metadata and controls
86 lines (74 loc) · 2.14 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<html>
<head>
<title>7Digital API JSON/Jquery example</title>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
GetNewRandom();
$("#randomLink").click(GetNewRandom);
});
function GetNewRandom() {
$.ajax({
url: "randomiser.php",
dataType: "json",
type: "GET",
cache: false,
error: function(XMLHttpRequest, textStatus, errorThrown){
alert(errorThrown);
},
success: function(result) {
if(result.response === undefined) {
console.log(result);
return GetNewRandom();
}
if(result.response.track === undefined) {
OutputMultipleTrack(result)
} else {
OutputSingleTrack(result)
}
}
});
}
function OutputMultipleTrack(result) {
$.each(result.response.tracks.track, function(i,track){
trackImage = $("<img/>").attr("src", track.release.image);
linkPlaceHolder = $("<a/>").attr("href", track.url)
.html(track.title)
.prepend(trackImage);
$("#output").html(linkPlaceHolder)
});
}
function OutputSingleTrack(result) {
track = result.response.track;
bigTrack = track.release.image.replace("_50", "_350"); // HACKd
$("h1#artistTitle").html(track.artist.name);
$("h2#albumTitle").html(track.release.title);
$("img#albumCover").attr("src", bigTrack);
$("a#trackLink").attr("href", track.url).html(track.title);
trackId = track["@attributes"].id;
previewUrl = BuildPreview(34, trackId);
}
function BuildPreview(countryId, trackId) {
previewUrl = "http://previews.7digital.com/clips/" + countryId + "/" + trackId + ".clip.mp3";
return previewUrl;
}
</script>
</head>
<body>
<table width="100%">
<tr>
<td align="center">
<div id="output">
<h1 id="artistTitle"></h1>
<h2 id="albumTitle"></h2>
<div id="imagePlaceHolder" style="height:350px"><img id="albumCover" /></div><br />
<a id="trackLink"></a>
</div>
</td>
<tr>
<td align="center"><button id="randomLink" style="display:block">Rrrrrrrrandomise!</button></td>
</tr>
</tr>
</table>
</body>
</html>