From 8d9cd7b216dafa8a18e481c31b6f2ec9af6faaab Mon Sep 17 00:00:00 2001 From: Florrie Date: Sat, 2 Sep 2017 13:04:17 -0300 Subject: Skip back/forwards --- src/pickers2.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src/pickers2.js') diff --git a/src/pickers2.js b/src/pickers2.js index e36d257..af3fc2a 100644 --- a/src/pickers2.js +++ b/src/pickers2.js @@ -52,13 +52,28 @@ class HistoryController { } } - getNextTrack() { + getNextTrack(move = true) { // Moves the timeline index forwards and returns the track at the new index // (while refilling the timeline, so that the "up next" list is still full, // and so the picker is called if there is no track at the current index). - this.timelineIndex++ - this.fillTimeline() - return this.currentTrack + if (move) { + this.timelineIndex++ + this.fillTimeline() + return this.currentTrack + } else { + return this.timeline[this.timelineIndex + 1] + } + } + + getBackTrack(move = true) { + if (move) { + if (this.timelineIndex > 0) { + this.timelineIndex-- + } + return this.currentTrack + } else { + return this.timeline[Math.max(this.timelineIndex - 1, 0)] + } } get currentTrack() { -- cgit 1.3.0-6-gf8a5