-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
83 lines (69 loc) · 2.52 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>iTunes Previewer</title>
<script src="jquery-1.11.3.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
$("#clearButton").click(function() {
$("ul").empty();
})
$("#searchButton").click(function() {
// console.log( "clicks!" );
var value = $("#searchQuery").val();
console.log(value);
$.ajax({
url: 'https://itunes.apple.com/search?term=' + value,
dataType: 'jsonp',
success: function(data){
// do whatever you want with the data you get back from the API
console.log(data)
var newArray = [];
var anotherArray = [];
var resultsArray = data.results;
var audioArray = [];
// Get each track name, artworkURL and its previewURL then store it
// into new arrays
for (var i=0; i<resultsArray.length; i++){
var track = resultsArray[i].trackName;
var artwork = resultsArray[i].artworkUrl100;
var audioP = resultsArray[i].previewUrl;
newArray.push(track);
anotherArray.push(artwork);
audioArray.push(audioP);
}
console.log(newArray);
console.log(anotherArray);
var newHTML = [];
// Creates list of elements we want to list on the view
$.each(newArray, function(index, value) {
// Audio tag/element is used to embed audio into the document
// Some browsers do NOT support audio element
newHTML.push('<hr><li> <br><img src=' + anotherArray[index]
+ '> <br>' + newArray[index]
+ '</li> <br>' + '<audio controls><source src='
+ audioArray[index] + ' type="audio/mp4" /></audio><br>'
);
console.log(artwork)
});
// append, is very synonymous to push. In short it appends
// .join() joins the items of an array by using its parameter as a separator
// between these list items
$('#list').append( newHTML.join(''));
}
})
})
});
</script>
</head>
<body>
<p>Please input a music artist's name: </p>
<input type="text" id="searchQuery"/>
<input type="submit" id="searchButton" value = "Fetch Tracks"/>
<input type="submit" id="clearButton" value = "Clear"/>
<ul id="list">
</ul>
</body>
</html>