diff options
-rw-r--r-- | frontend/js/app.js | 10 | ||||
-rw-r--r-- | frontend/js/views/SongTable.js | 11 |
2 files changed, 17 insertions, 4 deletions
diff --git a/frontend/js/app.js b/frontend/js/app.js index 45e7927..6f58a0a 100644 --- a/frontend/js/app.js +++ b/frontend/js/app.js @@ -10,7 +10,7 @@ $(function() { var audioPlayer = new AudioPlayer($("#controls")); var songList = new SongList([], audioPlayer); - new SongTable({ + var songTable = new SongTable({ el: $(document.body), collection: songList }); @@ -24,11 +24,13 @@ $(function() { if (!isNaN(song) && song > 0) { songList.once("sync", function() { var loadSong = function() { - if (song <= songList.length) - audioPlayer.playSong(songList.models[song - 1]); + if (song > songList.length) + return; + audioPlayer.playSong(songList.models[song - 1]); + songTable.scrollTo(songList.models[song - 1]); }; if (song > songList.length && songList.hasMore()) - songList.more({ success: loadSong, limit: song - songList.length }); + songList.more({ success: loadSong, limit: songList.options.limit * Math.ceil((song - songList.length) / songList.options.limit) }); else loadSong(); }); diff --git a/frontend/js/views/SongTable.js b/frontend/js/views/SongTable.js index add31d3..60a862f 100644 --- a/frontend/js/views/SongTable.js +++ b/frontend/js/views/SongTable.js @@ -54,5 +54,16 @@ var SongTable = Backbone.View.extend({ }, renderMore: function(more) { more.each(this.appendSong); + }, + scrollTo: function(song) { + var that = this; + _.defer(function() { + if (!(song.id in that.songRows)) + return; + var offset = that.songRows[song.id].$el.offset().top; + if (that.$songlistContainer.scrollTop() + that.$songlistContainer.height() >= offset) + return; + that.$songlistContainer.scrollTop(offset - that.$songlistContainer.height() / 2); + }); } }); |