var player = ''; $(document).ready(function() { player = $('#music-player').get(0); // on music track click $('.now-playing-list .music-track').on('click', function() { // change selected track changeSelectedTrack(this); }); // on album art click $('.music-album .thumbnail').on('click', function() { // change selected album changeSelectedAlbum(this); }); }); function changeSelectedAlbum(albumElem) { var oldSelected = $('.music-album.selected'); var newSelected = $(albumElem).parent(); if (oldSelected.data('albumid') != newSelected.data('albumid')) { // remove selected class from the old element and add it to the new one oldSelected.removeClass('selected'); newSelected.addClass('selected'); // change album info getAlbumInfo(albumElem); // change available songs getAlbumSongs(albumElem); } } function getAlbumInfo(albumElem) { albumElem = $(albumElem).parent(); $.get('/apiv1/music/album-info/' + albumElem.data('albumid'), function(data) { var json = $.parseJSON(data); // change album artwork $('#album-artwork').attr('src', json.album_art); // change album title $('#album-title').text(json.title); // change album description $('#album-description').text(json.description); }); } function getAlbumSongs(albumElem) { albumElem = $(albumElem).parent(); $.get('/apiv1/music/album-songs/' + albumElem.data('albumid'), function(data) { var json = $.parseJSON(data); var playlist = $('#now-playing-list'); playlist.empty(); for (var i = 0; i < json.songs.length; i++) { var song = json.songs[i]; var classString = ''; if (i === 0) { classString = 'music-track selected'; } else { classString = 'music-track'; } var songElem = '