-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspotapi.html
More file actions
153 lines (133 loc) · 4.12 KB
/
spotapi.html
File metadata and controls
153 lines (133 loc) · 4.12 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<html>
<head>
<title>Dan Meehan</title>
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/css/materialize.min.css">
<link href="css/style.css" rel="stylesheet">
<style>
/* input color */
.input-field input[type=text] {
border-bottom: 1px solid #35394B;
box-shadow: none;
}
/* label color */
.input-field label, label {
color: #35394B;
}
/* label focus color */
.input-field input[type=text]:focus + label {
color: #CEE0E2;
}
/* input underline focus color */
.input-field input[type=text]:focus {
border-bottom: 1px solid #CEE0E2;
box-shadow: 0 1px 0 0 #CEE0E2;
}
/* radio button not selected */
[type=radio]:not(:checked)+label:before,
[type=radio]:not(:checked)+label:after {
border: 2px solid #35394B;
border-radius: 50%;
}
/* radio button selected */
[type=radio]:checked+label:before,
[type=radio]:checked+label:after {
border: 2px solid transparent;
border-radius: 50%;
background-color: #CEE0E2;
}
/* radio label selected */
[type=radio]:checked+label {
color: #CEE0E2;
}
</style>
</head>
<body class="charcoal white-text">
<nav class="sweet-brown">
<div class="nav-wrapper">
<ul>
<li><a href="/#">Home</a></li>
<li><a href="/#work">Work</a></li>
<li><a href="/#school">School</a></li>
<li><a href="/#projects">Projects</a></li>
</ul>
</div>
</nav>
<div class="container">
<div class="row">
<h2>SpotAPI</h2>
</div>
<div class="row">
<div class="custom-card sweet-brown">
<div class="row">
<div class="input-field col s12 m6">
<input type="text" id="search-text" class="columbia-blue-text" />
<label for="search-text">Search Query</label>
</div>
<div class="col s12 m6 l3">
<p>
<input id="radio-artist" type="radio" name="type" value="artist" />
<label for="radio-artist">Artist</label>
</p>
<p>
<input id="radio-album" type="radio" name="type" value="album" />
<label for="radio-album">Album</label>
</p>
</div>
<div class="col s12 l3 center">
<br>
<button id="search" class="btn-large burly-wood charcoal-text hoverable">Search</button>
</div>
<div class="col s12">
<ul id="search-results" class="collection quick-silver charcoal-text"></ul>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/js/materialize.min.js"></script>
<script src="js/SpotAPI.js"></script>
<script type="text/javascript">
var spot = new Spotify();
var appendItem = function(item) {
var entry = '';
if (item['images'].length > 0) {
entry = '<li class="collection-item quick-silver avatar"><img class="circle" src="' + item['images'][0]['url'] + '" /><span class="title">' + item['name'] + '</span>';
} else {
entry = '<li class="collection-item quick-silver"><span class="title">' + item['name'] + '</span>';
}
if (item['artists'] && item['artists'].length > 0) {
entry += '<p class="thin">' + item['artists'][0]['name'] + '</p>';
} else if (item['genres'] && item['genres'].length > 0) {
entry += '<p class="thin">' + item['genres'][0] + '</p>';
}
entry += '</li>';
$('#search-results').append(entry);
}
$('#search').on('click', function(e) {
if ($('#search-text').val() === '') return;
if ($('#radio-album').prop('checked')) {
spot.searchAlbum($('#search-text').val(), function(res) {
var result = res['albums']['items'];
$('#search-results').html('');
for (var i = 0; i < result.length; i++) {
var id = result[i]['id'];
spot.getAlbum(id, function(res) {
appendItem(res);
});
}
});
} else {
spot.searchArtist($('#search-text').val(), function(res) {
var result = res['artists']['items'];
$('#search-results').html('');
for (var i = 0; i < result.length; i++) {
appendItem(result[i]);
}
});
}
});
</script>
</body>
</html>