From f51d27860a0214fdc35b7d6649008fefe7ce350e Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Sat, 9 Jan 2021 15:49:34 +0000 Subject: [PATCH] Validate input index before flipping page --- public/js/reader.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/public/js/reader.js b/public/js/reader.js index c09c340..8bf1133 100644 --- a/public/js/reader.js +++ b/public/js/reader.js @@ -101,8 +101,9 @@ const readerComponent = () => { */ flipPage(isNext) { const idx = parseInt(this.curItem.id); - const delta = isNext ? 1 : -1; - const newIdx = idx + delta; + const newIdx = idx + (isNext ? 1 : -1); + + if (newIdx <= 0 || newIdx > this.items.length) return; this.toPage(newIdx);