-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA8MiTunes.htm
More file actions
333 lines (291 loc) · 9.21 KB
/
A8MiTunes.htm
File metadata and controls
333 lines (291 loc) · 9.21 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<!--Assignment: MiTunes
Author: Jakub Holewik
ID: B615637
Login: cojrh2-->
<!DOCTYPE html>
<html>
<head>
<title>MiTunes</title>
<style type="text/css">
*
{
box-sizing: content-box; /*change everything to content-box, makes it easier to work on in my opinion*/
}
body
{
background-color: #272727;
}
#tabs /*div containing the 3 main tabs*/
{
margin-bottom: 7px;
text-align: center;
}
.display /*class for the main tabs*/
{
display: inline-block; /*makes the all stay on one line*/
overflow: auto; /*if there is too much conent, a scrollbar will appear*/
height: 400px;
width: 350px;
text-align: left;
background-color: #000000;
border: 3px solid #3CB371;
font-family: Rockwell, Verdana, sans-serif; /*LOVE the sans-serif fonts!*/
font-size: 18px;
color: #FFFFFF;
}
.songdata p /*special rules for text in the third tab*/
{
margin: 12px 0;
text-align: center;
}
img, audio
{
display: block;
margin: 0 auto;
max-width: 250px;
max-height: 250px;
}
#lyrics /*lyrics displayed at the bottom of the third tab*/
{
text-align: justify;
font-size: 15px;
font-style: italic;
}
.choice /*the divs containing listed elements: albums and tracks*/
{
margin: 12px 0;
font-size: 22px;
}
.choice:hover
{
background-color: #696969;
cursor: pointer;
}
.found /*highlights the found keyword when searching*/
{
background-color: #FF0000;
}
.quote /*I wanted the displayed lyrics to be smaller than the tile and album */
{
font-size: 20px;
}
#keyboard /*bottom tab with the keys*/
{
margin: auto;
height: 270px;
width: 560px;
line-height: 30px;
text-align: center;
background-color: #000000;
border: 5px solid #3CB371;
border-radius: 10%;
}
#search_bar /*textbox on top of the keyboard*/
{
margin-top: 10px;
margin-bottom: 8px;
height: 35px;
width: 180px;
text-align: center;
background-color: #696969;
border-width: 0;
font-family: Helvetica, sans-serif;
font-size: 25px;
color: #FFFFFF;
cursor: pointer;
}
.key /*keys that make the keyboard*/
{
display: inline-block;
margin: 4px;
padding: 3px;
height: 32px;
width: 35px;
border: 3px solid #3CB371;
border-radius: 20%; /*rounded edges for the win*/
font-family: Calibri, sans-serif;
font-size: 40px;
color: #FFFFFF;
}
.key:hover
{
background-color: #696969;
cursor: pointer;
}
.big /*the bottom row keys are bigger*/
{
width: 150px;
}
</style>
<script type="text/javascript" src="music.js"></script>
<script type="text/javascript">
function generateSongData(album_id, song_id)
{
//This function generates a song tab, whenever a new song is selected
var alb = albums[album_id];
var track = alb.tracks[song_id];
//Construct path to the sound file, without extension
var path = "audio/" + alb.artist + "/" + alb.title + "/" + track.mp3.substring(0, track.mp3.length - 4);
var code = "<img src='artwork/" + alb.artwork + ".jpg' />" +
"<p>" + alb.artist + "<br />" + alb.title + "</p>" +
"<p>Track " + (song_id + 1) + "/" + alb.tracks.length + "<br />" + track.title + "</p>" + //song_id + 1 because we want to count from 1 not from 0
"<audio controls='controls'>" +
"<source src='" + path +".mp3' type='audio/mpeg'>" +
"<source src='" + path +".wav' type='audio/wav'>" +
"Your browser does not support the audio element.</audio>" +
"<p>Lyrics:<br />" +
"<span id='lyrics'>" + track.lyrics + "</span></p>";
current_track.innerHTML = code;
}
function generateTrackList(album_id)
{
//This function generates code for the track list, whenever a new album is chosen
var alb = albums[album_id];
var code = alb.title + "<br />by " + alb.artist;
for(var i in alb.tracks)
{
//After clicking the chosen song, it will call a function that fills the third tab
code += "<div class='choice' onclick='generateSongData(" + album_id + ", " + i + ");'>" + alb.tracks[i].title + "</div>";
}
track_list.innerHTML = code;
}
function generateAlbumList()
{
//This function generates code for the album list
var code = "Albums:<br /><br />";
for(var i in albums)
{
//After clicking the chosen album, it will call a function that fills the second tab
code += "<div class='choice' onclick='generateTrackList(" + i + ");'>" + albums[i].artist + "/" + albums[i].title + "</div>";
}
album_list.innerHTML = code;
}
function search()
{
//This function will output the found contents in track list, whenever contents of search bar change
var s = search_bar.value;
code = "";
if(s == "")
{
code = "No album selected";
}
else
{
for(var i in albums)
{
var alb = albums[i];
for(var k in alb.tracks)
{
var track = alb.tracks[k];
var low_title = track.title.toLowerCase();
var low_lyrics = track.lyrics.toLowerCase();
var in_title = false; //Has the keyword been found in the title?
var in_lyrics = false; //Has the keyword been found in the lyrics?
var ti = low_title.indexOf(s); //position in title
if(ti != -1) in_title = true;
var li = low_lyrics.indexOf(s); //position in lyrics
if(li != -1) in_lyrics = true;
if(in_title || in_lyrics)
{
code += "<p class='choice' onclick='generateSongData(" + i + ", " + k + ");'>";
if(in_title)
{
//The spans of class "found" represent the highlighted text that matches the keyword
code += track.title.substring(0, ti) +
"<span class='found'>" + track.title.substring(ti, ti + s.length) + "</span>" +
track.title.substring(ti + s.length, track.title.length);
}
else
{
code += track.title;
}
code += "<br />" + alb.artist + ", " + alb.title;
if(in_lyrics)
{
code += "<br /><span class='quote'>";
//Position at which we start displaying lyrics
var start = track.lyrics.lastIndexOf(" ", li - 5); //I chose 5 as the minimal number of characters to display before and after the found keyword
if(start == -1) start = 0;
else start++; //Add one so that we don't display the space
var end = track.lyrics.indexOf(" ", li + s.length + 5);
if(end == -1) end = track.lyrics.length;
if(start != 0) code += "..."; //Start the quote with dots if not going from the beginning
code += track.lyrics.substring(start, li) +
"<span class='found'>" + track.lyrics.substring(li, li + s.length) + "</span>" +
track.lyrics.substring(li + s.length, end);
if(end != track.lyrics.length) code += "..."; //End the quotes with dots if not going until the end
code += "</span>";
}
code += "</p>";
}
}
}
if(code == "")
{
code = "No matches found.";
}
}
track_list.innerHTML = code;
}
function deleteLetter()
{
//This function deletes the last letter of the search bar
search_bar.value = search_bar.value.substring(0, search_bar.value.length - 1);
search();
}
function insertLetter(c)
{
//This function inserts value of the clicked button into the search bar
search_bar.value += c.toLowerCase();
search();
}
function resetSearchBar()
{
//This function deletes all letters from the search bar
search_bar.value = "";
search();
}
function generateKeyboard()
{
//This function generates code for the keyboard used in the 'keyboard' div
//List of all keys in a qwerty keyboard, grouped in three rows
var qwerty = [ "QWERTYUIOP", "ASDFGHJKL", "ZXCVBNM" ];
//First, make the textbox
//Readonly, because w don't support normal keyboard input
//The onfocus function eliminates the text cursor that appears when clicking the text
//Clickig on this textbox returns the user to search results
var code = "<form><input type='text' id='search_bar' onclick='search();' onfocus='this.blur();'' readonly></form>";
//Constructing the letter buttons
for(var i in qwerty)
{
code += "<div>";
for(var k = 0; k < qwerty[i].length; k++)
{
code += "<div class='key' onclick='insertLetter(this.innerHTML);'>" + qwerty[i][k] + "</div>";
}
code += "</div>";
}
//Additional buttons on the final row
code += "<div><div class='key big' onclick='insertLetter(\" \");'>SPACE</div>";
code += "<div class='key big' onclick='deleteLetter();'>BACK</div>";
code += "<div class='key big' onclick='resetSearchBar();'>RESET</div></div>";
keyboard.innerHTML = code;
}
</script>
</head>
<!-- Generate The first tab and the keyboard tab as soon as the page is loaded -->
<body onload='generateAlbumList(); generateKeyboard();'>
<div id='tabs'>
<div id='album_list' class='display'>
</div>
<div id='track_list' class='display'>
No album selected
</div>
<div id='current_track' class='display songdata'>
No song selected
</div>
</div>
<div id='keyboard'>
</div>
</body>
</html>