From 6ea41f79e977829f026a4d5e0d80cf16cfca6b4a Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Fri, 11 Dec 2020 09:47:32 +0000 Subject: [PATCH] Simplify the `showControl` calls on reader page --- public/js/reader.js | 7 ++++--- src/views/reader.html.ecr | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/public/js/reader.js b/public/js/reader.js index f7b26c3..233e2aa 100644 --- a/public/js/reader.js +++ b/public/js/reader.js @@ -141,10 +141,9 @@ const waitForPage = (idx, cb) => { * Show the control modal * * @function showControl - * @param {object} event - The onclick event that triggers the function + * @param {string} idx - One-based index of the current page */ -const showControl = (event) => { - const idx = parseInt($(event.currentTarget).attr('id')); +const showControl = (idx) => { const pageCount = $('#page-select > option').length; const progressText = `Progress: ${idx}/${pageCount} (${(idx/pageCount * 100).toFixed(1)}%)`; $('#progress-label').text(progressText); @@ -191,6 +190,8 @@ const setupScroller = () => { $(el).on('inview', (event, inView) => { if (inView) { const current = $(event.currentTarget).attr('id'); + + setProp('curItem', getProp('items')[current - 1]); replaceHistory(current); } }); diff --git a/src/views/reader.html.ecr b/src/views/reader.html.ecr index 540fd0c..9136071 100644 --- a/src/views/reader.html.ecr +++ b/src/views/reader.html.ecr @@ -39,7 +39,7 @@ :width="item.width" :height="item.height" :id="item.id" - @click="showControl($event)" + :onclick="`showControl('${item.id}')`" /> <%- if next_entry_url -%> @@ -55,7 +55,7 @@ 'uk-align-center': true, 'uk-animation-slide-left': flipAnimation === 'left', 'uk-animation-slide-right': flipAnimation === 'right' - }" :data-src="curItem.url" :width="curItem.width" :height="curItem.height" :id="curItem.id" @click="showControl($event)" :style="` + }" :data-src="curItem.url" :width="curItem.width" :height="curItem.height" :id="curItem.id" :onclick="`showControl('${curItem.id}')`" :style="` width:${mode === 'width' ? '100vw' : 'auto'}; height:${mode === 'height' ? '100vh' : 'auto'}; margin-bottom:0;