-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
87 lines (77 loc) · 2.57 KB
/
index.html
File metadata and controls
87 lines (77 loc) · 2.57 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
87
<!doctype html>
<html>
<head>
<link rel="icon" href="data:,">
<meta charset="utf-8">
<title>JSON Setlist</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<!--script language="javascript" src="animals.json"></script-->
</head>
<body>
<script language="javascript">
var strHTML = "";
$.get( "https://acbutcher.github.io/songlist.json",
function( data ) {
str = JSON.stringify(data);
$("#raw_string").html(str +"<br/>");
strHTML = "<ul>";
var genreList = [];
data.forEach(function(song) {
genreString = "";
(song.genres).forEach(function(genre) {
if (!genreList.includes(genre)) genreList.push(genre);
if (genreString != "") genreString = genreString + ", ";
genreString = genreString + genre;
})
strHTML += "<br/>";
strHTML += song.title + "<br/>";
strHTML += "Artist: " + song.artist + "<br/>";
strHTML += "Genres: " + genreString + "<br/>";
strHTML += "Release Year: " + song.year + "<br/>";
})
strHTML += "</ul>";
// console.log(strHTML);
$("#songlist_table").html(strHTML);
makeDropdown(genreList);
})
function makeDropdown(genreList) {
var selectHTML = "<select name = 'genreSelect' id = 'genreSelect'>";
for (i = 0; i < genreList.length; i++) {
selectHTML = selectHTML + "<option>" + genreList[i] + "</option>";
}
selectHTML = selectHTML + "</select>";
$("#select_div").html(selectHTML);
}
function filterByGenre() {
// console.log("Click");
var selectedGenre = $("#genreSelect").val();
// console.log(selectedGenre + "\n");
$.get( "https://acbutcher.github.io/songlist.json",
function( data ) {
strHTML = "<ul>";
data.forEach(function(song) {
if (song.genres.includes(selectedGenre)) {
// console.log(song + "has");
genreString = "";
(song.genres).forEach(function(genre) {
if (genreString != "") genreString = genreString + ", ";
genreString = genreString + genre;
})
strHTML += "<br/>";
strHTML += song.title + "<br/>";
strHTML += "Artist: " + song.artist + "<br/>";
strHTML += "Genres: " + genreString + "<br/>";
strHTML += "Release Year: " + song.year + "<br/>";
}
})
strHTML += "</ul>";
$("#songlist_table").html(strHTML);
})
}
</script>
<div id = "raw_string"></div>
<div id = "songlist_table"></div>
<div id = "select_div"></div>
<button type = "button" onClick = "filterByGenre()">Filter</button>
</body>
</html>