Added song selection change when changing albums
This commit is contained in:
parent
8b42f39aa1
commit
df72cf3a58
@ -16,4 +16,23 @@ $app->get('/apiv1/music/album-info/:albumid', function($albumid) use($app) {
|
||||
$app->notFound();
|
||||
}
|
||||
|
||||
})->name('apiv1.music.get-album');
|
||||
})->name('apiv1.music.album-info');
|
||||
|
||||
// retrieve an album's songs
|
||||
$app->('/apiv1/music/album-songs/:albumid', function($albumid) use($app) {
|
||||
|
||||
if (!ctype_digit($albumid)) {
|
||||
echo 'Don\'t do that';
|
||||
return;
|
||||
}
|
||||
|
||||
$album = $app->album->where('id', $albumid)->first();
|
||||
|
||||
if ($album) {
|
||||
$json = [songs => $album->songs()];
|
||||
echo json_encode($json);
|
||||
} else {
|
||||
$app->notFound();
|
||||
}
|
||||
|
||||
})->name('apiv1.music.album-songs')
|
||||
|
@ -45,6 +45,33 @@ function getAlbumInfo(albumElem) {
|
||||
});
|
||||
}
|
||||
|
||||
function getAlbumSongs(albumElem) {
|
||||
albumElem = $(albumElem);
|
||||
|
||||
$.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 = '<li class="' + classString + '" data-trackid="' + song.id + '" data-title="' + song.title + '" data-album="' + song.album_id + '" data-order="' + song.track_order + '" data-path="' + song.audio_file + '">' +
|
||||
'<span>' + song.track_order + '. ' + song.title + '</span>' +
|
||||
'</li>';
|
||||
|
||||
playlist.append(song);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function changeSelectedTrack(trackElem) {
|
||||
var oldSelected = $('.now-playing-list .music-track.selected');
|
||||
var newSelected = $(trackElem);
|
||||
|
Loading…
Reference in New Issue
Block a user